Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • G GLib
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 859
    • Issues 859
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 55
    • Merge requests 55
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • GLib
  • Merge requests
  • !1968

gspawn: Implement fd remapping for posix_spawn codepath, and fix file descriptor conflation issues

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Michael Catanzaro requested to merge mcatanzaro/posix-spawn2 into main Feb 25, 2021
  • Overview 46
  • Commits 10
  • Pipelines 28
  • Changes 3

Hi Philip, this removes the FIXME that you added in !1690 (merged). I think the implementation is on par with the existing code, unless there is some edge case I've failed to consider.

But it's marked WIP because I discovered a (quite unlikely) edge case in the preexisting fork/exec codepath that I want to investigate further before landing:

  /* FIXME: this works in the naive case but not for a case like:
   *
   * Case: source_fd 5 -> target_fd 7, source_fd 4 -> target_fd 6
   *
   * dup(5) -> get unlucky, dup returns 6
   * dup(4) -> dup returns 7
   *
   * This means we wind up with: 6 -> 7, 7 -> 6. That means that after
   * we dup2(6, 7), we have clobbered fd 7 before we dup2(7, 6). End
   * result is we have remapped 5 -> 7 as expected, but then remapped
   * 5 -> 6 instead of 4 -> 6. So we will need a quadratic loop to check
   * that each value in duped_source_fds is not present in target_fds,
   * and repeatedly dup if it is.
   *
   * The existing fork/exec codepath has the exact same bug and must
   * also be fixed.
   */

I'll probably open a separate issue for that after thinking harder about it. Seemed useful to create the MR now as a heads-up since I see you've been working on the code recently.

Update: I wound up fixing the above as part of this MR.

Edited Nov 03, 2021 by Michael Catanzaro
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: mcatanzaro/posix-spawn2