Skip to content

do_spawn_fork double-closes the parent STDIO pipe FDs #306

Description

@josephcsible

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.

Activity

  1. added a commit that references this issue on Mar 26, 2024
    8a9bf8b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions