Skip to content

Adopt OpenBSD 8.0 posix_spawn chdir file actions - #389

Open
jakepetroules wants to merge 1 commit into
swiftlang:mainfrom
jakepetroules:jake-petroules/openbsd-chdir
Open

jakepetroules wants to merge 1 commit into
swiftlang:mainfrom
jakepetroules:jake-petroules/openbsd-chdir

Conversation

@jakepetroules

@jakepetroules jakepetroules commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

OpenBSD 8.0 added posix_spawn_file_actions_addchdir(3) and posix_spawn_file_actions_addfchdir(3) (commit, man page). POSIX.1-2024 specifies them without the _np suffix. This adopts them.

Changes

  • Probe for posix_spawn_file_actions_addfchdir and posix_spawn_file_actions_addchdir with dlsym, preferring the unsuffixed names and falling back to the _np spelling used by older glibc, Bionic and FreeBSD. Darwin is unchanged.
  • Add a separate capability bit and shim, _subprocess_spawn_addchdir, for the path-based action. OpenBSD has no O_SEARCH or O_PATH, so it cannot open a descriptor for fchdir without requiring read permission on the directory, which chdir does not. The path-based action needs no descriptor.
  • Rule 5 of requiresFallbackSpawnPath now only requires the fallback for a working directory when neither the fchdir route nor the path-based action is available.
  • resolveWorkingDirectory opens a descriptor only when the fchdir route is usable. Otherwise it does the existing advisory stat/faccessat check, which keeps a bad directory from being reported as executableNotFound.

Behavior on OpenBSD

OpenBSD still has no close-all mechanism (no POSIX_SPAWN_CLOEXEC_DEFAULT, no closefrom action) and no POSIX_SPAWN_SETSID, so rule 2 still sends every OpenBSD spawn through the fork/exec fallback. This change corrects capability reporting and removes the working-directory blocker, but does not change runtime behavior there yet.

OpenBSD 8.0 added posix_spawn_file_actions_addchdir and addfchdir, which
POSIX.1-2024 specifies without the _np suffix. Probe for them with dlsym,
preferring the unsuffixed names and falling back to _np on older glibc,
Bionic and FreeBSD.

OpenBSD has no O_SEARCH or O_PATH, so it cannot open a directory for an
fchdir action without requiring read permission. Track the path-based
chdir action as its own capability and use it when no descriptor can be
opened, so a working directory no longer forces the fallback path on its
own.

OpenBSD still has no close-all mechanism and no POSIX_SPAWN_SETSID, so it
continues to spawn through the fork/exec fallback for now.
@jakepetroules
jakepetroules marked this pull request as ready for review October 29, 2026 06:20
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 this pull request may close these issues.

1 participant