watch: Don't leak extra fds to the child
Once the write side of the pipe has been duped to stdout for the child, the original pipefd is no longer needed, so it can be closed to avoid leaking to the child. The leak can easily be seen with "watch ls -l /proc/self/fd", but I found this due to "watch lvs" diagnosing itself: File descriptor 4 (pipe:[3163616]) leaked on lvs invocation. Signed-off-by: Josh Stone <jistone@redhat.com>
This commit is contained in:
parent
4fcd56bf58
commit
835b6294d1
1
watch.c
1
watch.c
@ -387,6 +387,7 @@ static int run_command(char *restrict command, char **restrict command_argv)
|
||||
if (dup2(pipefd[1], 1) < 0) { /* replace stdout with write side of pipe */
|
||||
xerr(3, _("dup2 failed"));
|
||||
}
|
||||
close(pipefd[1]); /* once duped, the write fd isn't needed */
|
||||
dup2(1, 2); /* stderr should default to stdout */
|
||||
|
||||
if (flags & WATCH_EXEC) { /* pass command to exec instead of system */
|
||||
|
Loading…
Reference in New Issue
Block a user