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. |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 ParentProcessLogger.instance().release_parent() | 502 ParentProcessLogger.instance().release_parent() |
503 | 503 |
504 signal.signal(signal.SIGUSR1, sigusr1_handler) | 504 signal.signal(signal.SIGUSR1, sigusr1_handler) |
505 args.append("--signal-parent") | 505 args.append("--signal-parent") |
506 | 506 |
507 self.host_proc = subprocess.Popen(args, env=self.child_env, | 507 self.host_proc = subprocess.Popen(args, env=self.child_env, |
508 stdin=subprocess.PIPE) | 508 stdin=subprocess.PIPE) |
509 logging.info(args) | 509 logging.info(args) |
510 if not self.host_proc.pid: | 510 if not self.host_proc.pid: |
511 raise Exception("Could not start Chrome Remote Desktop host") | 511 raise Exception("Could not start Chrome Remote Desktop host") |
512 self.host_proc.stdin.write(json.dumps(host_config.data)) | 512 |
513 self.host_proc.stdin.close() | 513 try: |
| 514 self.host_proc.stdin.write(json.dumps(host_config.data)) |
| 515 self.host_proc.stdin.flush() |
| 516 except IOError as e: |
| 517 # This can occur in rare situations, for example, if the machine is |
| 518 # heavily loaded and the host process dies quickly (maybe if the X |
| 519 # connection failed), the host process might be gone before this code |
| 520 # writes to the host's stdin. Catch and log the exception, allowing |
| 521 # the process to be retried instead of exiting the script completely. |
| 522 logging.error("Failed writing to host's stdin: " + str(e)) |
| 523 finally: |
| 524 self.host_proc.stdin.close() |
514 | 525 |
515 | 526 |
516 def get_daemon_proc(): | 527 def get_daemon_proc(): |
517 """Checks if there is already an instance of this script running, and returns | 528 """Checks if there is already an instance of this script running, and returns |
518 a psutil.Process instance for it. | 529 a psutil.Process instance for it. |
519 | 530 |
520 Returns: | 531 Returns: |
521 A Process instance for the existing daemon process, or None if the daemon | 532 A Process instance for the existing daemon process, or None if the daemon |
522 is not running. | 533 is not running. |
523 """ | 534 """ |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 else: | 1353 else: |
1343 logging.info("Host exited with status %s." % os.WEXITSTATUS(status)) | 1354 logging.info("Host exited with status %s." % os.WEXITSTATUS(status)) |
1344 elif os.WIFSIGNALED(status): | 1355 elif os.WIFSIGNALED(status): |
1345 logging.info("Host terminated by signal %s." % os.WTERMSIG(status)) | 1356 logging.info("Host terminated by signal %s." % os.WTERMSIG(status)) |
1346 | 1357 |
1347 | 1358 |
1348 if __name__ == "__main__": | 1359 if __name__ == "__main__": |
1349 logging.basicConfig(level=logging.DEBUG, | 1360 logging.basicConfig(level=logging.DEBUG, |
1350 format="%(asctime)s:%(levelname)s:%(message)s") | 1361 format="%(asctime)s:%(levelname)s:%(message)s") |
1351 sys.exit(main()) | 1362 sys.exit(main()) |
OLD | NEW |