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 6b62d26791c8cc21c723fcd6ae1840ace1e4a104..ef5b4c6b713dab07419e3728b60690b495046cb5 100755 |
| --- a/remoting/tools/me2me_virtual_host.py |
| +++ b/remoting/tools/me2me_virtual_host.py |
| @@ -634,16 +634,20 @@ def daemonize(log_filename): |
| def cleanup(): |
| logging.info("Cleanup.") |
| + global g_pidfile |
| if g_pidfile: |
| try: |
| g_pidfile.delete_file() |
| + g_pidfile = None |
| except Exception, e: |
| logging.error("Unexpected error deleting PID file: " + str(e)) |
| + global g_desktops |
| for desktop in g_desktops: |
| if desktop.x_proc: |
| logging.info("Terminating Xvfb") |
| desktop.x_proc.terminate() |
| + g_desktops = [] |
| def reload_config(): |
| @@ -663,6 +667,11 @@ def signal_handler(signum, stackframe): |
| raise SystemExit |
| +def relaunch_self(): |
| + cleanup() |
| + os.execvp(sys.argv[0], sys.argv) |
| + |
| + |
| def main(): |
| DEFAULT_SIZE = "1280x800" |
| parser = optparse.OptionParser( |
| @@ -873,32 +882,32 @@ def main(): |
| last_launch_time = 0 |
| while True: |
| - # If the session process stops running (e.g. because the user logged out), |
| - # the X server should be reset and the session restarted, to provide a |
| - # completely clean new session. |
| + # If the session process or X server stops running (e.g. because the user |
| + # logged out), re-run this script with its original arguments. Since the |
| + # user's desktop is already gone at this point, there's no state to lose |
| + # so now is a good time to pick up any updates to this script that might |
| + # have been installed. |
| if desktop.session_proc is None and desktop.x_proc is not None: |
| logging.info("Terminating X server") |
| desktop.x_proc.terminate() |
| - |
| - if desktop.x_proc is None: |
| - if desktop.session_proc is not None: |
| - # The X session would probably die soon if the X server is not |
| - # running (because of the loss of the X connection). Terminate it |
| - # anyway, to be sure. |
| - logging.info("Terminating X session") |
| - desktop.session_proc.terminate() |
| - else: |
| - # Neither X server nor X session are running. |
| - elapsed = time.time() - last_launch_time |
| - if elapsed < 60: |
| - logging.error("The session lasted less than 1 minute. Waiting " + |
| - "before starting new session.") |
| - time.sleep(60 - elapsed) |
| - |
| - logging.info("Launching X server and X session") |
| - last_launch_time = time.time() |
| - desktop.launch_x_server(args) |
| - desktop.launch_x_session() |
| + relaunch_self() |
| + elif desktop.x_proc is None and desktop.session_proc is not None: |
| + logging.info("Terminating X session") |
| + desktop.session_proc.terminate() |
| + relaunch_self() |
|
Lambros
2012/08/18 00:06:50
Unfortunately, calling relaunch_self() here (or ab
Jamie
2012/08/20 19:46:05
Good catch! Done.
|
| + |
| + if desktop.x_proc is None and desktop.session_proc is None: |
| + # Neither X server nor X session are running. |
| + elapsed = time.time() - last_launch_time |
| + if elapsed < 60: |
| + logging.error("The session lasted less than 1 minute. Waiting " + |
| + "before starting new session.") |
| + time.sleep(60 - elapsed) |
| + |
| + logging.info("Launching X server and X session") |
| + last_launch_time = time.time() |
| + desktop.launch_x_server(args) |
| + desktop.launch_x_session() |
| if desktop.host_proc is None: |
| logging.info("Launching host process") |