git: f5d3d35273ea - stable/15 - diff: use O_CLOEXEC on pipes

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Mon, 06 Apr 2026 16:52:24 UTC
The branch stable/15 has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=f5d3d35273ea58b120ea80d1222205c3d4f969ee

commit f5d3d35273ea58b120ea80d1222205c3d4f969ee
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2026-03-28 08:55:24 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2026-04-06 16:51:46 +0000

    diff: use O_CLOEXEC on pipes
    
    This only simplifies the code, no functional changes expected
    
    MFC After:      1 week
    
    (cherry picked from commit c8d40bf8ecc60cc15e3904410db62065ea681fdc)
---
 usr.bin/diff/pr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/usr.bin/diff/pr.c b/usr.bin/diff/pr.c
index 51cf2c765283..e8a4162d8b18 100644
--- a/usr.bin/diff/pr.c
+++ b/usr.bin/diff/pr.c
@@ -61,7 +61,7 @@ start_pr(char *file1, char *file2)
 	xasprintf(&header, "%s %s %s", diffargs, file1, file2);
 	signal(SIGPIPE, SIG_IGN);
 	fflush(stdout);
-	if (pipe(pfd) == -1)
+	if (pipe2(pfd, O_CLOEXEC) == -1)
 		err(2, "pipe");
 
 	if ((error = posix_spawnattr_init(&sa)) != 0)
@@ -71,11 +71,8 @@ start_pr(char *file1, char *file2)
 
 	posix_spawnattr_setprocdescp_np(&sa, &pr->procd, 0);
 
-	if (pfd[0] != STDIN_FILENO) {
+	if (pfd[0] != STDIN_FILENO)
 		posix_spawn_file_actions_adddup2(&fa, pfd[0], STDIN_FILENO);
-		posix_spawn_file_actions_addclose(&fa, pfd[0]);
-	}
-	posix_spawn_file_actions_addclose(&fa, pfd[1]);
 
 	char *argv[] = { __DECONST(char *, _PATH_PR),
 	    __DECONST(char *, "-h"), header, NULL };