diff: Correct fd 0 case on pipe

After git commit c8d40bf8ec, if fd 0 was
not open, it is left with CLOEXEC set and therefore fails. This is an
unlikely situation, but fixing it reduces the size of the code (by using
posix_spawn_file_actions_adddup2's special case if the two file
descriptor numbers are the same).

At the same time, check the error code from
posix_spawn_file_actions_adddup2.

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D56910
This commit is contained in:
Jilles Tjoelker
2026-06-03 22:42:01 +02:00
parent 248dd56d2d
commit 8bf4902569
+3 -2
View File
@@ -71,8 +71,9 @@ start_pr(char *file1, char *file2)
posix_spawnattr_setprocdescp_np(&sa, &pr->procd, 0); posix_spawnattr_setprocdescp_np(&sa, &pr->procd, 0);
if (pfd[0] != STDIN_FILENO) error = posix_spawn_file_actions_adddup2(&fa, pfd[0], STDIN_FILENO);
posix_spawn_file_actions_adddup2(&fa, pfd[0], STDIN_FILENO); if (error != 0)
errc(2, error, "posix_spawn_file_actions_adddup2");
char *argv[] = { __DECONST(char *, _PATH_PR), char *argv[] = { __DECONST(char *, _PATH_PR),
__DECONST(char *, "-h"), header, NULL }; __DECONST(char *, "-h"), header, NULL };