diff options
author | Gunnar Beutner <[email protected]> | 2011-07-29 10:17:46 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2011-08-01 13:52:23 -0700 |
commit | 3132cb397ad1b60cac548b35ad8bbd4c7183fde4 (patch) | |
tree | 8b748cc67e44ebc826096df32f7258c572c2aa67 /lib/libzfs/libzfs_util.c | |
parent | 5333eb0b3b18d345052b8cfaf41b90a0c5781fb8 (diff) |
Use /dev/null for stdout/stderr in libzfs_run_process().
Simply closing the stdout and/or stderr file descriptors for
the child process can have bad side effects if for example
the child writes to stdout/stderr after open()ing a file.
The open() call might have returned the same file descriptor
one would usually expect for stdout/stderr (1 and 2), thereby
causing mis-directed writes.
Signed-off-by: Brian Behlendorf <[email protected]>
Issue #190
Diffstat (limited to 'lib/libzfs/libzfs_util.c')
-rw-r--r-- | lib/libzfs/libzfs_util.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index f55b658d0..5f6763c49 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -635,15 +635,22 @@ int libzfs_run_process(const char *path, char *argv[], int flags) { pid_t pid; - int rc; + int rc, devnull_fd; pid = vfork(); if (pid == 0) { + devnull_fd = open("/dev/null", O_WRONLY); + + if (devnull_fd < 0) + _exit(-1); + if (!(flags & STDOUT_VERBOSE)) - close(STDOUT_FILENO); + (void) dup2(devnull_fd, STDOUT_FILENO); if (!(flags & STDERR_VERBOSE)) - close(STDERR_FILENO); + (void) dup2(devnull_fd, STDERR_FILENO); + + close(devnull_fd); (void) execvp(path, argv); _exit(-1); |