-
Notifications
You must be signed in to change notification settings - Fork 3.4k
dup() syscall is wrongly implemented #4017
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
Comments
Can you make a small standalone testcase for this? It would be useful to verify that we fix it properly, and then we'd put it in the test suite. |
I already done that. See tests :) I fetched output of |
This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
@kripken what is the actual status ? |
I think I missed this issue back then because I didn't see the test, sorry about that! Do you want to open a PR with that? Looks like it hasn't been fixed since. |
Possibly. Unfortunatelly not right now. |
@socketpair @kripken I've rebased this on incoming, but the test no longer passes. The seek position and flags work properly, but the duplicated file descriptors don't close properly. Looking into the issue, it appears that Unless I'm mistaken, it seems that stream parameters such as flags and seek position are shared between duplicated streams, but the closed status is not? |
I'm no JS guru, but it looks to me like we might want a new prototype for shared stream attributes. |
Well, I have a branch (https://github.com/jakogut/emscripten/tree/fix-dup-syscalls) that works with manual testing like so:
Output:
Strangely, using the test runner, it still fails like it's unpatched.
Output:
I've created a PR for review here: #9396 |
According to posix, everything should be shared, except o_cloexec flag. Close() must remove the fd from the process namespace and then possibly destroy underlying object t. If fd is a socket, it should close connection (i.e. call shutdown() internally) only if latest reference is closed. Calling shutdown() must influence all fd duplicates, but leave them "open" (and unusable) The same about closing pipe fds. In short, real object destruction should happen only when closed last fd referring it. In multiprocess environment, duplicates of descriptors might present in different processes. Note, opening the same file must give another object which must not share state with one opened previously. Also some picky details about flock() syscall |
If fd is duplicated and then closed, original fd must be accessible in all ways as if duplication and closing did not happen. |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
It was actual at time of writing. Don't know if still actual. |
I just ran into this issue as well. Any chance of landing a fix here? |
I opened another issue #15012 which may well also be caused by this. |
Checking the testcase in jakogut@cfacd7d (copied and slightly modified here to avoid the need for JS, https://gist.github.com/kripken/381aa555c2597bd5ebb28c83b2cf0add), looks like it passes in the new WASMFS work (#15041). @ethanalee @tlively I might be missing something, but it doesn't look like we have a test for this atm - dup tests don't use seek, and vice versa. If so, it might be good to add a test for this issue. |
Thanks for the gist. This looks like a good test case to add. Thanks will make a note for the following PR! |
Note that while this issue was closed, this only works in the new FS, which is not yet on by default. Perhaps we should reopen this issue, but then we might forget to close it later (and hopefully not much later in the future), so leaving closed. |
@kripken I did not check the change. Dup and dup2 should not share O_CLOEXEC flag. It's per FD. And also the flag should be honored in execve() - automatically close FDs where the flag is set. Should not be closed on fork(). |
Re-opening since we are still have a broken dup as of today. We can close it if/when the FS becomes the default or if someone wants to fix the current FS implementation. |
@socketpair, Emscripten does not have |
Hmm. I think execve is possible to implement. Fork - no, but execve yes. |
emscripten is fundamentally single process (at least today) so there is no exec or fork or anything like that. |
@sbc100 yes, I know. Concept of execve does not mean creating new processes. Execve means "convert" working program to another. Without any parallelism. |
OK, but that is something else that we also have no support for today. |
Relevant Issue: emscripten-core#15041 Verifies that this issue has been fixed with the dup syscall: emscripten-core#4017
dup()
ed file descriptors should share all flags (and also seek position). Opening same file twice is not the same thing. Also, one may try todup()
socket, which cannot beopen()
ed.The text was updated successfully, but these errors were encountered: