Skip to content

Preserve shared and cyclic descriptors when remapping child standard streams #558

Description

@LunaStev

proc_spawn_exec_raw remaps stdin, stdout and stderr sequentially. _proc_dup_child_fd closes each source fd immediately after dup2. Passing the same nonstandard fd for both stdout and stderr therefore closes it after the first mapping; the second dup2 uses a closed fd and the child exits with PROC_EXIT_DUP_FAIL. Mappings that swap standard descriptors can also overwrite a source before it is used.

Combining stdout/stderr onto one pipe is a normal subprocess use case.

Code evidence:

Acceptance:

  • Plan remapping before closing descriptors, preserving sources required by later mappings and using temporary duplicates for cycles where needed.
  • Cover shared stdout/stderr, a stdin/stdout swap, identity mappings and disabled (-1) mappings.
  • Close each no-longer-needed descriptor exactly once and clean up temporary duplicates on failure.
  • Keep parent-owned descriptors and native Unix process behavior intact; Add native Windows process spawning and waiting APIs #429 handles the separate Windows spawning implementation.

Audit status: static source inspection against canonical master ea74c2dafc31da876e5561f2d176ba719f5a0458 on 2026-09-10. No compiler build, test execution, implementation change or local reproduction was performed for this report. The examples describe the source-derived behavior to verify when implementing the fix.

Activity

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

    bugA problem that causes incorrect behavior or crashes.help wantedThe issue requires extra attention or help from others.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions