Index: remoting/host/linux/linux_me2me_host.py |
diff --git a/remoting/host/linux/linux_me2me_host.py b/remoting/host/linux/linux_me2me_host.py |
index d2642ac52f7b6ce05d465a38341de9eecab77c67..53a090ac1c21556881be9f1cdcb52065bb1023fe 100755 |
--- a/remoting/host/linux/linux_me2me_host.py |
+++ b/remoting/host/linux/linux_me2me_host.py |
@@ -512,7 +512,7 @@ class Desktop: |
self.host_ready = True |
if (ParentProcessLogger.instance() and |
False not in [desktop.host_ready for desktop in g_desktops]): |
- ParentProcessLogger.instance().release_parent() |
+ ParentProcessLogger.instance().release_parent(True) |
signal.signal(signal.SIGUSR1, sigusr1_handler) |
args.append("--signal-parent") |
@@ -682,22 +682,31 @@ class ParentProcessLogger(object): |
ParentProcessLogger.__instance = self |
def start_logging(self): |
- """Installs a logging handler that sends log entries to a pipe. |
+ """Installs a logging handler that sends log entries to a pipe, prefixed |
+ with the string 'MSG:'. This allows them to be distinguished by the parent |
+ process from commands sent over the same pipe. |
Must be called by the child process. |
""" |
self._read_file.close() |
self._logging_handler = logging.StreamHandler(self._write_file) |
+ self._logging_handler.setFormatter(logging.Formatter(fmt='MSG:%(message)s')) |
logging.getLogger().addHandler(self._logging_handler) |
- def release_parent(self): |
+ def release_parent(self, success): |
"""Uninstalls logging handler and closes the pipe, releasing the parent. |
Must be called by the child process. |
+ |
+ success: If true, write a "host ready" message to the parent process before |
+ closing the pipe. |
""" |
if self._logging_handler: |
logging.getLogger().removeHandler(self._logging_handler) |
self._logging_handler = None |
+ if success: |
+ self._write_file.write("READY\n") |
+ self._write_file.flush() |
if not self._write_file.closed: |
self._write_file.close() |
@@ -730,13 +739,20 @@ class ParentProcessLogger(object): |
# Print lines as they're logged to the pipe until EOF is reached or readline |
# is interrupted by one of the signal handlers above. |
+ host_ready = False |
try: |
for line in iter(self._read_file.readline, ''): |
- sys.stderr.write(line) |
+ if line[:4] == "MSG:": |
+ sys.stderr.write(line[4:]) |
+ elif line == "READY\n": |
+ host_ready = True |
+ else: |
+ sys.stderr.write("Unrecognized command: " + line) |
except IOError as e: |
if e.errno != errno.EINTR: |
raise |
print("Log file: %s" % os.environ[LOG_FILE_ENV_VAR], file=sys.stderr) |
+ return host_ready |
@staticmethod |
def instance(): |
@@ -795,8 +811,10 @@ def daemonize(): |
os._exit(0) # pylint: disable=W0212 |
else: |
# Parent process |
- parent_logger.wait_for_logs() |
- os._exit(0) # pylint: disable=W0212 |
+ if parent_logger.wait_for_logs(): |
+ os._exit(0) # pylint: disable=W0212 |
+ else: |
+ os._exit(1) # pylint: disable=W0212 |
Lambros
2016/02/10 19:43:32
What will happen in the case of timeout after 30 s
Jamie
2016/02/11 00:00:22
According to the comment on line 733, the read loo
Lambros
2016/02/11 21:46:02
My reading of the old code is that, after the 30s
Jamie
2016/02/12 18:32:11
Good point. I've removed the timeout from this scr
|
logging.info("Daemon process started in the background, logging to '%s'" % |
os.environ[LOG_FILE_ENV_VAR]) |
@@ -842,7 +860,7 @@ def cleanup(): |
g_desktops = [] |
if ParentProcessLogger.instance(): |
- ParentProcessLogger.instance().release_parent() |
+ ParentProcessLogger.instance().release_parent(False) |
class SignalHandler: |
"""Reload the config file on SIGHUP. Since we pass the configuration to the |