diff options
| author | Baptiste Daroussin <bapt@FreeBSD.org> | 2026-03-28 08:41:47 +0000 |
|---|---|---|
| committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2026-03-28 08:51:48 +0000 |
| commit | 945e60e018c287f8097f3ee4a30ccf4921845aa1 (patch) | |
| tree | badabc0305676bc0baa2bc43b365c0a271382056 | |
| parent | 7b6be0014a4eb81943491122bae70914b7fd82b6 (diff) | |
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
| -rw-r--r-- | usr.bin/diff3/diff3.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index 8212b51e15a2..bbef1f0d21a5 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -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; |
