diff3: set O_CLOEXEC on pipes

This avoid leaking pipe fd in children and simplifies the code

MFC After:	1 week
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D56120
This commit is contained in:
Baptiste Daroussin
2026-03-28 09:41:47 +01:00
parent 7b6be0014a
commit 945e60e018
+2 -6
View File
@@ -317,10 +317,7 @@ diffexec(char **diffargv, int fd[])
errc(2, error, "posix_spawn_file_actions_init");
posix_spawnattr_setprocdescp_np(&sa, &pd, 0);
posix_spawn_file_actions_addclose(&fa, fd[0]);
posix_spawn_file_actions_adddup2(&fa, fd[1], STDOUT_FILENO);
posix_spawn_file_actions_addclose(&fa, fd[1]);
error = posix_spawn(&pid, diffargv[0], &fa, &sa, diffargv, environ);
if (error != 0)
@@ -1085,12 +1082,11 @@ main(int argc, char **argv)
if (caph_rights_limit(fileno(fp[2]), &rights_ro) < 0)
err(2, "unable to limit rights on: %s", file3);
if (pipe(fd13))
if (pipe2(fd13, O_CLOEXEC))
err(2, "pipe");
if (pipe(fd23))
if (pipe2(fd23, O_CLOEXEC))
err(2, "pipe");
diffargv[diffargc] = file1;
diffargv[diffargc + 1] = file3;
diffargv[diffargc + 2] = NULL;