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 b295824466dec0be46e05f3b8fde3be4188eb7b0..87d1800355ffdd6d752a84918e5169522c6e08be 100755 |
| --- a/remoting/tools/me2me_virtual_host.py |
| +++ b/remoting/tools/me2me_virtual_host.py |
| @@ -33,6 +33,13 @@ import uuid |
| import gaia_auth |
| import keygen |
| +# The X session command is normally determined automatically. To use a |
|
Wez
2012/07/12 21:18:14
nit: "By default this script will try to determine
Lambros
2012/07/13 00:30:18
Done.
|
| +# specific session instead, set this variable to the executable filename, or a |
| +# list containing the executable and any arguments, for example: |
| +# XSESSION_COMMAND = "/usr/bin/gnome-session-fallback" |
| +# XSESSION_COMMAND = ["/usr/bin/gnome-session", "--session=ubuntu-2d"] |
| +XSESSION_COMMAND = None |
| + |
| REMOTING_COMMAND = "remoting_me2me_host" |
| # Command-line switch for passing the config path to remoting_me2me_host. |
| @@ -333,14 +340,13 @@ class Desktop: |
| def launch_x_session(self): |
| # Start desktop session |
| - # The /dev/null input redirection is necessary to prevent Xsession from |
| + # The /dev/null input redirection is necessary to prevent the X session |
| # reading from stdin. If this code runs as a shell background job in a |
| # terminal, any reading from stdin causes the job to be suspended. |
| # Daemonization would solve this problem by separating the process from the |
| # controlling terminal. |
| - # |
| - # This assumes that GDM is installed and configured on the system. |
| - self.session_proc = subprocess.Popen("/etc/gdm/Xsession", |
| + logging.info("Launching X session: %s" % XSESSION_COMMAND) |
| + self.session_proc = subprocess.Popen(XSESSION_COMMAND, |
| stdin=open(os.devnull, "r"), |
| cwd=HOME_DIR, |
| env=self.child_env) |
| @@ -439,6 +445,46 @@ class PidFile: |
| os.remove(self.filename) |
| +def choose_x_session(): |
| + """Finds an appropriate choice of X session command for this system. |
|
Wez
2012/07/12 21:18:14
nit: "Chooses the most appropriate X session comma
Lambros
2012/07/13 00:30:18
Done.
|
| + |
| + If XSESSION_COMMAND is already set, its value is returned directly. |
| + Otherwise, a session is chosen for this system. |
| + |
| + This may print some information to stderr, so this function is called |
| + before daemonization, and the result is assigned to XSESSION_COMMAND. This |
| + way, any problems or errors can be reported before daemonization occurs. |
|
Wez
2012/07/12 21:18:14
You print the information to stderr so that it wil
Lambros
2012/07/13 00:30:18
Removed the side-effect.
|
| + |
| + Returns: |
| + A string containing the command to run, or a list of strings containing |
| + the executable program and its arguments, which is suitable for passing as |
| + the first parameter of subprocess.Popen(). If a suitable session cannot |
| + be found, returns None. |
| + """ |
| + if XSESSION_COMMAND is not None: |
| + return XSESSION_COMMAND |
| + |
| + for candidate in [ |
| + "/usr/bin/gnome-session-fallback", |
| + "/etc/gdm/Xsession"]: |
| + if os.path.exists(candidate): |
| + return candidate |
|
Wez
2012/07/12 21:18:14
You could structure this as a dictionary of {file-
Lambros
2012/07/13 00:30:18
Done, but with a list instead of a dictionary, bec
|
| + |
| + # Unity-2d would normally be the preferred choice on Ubuntu 12.04. At the |
| + # time of writing, this session does not work properly (missing launcher and |
| + # panel), so gnome-session-fallback is used in preference. |
| + # "unity-2d-panel" was chosen here simply because it appears in the TryExec |
| + # line of the session's .desktop file; other choices might be just as good. |
| + if os.path.exists("/usr/bin/unity-2d-panel"): |
| + print >> sys.stderr, ( |
| + "The Unity 2D desktop session will be used.\n" |
| + "If you encounter problems with this choice of desktop, please install\n" |
| + "the gnome-session-fallback package, and restart this script.\n") |
|
Wez
2012/07/12 21:18:14
It would be cleaner to have the calling code test
Lambros
2012/07/13 00:30:18
Done.
|
| + return ["/usr/bin/gnome-session", "--session=ubuntu-2d"] |
| + |
| + return None |
| + |
| + |
| def locate_executable(exe_name): |
| for path in EXE_PATHS_TO_TRY: |
| exe_path = os.path.join(SCRIPT_PATH, path, exe_name) |
| @@ -588,6 +634,12 @@ def main(): |
| except ValueError: |
| parser.error("Width and height should be 100 pixels or greater") |
| + global XSESSION_COMMAND |
| + XSESSION_COMMAND = choose_x_session() |
| + if XSESSION_COMMAND is None: |
| + print "Unable to choose suitable X session command" |
| + return 1 |
| + |
| atexit.register(cleanup) |
| for s in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM, signal.SIGUSR1]: |