aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorChris Dunlap <[email protected]>2016-03-01 12:23:55 -0800
committerBrian Behlendorf <[email protected]>2016-03-08 17:46:41 -0800
commit048bb5bd4950b9cb5368ed93d273f0f36e439122 (patch)
tree69f13db478b1c730a8fb9907bf47bc2cd5fadb90 /cmd
parent272be6834c3989f13c51f65eba6ec1d776a0ad43 (diff)
Ensure zed _finish_daemonize() leaves fds 0-2 open
In zed's _finish_daemonize(), /dev/null is open()d onto a temporary file descriptor which is then dup()d onto stdin, stdout, and stderr. But if file descriptors 0, 1, or 2 are not already open at the start of this function, then the temporary file descriptor will fall within this range and be inadvertently closed when the function cleans up. This commit adds a check to prevent inadvertently closing this (presumably temporary) file descriptor when it shouldn't. Signed-off-by: Chris Dunlap <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #4384
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zed/zed.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/cmd/zed/zed.c b/cmd/zed/zed.c
index f85668fea..55ab68cd0 100644
--- a/cmd/zed/zed.c
+++ b/cmd/zed/zed.c
@@ -199,7 +199,7 @@ _finish_daemonize(void)
zed_log_die("Failed to dup /dev/null onto stderr: %s",
strerror(errno));
- if (close(devnull) < 0)
+ if ((devnull > STDERR_FILENO) && (close(devnull) < 0))
zed_log_die("Failed to close /dev/null: %s", strerror(errno));
/* Notify parent that daemonization is complete. */