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

do_spawn_fork double-closes the parent STDIO pipe FDs #306

Closed
josephcsible opened this issue Mar 25, 2024 · 0 comments · Fixed by #307
Closed

do_spawn_fork double-closes the parent STDIO pipe FDs #306

josephcsible opened this issue Mar 25, 2024 · 0 comments · Fixed by #307

Comments

@josephcsible
Copy link
Contributor

When running this Haskell code:

import System.Posix.User
import System.Process

getEffectiveGroupID >>= \egid -> createProcess (proc "/nonexistent" []){ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe, child_group = Just egid }

The resulting exception will incorrectly be invalid argument (Bad file descriptor) instead of does not exist (No such file or directory). The problem itself has nothing to do with GIDs, but by setting one, do_spawn_fork is forced to be used instead of do_spawn_posix, which makes this reproducible even when posix_spawn is otherwise supported.

The problem is that the parent_end FD of stdin, stdout, and stderr all get closed both by runInteractiveProcess and by do_spawn_fork. In addition to all of the problems that double-close usually causes, here it also causes errno to be unexpectedly overwritten. I'm pretty sure, but not 100% positive, that runInteractiveProcess is the one that's supposed to be closing them, and that do_spawn_fork shouldn't be.

bgamari added a commit to bgamari/process that referenced this issue Mar 26, 2024
Previously the fork/exec backend would attempt to close
stdin, et al. on process spawn failure. This result in spurious `close`
failures due to `runInteractiveProcess` doing the same. Consequently,
the cause of the failure would be confusingly mis-identified.

Fixes haskell#306.
bgamari added a commit that referenced this issue Apr 9, 2024
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.

1 participant