Commit ed3920e3 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix a rare bug in StartDaemonChild and GenericMain

I've seen cases where the result from str(sys.exc_info()[1]) is ""; this
breaks the error reporting as the parent relies on non-empty error
messages to properly detect child status (otherwise it will try to read
the pid and fail, so on).

While this was always in case of asserts, we need to ensure this doesn't
happen. Therefore we abstract this functionality (writing the error
message) and ensure we write a non-empty string in the new function.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 3e87c1bf
......@@ -671,8 +671,7 @@ def GenericMain(daemon_name, optionparser,
prep_results = None"%s daemon startup", daemon_name)
except Exception, err:
if wpipe is not None:
os.write(wpipe, _BeautifyError(err))
utils.WriteErrorToFD(wpipe, _BeautifyError(err))
if wpipe is not None:
......@@ -435,9 +435,7 @@ def _StartDaemonChild(errpipe_read, errpipe_write,
except: # pylint: disable-msg=W0702
# Report errors to original process
buf = str(sys.exc_info()[1])
RetryOnSignal(os.write, errpipe_write, buf)
WriteErrorToFD(errpipe_write, str(sys.exc_info()[1]))
except: # pylint: disable-msg=W0702
# Ignore errors in error handling
......@@ -445,6 +443,23 @@ def _StartDaemonChild(errpipe_read, errpipe_write,
os._exit(1) # pylint: disable-msg=W0212
def WriteErrorToFD(fd, err):
"""Possibly write an error message to a fd.
@type fd: None or int (file descriptor)
@param fd: if not None, the error will be written to this fd
@param err: string, the error message
if fd is None:
if not err:
err = "<unknown error>"
RetryOnSignal(os.write, fd, err)
def _RunCmdPipe(cmd, env, via_shell, cwd, interactive):
"""Run a command and return its output.
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