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>
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 */