Skip to content

Commit f021c07

Browse files
authored
Make readdir on /proc/self/fd work (#23073)
1 parent 5122e40 commit f021c07

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/library_fs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,9 @@ FS.staticInit();
13931393
FS.mount({
13941394
mount() {
13951395
var node = FS.createNode(proc_self, 'fd', {{{ cDefs.S_IFDIR | 0o777 }}}, {{{ cDefs.S_IXUGO }}});
1396+
node.stream_ops = {
1397+
llseek: MEMFS.stream_ops.llseek,
1398+
};
13961399
node.node_ops = {
13971400
lookup(parent, name) {
13981401
var fd = +name;
@@ -1401,9 +1404,15 @@ FS.staticInit();
14011404
parent: null,
14021405
mount: { mountpoint: 'fake' },
14031406
node_ops: { readlink: () => stream.path },
1407+
id: fd + 1,
14041408
};
14051409
ret.parent = ret; // make it look like a simple root node
14061410
return ret;
1411+
},
1412+
readdir() {
1413+
return Array.from(FS.streams.entries())
1414+
.filter(([k, v]) => v)
1415+
.map(([k, v]) => k.toString());
14071416
}
14081417
};
14091418
return node;

test/fs/test_proc_self_fd.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ int main(int argc, char* argv[]) {
1414
struct dirent *entry;
1515
while ((entry = readdir(d))) {
1616
printf("entry: %s\n", entry->d_name);
17-
printf("unexpected success reading directory!");
18-
return 1;
1917
}
2018
closedir(d);
2119

test/fs/test_proc_self_fd.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
entry: 0
2+
entry: 1
3+
entry: 2
4+
entry: 3
15
fd0: /dev/tty
26
done

0 commit comments

Comments
 (0)