Chromium Code Reviews| Index: remoting/tools/me2me_virtual_host.py |
| diff --git a/remoting/tools/me2me_virtual_host.py b/remoting/tools/me2me_virtual_host.py |
| index 53a3118bc1602be68594b5668b48051abd2d2414..b159facac947824fa9c9e18550b28af7964fe561 100755 |
| --- a/remoting/tools/me2me_virtual_host.py |
| +++ b/remoting/tools/me2me_virtual_host.py |
| @@ -288,12 +288,14 @@ class Desktop: |
| def launch_host(self, host_config): |
| # Start remoting host |
| - args = [locate_executable(HOST_BINARY_NAME), |
| - "--host-config=%s" % (host_config.path)] |
| - self.host_proc = subprocess.Popen(args, env=self.child_env) |
| + args = [locate_executable(HOST_BINARY_NAME), "--host-config=/dev/stdin"] |
| + self.host_proc = subprocess.Popen(args, env=self.child_env, |
| + stdin=subprocess.PIPE) |
| logging.info(args) |
| if not self.host_proc.pid: |
| raise Exception("Could not start Chrome Remote Desktop host") |
| + self.host_proc.stdin.write(json.dumps(host_config.data)) |
| + self.host_proc.stdin.close() |
| class PidFile: |
| @@ -515,19 +517,27 @@ def cleanup(): |
| g_desktops = [] |
| -def reload_config(): |
| - for desktop in g_desktops: |
| - if desktop.host_proc: |
| - desktop.host_proc.send_signal(signal.SIGHUP) |
| +class SignalHandler: |
| + """Reload the config file on SIGHUP. Since we pass the configuration to the |
| + host processes via stdin, they can't reload it, so terminate them. They will |
| + be relaunched automatically with the new config.""" |
| + def __init__(self, host_config): |
| + self.host_config = host_config |
| -def signal_handler(signum, _stackframe): |
| - if signum == signal.SIGHUP: |
| - logging.info("SIGHUP caught, reloading configuration.") |
| - reload_config() |
| - else: |
| - # Exit cleanly so the atexit handler, cleanup(), gets called. |
| - raise SystemExit |
| + def __call__(self, signum, _stackframe): |
| + if signum == signal.SIGHUP: |
| + logging.info("SIGHUP caught, restarting host.") |
| + self.reload_config() |
| + else: |
| + # Exit cleanly so the atexit handler, cleanup(), gets called. |
| + raise SystemExit |
| + |
| + def reload_config(self): |
|
Sergey Ulanov
2012/09/04 22:01:48
This method is not used outside of this class, so
Jamie
2012/09/05 21:15:38
I just got rid of the function. There was no real
|
| + self.host_config.load() |
| + for desktop in g_desktops: |
| + if desktop.host_proc: |
| + desktop.host_proc.send_signal(signal.SIGTERM) |
| def relaunch_self(): |
| @@ -642,15 +652,15 @@ Web Store: https://chrome.google.com/remotedesktop""" |
| atexit.register(cleanup) |
| - for s in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM, signal.SIGUSR1]: |
| - signal.signal(s, signal_handler) |
| + config_filename = os.path.join(CONFIG_DIR, "host#%s.json" % host_hash) |
| + host_config = Config(config_filename) |
| - # Ensure full path to config directory exists. |
| - if not os.path.exists(CONFIG_DIR): |
| - os.makedirs(CONFIG_DIR, mode=0700) |
| + for s in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM, signal.SIGUSR1]: |
| + signal.signal(s, SignalHandler(host_config)) |
| - host_config = Config(os.path.join(CONFIG_DIR, "host#%s.json" % host_hash)) |
| - host_config.load() |
| + if (not host_config.load()): |
| + print >> sys.stderr, "Failed to load " + config_filename |
|
Lambros
2012/09/05 16:35:54
logging.error() is preferred for printing error me
|
| + return 1 |
| auth = Authentication() |
| auth_config_valid = auth.copy_from(host_config) |