Created
April 23, 2010 14:38
-
-
Save horatio-sans-serif/376596 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ file /proc/14207/smaps | |
/proc/14207/smaps: empty | |
$ tail /proc/14207/smaps | |
Shared_Dirty: 0 kB | |
Private_Clean: 0 kB | |
Private_Dirty: 8 kB | |
bf9cc000-bf9e2000 rw-p bf9cc000 00:00 0 [stack] | |
Size: 88 kB | |
Rss: 32 kB | |
Shared_Clean: 0 kB | |
Shared_Dirty: 0 kB | |
Private_Clean: 0 kB | |
Private_Dirty: 32 kB | |
$ ls -l /proc/14207/smaps | |
-r--r--r-- 1 brian brian 0 Apr 23 14:27 /proc/14207/smaps | |
$ cat /tmp/test.c | |
#include <stdio.h> | |
int main() { | |
char buf[1024]; | |
FILE* fp = fopen("/proc/14207/smaps", "rb"); | |
fread(buf, 1023, 1, fp); | |
buf[1023] = '\0'; | |
printf("%s\n", buf); | |
fclose(fp); | |
return 0; | |
} | |
$ /tmp/test | |
08048000-081a8000 r-xp 00000000 ca:00 794693 /usr/bin/vim.basic | |
Size: 1408 kB | |
Rss: 1220 kB | |
Shared_Clean: 1144 kB | |
Shared_Dirty: 0 kB | |
Private_Clean: 76 kB | |
Private_Dirty: 0 kB | |
081a8000-081b4000 rw-p 00160000 ca:00 794693 /usr/bin/vim.basic | |
Size: 48 kB | |
Rss: 44 kB | |
Shared_Clean: 4 kB | |
Shared_Dirty: 0 kB | |
Private_Clean: 0 kB | |
Private_Dirty: 40 kB | |
081b4000-082e5000 rw-p 081b4000 00:00 0 [heap] | |
Size: 1220 kB | |
Rss: 1160 kB | |
Shared_Clean: 0 kB | |
Shared_Dirty: 0 kB | |
Private_Clean: 0 kB | |
Private_Dirty: 1160 kB | |
b7d2c000-b7d35000 r-xp 00000000 ca:00 168 /lib/libnss_files-2.7.so | |
Size: 36 kB | |
Rss: 12 kB | |
Shared_Clean: 12 kB | |
Shared_Dirty: 0 kB | |
Private_Clean: 0 kB | |
Private_Dirty: 0 kB | |
b7d35000-b7d37000 rw-p 00008000 ca:00 168 /lib/libnss_files-2.7.so | |
Size: 8 kB | |
Rss: | |
$ cat /tmp/test.js | |
var | |
sys = require("sys"), | |
fs = require("fs"); | |
sys.puts(fs.readFileSync("/proc/14207/smaps", "binary")); | |
$ node /tmp/test.js | |
Error: ESPIPE, Illegal seek | |
at Object.readFileSync (fs:79:23) | |
at Object.<anonymous> (/tmp/test.js:5:13) | |
at Module._compile (module:385:23) | |
at module:413:20 | |
at fs:52:23 | |
at node.js:164:9 | |
$ node -v | |
v0.1.91-38-gc9e27b1 | |
What's going on here? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/fs.js b/lib/fs.js | |
index c3ab698..51cf965 100644 | |
--- a/lib/fs.js | |
+++ b/lib/fs.js | |
@@ -73,7 +73,7 @@ fs.readFileSync = function (path, encoding) { | |
var fd = binding.open(path, process.O_RDONLY, 0666); | |
var content = ''; | |
- var pos = 0; | |
+ var pos; // leave undefined to allow reads on unseekable devices | |
var r; | |
while ((r = binding.read(fd, 4*1024, pos, encoding)) && r[0]) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so /proc/x/smaps is unseekable.
I think node/lib/fs.js should be patched to not use a pos=0 by default.
It makes this work and doesn't change any other functionality that I can see (make test passes).