Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeFS fails on (folders with) named pipes #22924

Open
hoodmane opened this issue Nov 14, 2024 · 2 comments · May be fixed by #22925
Open

NodeFS fails on (folders with) named pipes #22924

hoodmane opened this issue Nov 14, 2024 · 2 comments · May be fixed by #22925

Comments

@hoodmane
Copy link
Contributor

hoodmane commented Nov 14, 2024

Setup:

mkdir has_named_pipe
mkfifo has_named_pipe/named_pipe

File a.c:

#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

int count_entries(char* dirname) {
    DIR* d = opendir(dirname);
    struct dirent *ep;
    int res = 0;
    while (1) {
        ep = readdir(d);
        if (ep == NULL) {
            break;
        }
        res ++;
       printf("%s\n", ep->d_name);
    }
    return res;
}


int main() {
#ifdef __EMSCRIPTEN__
    EM_ASM({
        FS.mount(NODEFS, { root: 'has_named_pipe' }, 'has_named_pipe');
    });
#endif
    int nentries = count_entries("has_named_pipe");
    printf("nentries: %d\n", nentries);
    return 0;
}

If we compile and run with gcc we get:

$ gcc a.c
$ ./a.out
named_pipe
.
..
nentries: 3

If we compile and run with emcc we get:

$ emcc a.c  -lnodefs.js
$ node a.out.js
nentries: 0

Indeed after we see the named pipe, getdents stops reading. An error is thrown here: https://github.com/emscripten-core/emscripten/blob/main/src/library_nodefs.js?plain=1#L71 which aborts the normal handling. I think we can just ignore these entries?

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.72-git (b2ced9de42ea8028233d7d3588c45ce837b61185)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 50866e84d1da8462aeb96607bf6d9e5bbd5869c5)
Target: wasm32-unknown-emscripten
Thread model: posix
@sbc100
Copy link
Collaborator

sbc100 commented Nov 14, 2024

I'm a little confused by the output "0" in the failing case... should that be nentries: 0 or is the zero coming from somewhere else?

@hoodmane
Copy link
Contributor Author

Yes it should be nentries: 0, edited it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants