Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # Virtual Me2Me implementation. This script runs and manages the processes | 6 # Virtual Me2Me implementation. This script runs and manages the processes |
| 7 # required for a Virtual Me2Me desktop, which are: X server, X desktop | 7 # required for a Virtual Me2Me desktop, which are: X server, X desktop |
| 8 # session, and Host process. | 8 # session, and Host process. |
| 9 # This script is intended to run continuously as a background daemon | 9 # This script is intended to run continuously as a background daemon |
| 10 # process, running under an ordinary (non-root) user account. | 10 # process, running under an ordinary (non-root) user account. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 import time | 22 import time |
| 23 import urllib2 | 23 import urllib2 |
| 24 import uuid | 24 import uuid |
| 25 | 25 |
| 26 # Local modules | 26 # Local modules |
| 27 import gaia_auth | 27 import gaia_auth |
| 28 import keygen | 28 import keygen |
| 29 | 29 |
| 30 REMOTING_COMMAND = "remoting_me2me_host" | 30 REMOTING_COMMAND = "remoting_me2me_host" |
| 31 | 31 |
| 32 # Command-line switch for passing the config path to remoting_me2me_host. | |
| 33 HOST_CONFIG_SWITCH_NAME = "host-config" | |
| 34 | |
| 32 SCRIPT_PATH = os.path.dirname(sys.argv[0]) | 35 SCRIPT_PATH = os.path.dirname(sys.argv[0]) |
| 33 if not SCRIPT_PATH: | 36 if not SCRIPT_PATH: |
| 34 SCRIPT_PATH = os.getcwd() | 37 SCRIPT_PATH = os.getcwd() |
| 35 | 38 |
| 36 # These are relative to SCRIPT_PATH. | 39 # These are relative to SCRIPT_PATH. |
| 37 EXE_PATHS_TO_TRY = [ | 40 EXE_PATHS_TO_TRY = [ |
| 38 ".", | 41 ".", |
| 39 "../../out/Debug", | 42 "../../out/Debug", |
| 40 "../../out/Release" | 43 "../../out/Release" |
| 41 ] | 44 ] |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 logging.info("Xvfb is active.") | 256 logging.info("Xvfb is active.") |
| 254 | 257 |
| 255 def launch_x_session(self): | 258 def launch_x_session(self): |
| 256 # Start desktop session | 259 # Start desktop session |
| 257 session_proc = subprocess.Popen("/etc/X11/Xsession", | 260 session_proc = subprocess.Popen("/etc/X11/Xsession", |
| 258 cwd=os.environ["HOME"], | 261 cwd=os.environ["HOME"], |
| 259 env=self.child_env) | 262 env=self.child_env) |
| 260 if not session_proc.pid: | 263 if not session_proc.pid: |
| 261 raise Exception("Could not start X session") | 264 raise Exception("Could not start X session") |
| 262 | 265 |
| 263 def launch_host(self): | 266 def launch_host(self, host): |
| 264 # Start remoting host | 267 # Start remoting host |
| 265 command = locate_executable(REMOTING_COMMAND) | 268 args = [locate_executable(REMOTING_COMMAND), |
| 266 self.host_proc = subprocess.Popen(command, env=self.child_env) | 269 "--%s=%s" % (HOST_CONFIG_SWITCH_NAME, host.config_file)] |
|
Wez
2011/12/10 00:00:09
Is it possible for |config_file| to contain anythi
Lambros
2011/12/10 02:00:31
This shouldn't confuse popen(), because the whole
| |
| 270 self.host_proc = subprocess.Popen(args, env=self.child_env) | |
| 267 if not self.host_proc.pid: | 271 if not self.host_proc.pid: |
| 268 raise Exception("Could not start remoting host") | 272 raise Exception("Could not start remoting host") |
| 269 | 273 |
| 270 | 274 |
| 271 def main(): | 275 def main(): |
| 272 atexit.register(cleanup) | 276 atexit.register(cleanup) |
| 273 | 277 |
| 274 for s in [signal.SIGINT, signal.SIGTERM]: | 278 for s in [signal.SIGINT, signal.SIGTERM]: |
| 275 signal.signal(s, signal_handler) | 279 signal.signal(s, signal_handler) |
| 276 | 280 |
| 277 # Ensure full path to config directory exists. | 281 # Ensure full path to config directory exists. |
| 278 if not os.path.exists(CONFIG_DIR): | 282 if not os.path.exists(CONFIG_DIR): |
| 279 os.makedirs(CONFIG_DIR, mode=0700) | 283 os.makedirs(CONFIG_DIR, mode=0700) |
| 280 | 284 |
| 281 auth = Authentication(os.path.join(CONFIG_DIR, "auth.json")) | 285 auth = Authentication(os.path.join(CONFIG_DIR, "auth.json")) |
| 282 if not auth.load_config(): | 286 if not auth.load_config(): |
| 283 try: | 287 try: |
| 284 auth.refresh_tokens() | 288 auth.refresh_tokens() |
| 285 except: | 289 except: |
| 286 logging.error("Authentication failed.") | 290 logging.error("Authentication failed.") |
| 287 return 1 | 291 return 1 |
| 288 auth.save_config() | 292 auth.save_config() |
| 289 | 293 |
| 290 host = Host(os.path.join(CONFIG_DIR, "host.json")) | 294 host = Host(os.path.join(CONFIG_DIR, "host#%s.json" % socket.gethostname())) |
|
Wez
2011/12/10 00:00:09
Is socket.gethostname() reliable, e.g. if the host
Lambros
2011/12/10 02:00:31
Python doc isn't helpful here, it says only that i
| |
| 291 | 295 |
| 292 if not host.load_config(): | 296 if not host.load_config(): |
| 293 host.create_config(auth) | 297 host.create_config(auth) |
| 294 host.save_config() | 298 host.save_config() |
| 295 | 299 |
| 296 logging.info("Using host_id: " + host.host_id) | 300 logging.info("Using host_id: " + host.host_id) |
| 297 | 301 |
| 298 desktop = Desktop() | 302 desktop = Desktop() |
| 299 desktop.launch_x_server() | 303 desktop.launch_x_server() |
| 300 desktop.launch_x_session() | 304 desktop.launch_x_session() |
| 301 desktop.launch_host() | 305 desktop.launch_host(host) |
| 302 | 306 |
| 303 while True: | 307 while True: |
| 304 pid, status = os.wait() | 308 pid, status = os.wait() |
| 305 logging.info("wait() returned (%s,%s)" % (pid, status)) | 309 logging.info("wait() returned (%s,%s)" % (pid, status)) |
| 306 | 310 |
| 307 if pid == desktop.x_proc.pid: | 311 if pid == desktop.x_proc.pid: |
| 308 logging.info("X server process terminated with code %d", status) | 312 logging.info("X server process terminated with code %d", status) |
| 309 break | 313 break |
| 310 | 314 |
| 311 if pid == desktop.host_proc.pid: | 315 if pid == desktop.host_proc.pid: |
| 312 logging.info("Host process terminated, relaunching") | 316 logging.info("Host process terminated, relaunching") |
| 313 desktop.launch_host() | 317 desktop.launch_host(host) |
| 314 | 318 |
| 315 if __name__ == "__main__": | 319 if __name__ == "__main__": |
| 316 logging.basicConfig(level=logging.DEBUG) | 320 logging.basicConfig(level=logging.DEBUG) |
| 317 sys.exit(main()) | 321 sys.exit(main()) |
| OLD | NEW |