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

Side by Side Diff: remoting/tools/me2me_virtual_host.py

Issue 11715003: Improve xsession execution (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 12 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 # list. 342 # list.
343 label = "%dx%d" % self.sizes[0] 343 label = "%dx%d" % self.sizes[0]
344 args = ["xrandr", "-s", label] 344 args = ["xrandr", "-s", label]
345 proc = subprocess.Popen(args, env=self.child_env, stdout=devnull, 345 proc = subprocess.Popen(args, env=self.child_env, stdout=devnull,
346 stderr=devnull) 346 stderr=devnull)
347 proc.wait() 347 proc.wait()
348 348
349 devnull.close() 349 devnull.close()
350 350
351 def _launch_x_session(self): 351 def _launch_x_session(self):
352 # Start desktop session 352 # Start desktop session.
353 # The /dev/null input redirection is necessary to prevent the X session 353 # 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 354 # 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. 355 # terminal, any reading from stdin causes the job to be suspended.
356 # Daemonization would solve this problem by separating the process from the 356 # Daemonization would solve this problem by separating the process from the
357 # controlling terminal. 357 # controlling terminal.
358 # If XSESSION_COMMAND is a single item, running with shell=True will
359 # run the file with "/bin/sh -c" which is intelligent about how to execute
360 # the file: It will try to exec() it directly and if that fails, it will
361 # parse any she-bang line and use that, otherwise it will run the file's
362 # contents as a shell-script.
358 logging.info("Launching X session: %s" % XSESSION_COMMAND) 363 logging.info("Launching X session: %s" % XSESSION_COMMAND)
359 self.session_proc = subprocess.Popen(XSESSION_COMMAND, 364 self.session_proc = subprocess.Popen(XSESSION_COMMAND,
360 stdin=open(os.devnull, "r"), 365 stdin=open(os.devnull, "r"),
361 cwd=HOME_DIR, 366 cwd=HOME_DIR,
362 env=self.child_env) 367 env=self.child_env,
368 shell=isinstance(
Sergey Ulanov 2013/01/02 18:42:42 It looks wrong to use shell=True in some cases, bu
Wez 2013/01/02 19:46:20 Two reasons for preferring "shell=False": 1. Redu
Sergey Ulanov 2013/01/02 22:56:54 Not sure how this makes any difference. The comman
369 XSESSION_COMMAND, str))
363 if not self.session_proc.pid: 370 if not self.session_proc.pid:
364 raise Exception("Could not start X session") 371 raise Exception("Could not start X session")
365 372
366 def launch_session(self, x_args): 373 def launch_session(self, x_args):
367 self._init_child_env() 374 self._init_child_env()
368 self._setup_pulseaudio() 375 self._setup_pulseaudio()
369 self._launch_x_server(x_args) 376 self._launch_x_server(x_args)
370 self._launch_x_session() 377 self._launch_x_session()
371 378
372 def launch_host(self, host_config): 379 def launch_host(self, host_config):
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 480
474 If XSESSION_COMMAND is already set, its value is returned directly. 481 If XSESSION_COMMAND is already set, its value is returned directly.
475 Otherwise, a session is chosen for this system. 482 Otherwise, a session is chosen for this system.
476 483
477 Returns: 484 Returns:
478 A string containing the command to run, or a list of strings containing 485 A string containing the command to run, or a list of strings containing
479 the executable program and its arguments, which is suitable for passing as 486 the executable program and its arguments, which is suitable for passing as
480 the first parameter of subprocess.Popen(). If a suitable session cannot 487 the first parameter of subprocess.Popen(). If a suitable session cannot
481 be found, returns None. 488 be found, returns None.
482 """ 489 """
483 if XSESSION_COMMAND is not None: 490 if XSESSION_COMMAND is not None:
Sergey Ulanov 2013/01/02 22:56:54 It looks wrong that choose_x_session() is used to
Lambros 2013/01/03 01:50:26 I'm going to remove XSESSION_COMMAND altogether, i
484 return XSESSION_COMMAND 491 return XSESSION_COMMAND
485 492
486 # If the session wrapper script (see below) is given a specific session as an 493 # If the session wrapper script (see below) is given a specific session as an
487 # argument (such as ubuntu-2d on Ubuntu 12.04), the wrapper will run that 494 # argument (such as ubuntu-2d on Ubuntu 12.04), the wrapper will run that
488 # session instead of looking for custom .xsession files in the home directory. 495 # session instead of looking for custom .xsession files in the home directory.
489 # So it's necessary to test for these files here. 496 # So it's necessary to test for these files here.
490 XSESSION_FILES = [ 497 XSESSION_FILES = [
491 "~/.chrome-remote-desktop-session", 498 "~/.chrome-remote-desktop-session",
492 "~/.xsession", 499 "~/.xsession",
493 "~/.Xsession" ] 500 "~/.Xsession" ]
494 for startup_file in XSESSION_FILES: 501 for startup_file in XSESSION_FILES:
495 startup_file = os.path.expanduser(startup_file) 502 startup_file = os.path.expanduser(startup_file)
496 if os.path.exists(startup_file): 503 if os.path.exists(startup_file):
497 # Use the same logic that a Debian system typically uses with ~/.xsession 504 return startup_file
Sergey Ulanov 2013/01/02 22:56:54 Does this still work correctly when .xsession or .
498 # (see /etc/X11/Xsession.d/50x11-common_determine-startup), to determine
499 # exactly how to run this file.
500 if os.access(startup_file, os.X_OK):
501 return startup_file
Sergey Ulanov 2013/01/02 22:56:54 An alternative fix is to change this line to retur
Lambros 2013/01/03 01:50:26 Done.
502 else:
503 shell = os.environ.get("SHELL", "sh")
504 return [shell, startup_file]
505 505
506 # Choose a session wrapper script to run the session. On some systems, 506 # 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 507 # /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 508 # alternative wrapper that is more likely to match the script that the
509 # system actually uses for console desktop sessions. 509 # system actually uses for console desktop sessions.
510 SESSION_WRAPPERS = [ 510 SESSION_WRAPPERS = [
511 "/usr/sbin/lightdm-session", 511 "/usr/sbin/lightdm-session",
512 "/etc/gdm/Xsession", 512 "/etc/gdm/Xsession",
513 "/etc/X11/Xsession" ] 513 "/etc/X11/Xsession" ]
514 for session_wrapper in SESSION_WRAPPERS: 514 for session_wrapper in SESSION_WRAPPERS:
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 host_config.clear_auth() 1050 host_config.clear_auth()
1051 host_config.clear_host_info() 1051 host_config.clear_host_info()
1052 host_config.save() 1052 host_config.save()
1053 return 0 1053 return 0
1054 1054
1055 1055
1056 if __name__ == "__main__": 1056 if __name__ == "__main__":
1057 logging.basicConfig(level=logging.DEBUG, 1057 logging.basicConfig(level=logging.DEBUG,
1058 format="%(asctime)s:%(levelname)s:%(message)s") 1058 format="%(asctime)s:%(levelname)s:%(message)s")
1059 sys.exit(main()) 1059 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698