Skip to content

Fix error handling in PosixSpawnAttr / PosixSpawnFileActions methods - #2865

Merged
asomers merged 2 commits into
nix-rust:masterfrom
thelastbackspace:fix/2855-spawn-errno
Nov 14, 2026
Merged

asomers merged 2 commits into
nix-rust:masterfrom
thelastbackspace:fix/2855-spawn-errno

Conversation

@thelastbackspace

Copy link
Copy Markdown
Contributor

The posix_spawnattr_* and posix_spawn_file_actions_* functions return 0 on success and the error number on failure, they don't return -1 and set errno. The wrappers in src/spawn.rs used Errno::result, which only treats -1 as an error, so every failure came back as Ok(()). #2595 already fixed this for posix_spawn/posix_spawnp themselves, this does the same for the rest of the file.

I added a small spawn_result helper and used it for all of them. That also means init() no longer reaches assume_init() when init fails.

Added a test that add_dup2(-1, 1) and add_close(-1) return EBADF. Both returned Ok(()) before the change.

The reinit double-destroy path mentioned in #2797 is a separate problem, so I didn't touch it here.

Fixes #2855

@asomers asomers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. The CI failure should be fixed on the master branch. I'm going to optimistically attempt a merge, since we use merge queue.

@asomers

asomers commented Nov 10, 2026

Copy link
Copy Markdown
Member

Nevermind, Github doesn't like that. @thelastbackspace please rebase.

The posix_spawnattr_* and posix_spawn_file_actions_* functions return 0
on success and an error number on failure. Errno::result only treats -1
as an error, so failures were reported as Ok(()).

Fixes nix-rust#2855
@thelastbackspace

Copy link
Copy Markdown
Contributor Author

Rebased onto master.

@asomers
asomers enabled auto-merge November 10, 2026 18:12
@asomers
asomers disabled auto-merge November 14, 2026 17:41
@asomers
asomers merged commit 143f203 into nix-rust:master Nov 14, 2026
45 of 64 checks passed
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.

nix::spawn attribute and file-action wrappers treat positive POSIX error numbers as success

2 participants