Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: remoting/tools/me2me_virtual_host.py

Issue 10860024: Handle updates to the wrapper script. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reinstated spin protection. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/tools/is_me2me_desktop ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cee9654dcf5f79bdcbfa64440a9789d07acca44b 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,35 @@ 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), kill the other. This will trigger the next conditional block
+ # as soon as the os.wait() call (below) returns.
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")
+ elif desktop.x_proc is None and desktop.session_proc is not None:
+ logging.info("Terminating X session")
+ desktop.session_proc.terminate()
+ elif 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)
+
+ if last_launch_time == 0:
+ # Neither process has been started yet. Do so now.
+ logging.info("Launching X server and X session.")
last_launch_time = time.time()
desktop.launch_x_server(args)
desktop.launch_x_session()
+ else:
+ # Both processes have terminated. Since the user's desktop is already
+ # gone at this point, there's no state to lose and now is a good time
+ # to pick up any updates to this script that might have been installed.
+ logging.info("Relaunching self")
+ relaunch_self()
if desktop.host_proc is None:
logging.info("Launching host process")
« no previous file with comments | « remoting/tools/is_me2me_desktop ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698