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 <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 3f42b4f6
......@@ -251,8 +251,10 @@ def SetupDaemonFDs(output_file, output_fd):
# Open /dev/null (read-only, only for stdin)
devnull_fd = os.open(os.devnull, os.O_RDONLY)
output_close = True
if output_fd is not None:
pass
output_close = False
elif output_file is not None:
# Open output file
try:
......@@ -268,6 +270,12 @@ def SetupDaemonFDs(output_file, output_fd):
os.dup2(output_fd, 1)
os.dup2(output_fd, 2)
if devnull_fd > 2:
utils_wrapper.CloseFdNoError(devnull_fd)
if output_close and output_fd > 2:
utils_wrapper.CloseFdNoError(output_fd)
def StartDaemon(cmd, env=None, cwd="/", output=None, output_fd=None,
pidfile=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