From c18c4b92c9a2b23f0ce06d9aebf151bdaded6dd1 Mon Sep 17 00:00:00 2001 From: Michael Raitza Date: Sat, 9 Feb 2019 19:17:34 +0100 Subject: [PATCH] Fix builder: Reinstate stderr instead of opening /dev/tty Reconnect the builder's original stderr file descriptor after the logger has finished its job. Fixes that redo could not be run without a controlling terminal. --- redo/builder.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/redo/builder.py b/redo/builder.py index 94788aa..b226110 100644 --- a/redo/builder.py +++ b/redo/builder.py @@ -37,6 +37,7 @@ def start_stdin_log_reader(status, details, pretty, color, After this, be sure to run await_log_reader() before exiting. """ global log_reader_pid + global stderr_fd r, w = os.pipe() # main pipe to redo-log ar, aw = os.pipe() # ack pipe from redo-log --ack-fd sys.stdout.flush() @@ -45,6 +46,7 @@ def start_stdin_log_reader(status, details, pretty, color, if pid: # parent log_reader_pid = pid + stderr_fd = os.dup(2) # save our stderr for after the log pipe gets closed os.close(r) os.close(aw) b = os.read(ar, 8) @@ -95,6 +97,7 @@ def start_stdin_log_reader(status, details, pretty, color, def await_log_reader(): """Await the redo-log instance we redirected stderr to, if any.""" + global stderr_fd if not env.v.LOG: return if log_reader_pid > 0: @@ -103,9 +106,8 @@ def await_log_reader(): # Since our stdout/stderr are attached to redo-log's stdin, # this will notify redo-log that it's time to die (after it finishes # reading the logs) - out = open('/dev/tty', 'w') - os.dup2(out.fileno(), 1) - os.dup2(out.fileno(), 2) + os.dup2(stderr_fd, 1) + os.dup2(stderr_fd, 2) os.waitpid(log_reader_pid, 0)