aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2026-06-03 20:42:01 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2026-06-03 20:50:38 +0000
commit8bf4902569869133affd91bdcb71b74656cfc36e (patch)
treef024b339fbd147eb48c8a834284ab8911071a598
parent248dd56d2dea03e4723e8225b890d02fcc10973f (diff)
diff: Correct fd 0 case on pipe
After git commit c8d40bf8ecc60cc15e3904410db62065ea681fdc, 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
-rw-r--r--usr.bin/diff/pr.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.bin/diff/pr.c b/usr.bin/diff/pr.c
index e8a4162d8b18..57cbb6a56ce5 100644
--- a/usr.bin/diff/pr.c
+++ b/usr.bin/diff/pr.c
@@ -71,8 +71,9 @@ start_pr(char *file1, char *file2)
posix_spawnattr_setprocdescp_np(&sa, &pr->procd, 0);
- if (pfd[0] != STDIN_FILENO)
- posix_spawn_file_actions_adddup2(&fa, pfd[0], STDIN_FILENO);
+ error = 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),
__DECONST(char *, "-h"), header, NULL };