| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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. |
| 11 | 11 |
| 12 import atexit | 12 import atexit |
| 13 import errno | 13 import errno |
| 14 import getpass | 14 import getpass |
| 15 import hashlib | 15 import hashlib |
| 16 import json | 16 import json |
| 17 import logging | 17 import logging |
| 18 import optparse | 18 import optparse |
| 19 import os | 19 import os |
| 20 import pipes |
| 20 import signal | 21 import signal |
| 21 import socket | 22 import socket |
| 22 import subprocess | 23 import subprocess |
| 23 import sys | 24 import sys |
| 24 import tempfile | 25 import tempfile |
| 25 import time | 26 import time |
| 26 import uuid | 27 import uuid |
| 27 | 28 |
| 28 # By default this script will try to determine the most appropriate X session | 29 # By default this script will try to determine the most appropriate X session |
| 29 # command for the system. To use a specific session instead, set this variable | 30 # command for the system. To use a specific session instead, set this variable |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 # list. | 343 # list. |
| 343 label = "%dx%d" % self.sizes[0] | 344 label = "%dx%d" % self.sizes[0] |
| 344 args = ["xrandr", "-s", label] | 345 args = ["xrandr", "-s", label] |
| 345 proc = subprocess.Popen(args, env=self.child_env, stdout=devnull, | 346 proc = subprocess.Popen(args, env=self.child_env, stdout=devnull, |
| 346 stderr=devnull) | 347 stderr=devnull) |
| 347 proc.wait() | 348 proc.wait() |
| 348 | 349 |
| 349 devnull.close() | 350 devnull.close() |
| 350 | 351 |
| 351 def _launch_x_session(self): | 352 def _launch_x_session(self): |
| 352 # Start desktop session | 353 # Start desktop session. |
| 353 # The /dev/null input redirection is necessary to prevent the X session | 354 # The /dev/null input redirection is necessary to prevent the X session |
| 354 # reading from stdin. If this code runs as a shell background job in a | 355 # reading from stdin. If this code runs as a shell background job in a |
| 355 # terminal, any reading from stdin causes the job to be suspended. | 356 # terminal, any reading from stdin causes the job to be suspended. |
| 356 # Daemonization would solve this problem by separating the process from the | 357 # Daemonization would solve this problem by separating the process from the |
| 357 # controlling terminal. | 358 # controlling terminal. |
| 358 logging.info("Launching X session: %s" % XSESSION_COMMAND) | 359 logging.info("Launching X session: %s" % XSESSION_COMMAND) |
| 359 self.session_proc = subprocess.Popen(XSESSION_COMMAND, | 360 self.session_proc = subprocess.Popen(XSESSION_COMMAND, |
| 360 stdin=open(os.devnull, "r"), | 361 stdin=open(os.devnull, "r"), |
| 361 cwd=HOME_DIR, | 362 cwd=HOME_DIR, |
| 362 env=self.child_env) | 363 env=self.child_env) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 "~/.chrome-remote-desktop-session", | 492 "~/.chrome-remote-desktop-session", |
| 492 "~/.xsession", | 493 "~/.xsession", |
| 493 "~/.Xsession" ] | 494 "~/.Xsession" ] |
| 494 for startup_file in XSESSION_FILES: | 495 for startup_file in XSESSION_FILES: |
| 495 startup_file = os.path.expanduser(startup_file) | 496 startup_file = os.path.expanduser(startup_file) |
| 496 if os.path.exists(startup_file): | 497 if os.path.exists(startup_file): |
| 497 # Use the same logic that a Debian system typically uses with ~/.xsession | 498 # Use the same logic that a Debian system typically uses with ~/.xsession |
| 498 # (see /etc/X11/Xsession.d/50x11-common_determine-startup), to determine | 499 # (see /etc/X11/Xsession.d/50x11-common_determine-startup), to determine |
| 499 # exactly how to run this file. | 500 # exactly how to run this file. |
| 500 if os.access(startup_file, os.X_OK): | 501 if os.access(startup_file, os.X_OK): |
| 501 return startup_file | 502 # "/bin/sh -c" is smart about how to execute the session script and |
| 503 # works in cases where plain exec() fails (for example, if the file is |
| 504 # marked executable, but is a plain script with no shebang line). |
| 505 return ["/bin/sh", "-c", pipes.quote(startup_file)] |
| 502 else: | 506 else: |
| 503 shell = os.environ.get("SHELL", "sh") | 507 shell = os.environ.get("SHELL", "sh") |
| 504 return [shell, startup_file] | 508 return [shell, startup_file] |
| 505 | 509 |
| 506 # Choose a session wrapper script to run the session. On some systems, | 510 # Choose a session wrapper script to run the session. On some systems, |
| 507 # /etc/X11/Xsession fails to load the user's .profile, so look for an | 511 # /etc/X11/Xsession fails to load the user's .profile, so look for an |
| 508 # alternative wrapper that is more likely to match the script that the | 512 # alternative wrapper that is more likely to match the script that the |
| 509 # system actually uses for console desktop sessions. | 513 # system actually uses for console desktop sessions. |
| 510 SESSION_WRAPPERS = [ | 514 SESSION_WRAPPERS = [ |
| 511 "/usr/sbin/lightdm-session", | 515 "/usr/sbin/lightdm-session", |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 host_config.clear_auth() | 1054 host_config.clear_auth() |
| 1051 host_config.clear_host_info() | 1055 host_config.clear_host_info() |
| 1052 host_config.save() | 1056 host_config.save() |
| 1053 return 0 | 1057 return 0 |
| 1054 | 1058 |
| 1055 | 1059 |
| 1056 if __name__ == "__main__": | 1060 if __name__ == "__main__": |
| 1057 logging.basicConfig(level=logging.DEBUG, | 1061 logging.basicConfig(level=logging.DEBUG, |
| 1058 format="%(asctime)s:%(levelname)s:%(message)s") | 1062 format="%(asctime)s:%(levelname)s:%(message)s") |
| 1059 sys.exit(main()) | 1063 sys.exit(main()) |
| OLD | NEW |