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.
This commit is contained in:
Michael Raitza 2019-02-09 19:17:34 +01:00
commit c18c4b92c9

View file

@ -37,6 +37,7 @@ def start_stdin_log_reader(status, details, pretty, color,
After this, be sure to run await_log_reader() before exiting. After this, be sure to run await_log_reader() before exiting.
""" """
global log_reader_pid global log_reader_pid
global stderr_fd
r, w = os.pipe() # main pipe to redo-log r, w = os.pipe() # main pipe to redo-log
ar, aw = os.pipe() # ack pipe from redo-log --ack-fd ar, aw = os.pipe() # ack pipe from redo-log --ack-fd
sys.stdout.flush() sys.stdout.flush()
@ -45,6 +46,7 @@ def start_stdin_log_reader(status, details, pretty, color,
if pid: if pid:
# parent # parent
log_reader_pid = pid log_reader_pid = pid
stderr_fd = os.dup(2) # save our stderr for after the log pipe gets closed
os.close(r) os.close(r)
os.close(aw) os.close(aw)
b = os.read(ar, 8) b = os.read(ar, 8)
@ -95,6 +97,7 @@ def start_stdin_log_reader(status, details, pretty, color,
def await_log_reader(): def await_log_reader():
"""Await the redo-log instance we redirected stderr to, if any.""" """Await the redo-log instance we redirected stderr to, if any."""
global stderr_fd
if not env.v.LOG: if not env.v.LOG:
return return
if log_reader_pid > 0: if log_reader_pid > 0:
@ -103,9 +106,8 @@ def await_log_reader():
# Since our stdout/stderr are attached to redo-log's stdin, # 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 # this will notify redo-log that it's time to die (after it finishes
# reading the logs) # reading the logs)
out = open('/dev/tty', 'w') os.dup2(stderr_fd, 1)
os.dup2(out.fileno(), 1) os.dup2(stderr_fd, 2)
os.dup2(out.fileno(), 2)
os.waitpid(log_reader_pid, 0) os.waitpid(log_reader_pid, 0)