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 <cdunlap@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4384
This commit is contained in:
Chris Dunlap 2016-03-01 12:23:55 -08:00 committed by Brian Behlendorf
parent 272be6834c
commit 048bb5bd49
1 changed files with 1 additions and 1 deletions

View File

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