Commit 638ac34b authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Don't leak file descriptors when setting up daemon output

When a daemon's output is configured using “utils.SetupDaemonFDs”, the
function must use dup2(2). Unfortunately the code didn't close the
original file descriptors, leaking them in the process.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 3f42b4f6
......@@ -251,8 +251,10 @@ def SetupDaemonFDs(output_file, output_fd):
# Open /dev/null (read-only, only for stdin)
devnull_fd =, os.O_RDONLY)
output_close = True
if output_fd is not None:
output_close = False
elif output_file is not None:
# Open output file
......@@ -268,6 +270,12 @@ def SetupDaemonFDs(output_file, output_fd):
os.dup2(output_fd, 1)
os.dup2(output_fd, 2)
if devnull_fd > 2:
if output_close and output_fd > 2:
def StartDaemon(cmd, env=None, cwd="/", output=None, output_fd=None,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment