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

Side by Side Diff: remoting/host/linux/linux_me2me_host.py

Issue 2537673002: Update linux_me2me_host.py to exit when Ctrl-C is pressed. (Closed)
Patch Set: . Created 4 years 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
« 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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 def wait_for_logs(self): 855 def wait_for_logs(self):
856 """Waits and prints log lines from the daemon until the pipe is closed. 856 """Waits and prints log lines from the daemon until the pipe is closed.
857 857
858 Must be called by the parent process. 858 Must be called by the parent process.
859 859
860 Returns: 860 Returns:
861 True if the host started and successfully registered with the directory; 861 True if the host started and successfully registered with the directory;
862 false otherwise. 862 false otherwise.
863 """ 863 """
864 # If Ctrl-C is pressed, inform the user that the daemon is still running. 864 # If Ctrl-C is pressed, inform the user that the daemon is still running.
865 # This signal will cause the read loop below to stop with an EINTR IOError.
866 def sigint_handler(signum, frame): 865 def sigint_handler(signum, frame):
867 _ = signum, frame 866 _ = signum, frame
868 print("Interrupted. The daemon is still running in the background.", 867 print("Interrupted. The daemon is still running in the background.",
869 file=sys.stderr) 868 file=sys.stderr)
869 sys.exit(1)
870 870
871 signal.signal(signal.SIGINT, sigint_handler) 871 signal.signal(signal.SIGINT, sigint_handler)
872 872
873 # Install a fallback timeout to release the parent process, in case the 873 # Install a fallback timeout to release the parent process, in case the
874 # daemon never responds (e.g. host crash-looping, daemon killed). 874 # daemon never responds (e.g. host crash-looping, daemon killed).
875 # This signal will cause the read loop below to stop with an EINTR IOError. 875 # This signal will cause the read loop below to stop with an EINTR IOError.
876 # 876 #
877 # The value of 120s is chosen to match the heartbeat retry timeout in 877 # The value of 120s is chosen to match the heartbeat retry timeout in
878 # hearbeat_sender.cc. 878 # hearbeat_sender.cc.
879 def sigalrm_handler(signum, frame): 879 def sigalrm_handler(signum, frame):
880 _ = signum, frame 880 _ = signum, frame
881 print("No response from daemon. It may have crashed, or may still be " 881 print("No response from daemon. It may have crashed, or may still be "
882 "running in the background.", file=sys.stderr) 882 "running in the background.", file=sys.stderr)
883 883
884 signal.signal(signal.SIGALRM, sigalrm_handler) 884 signal.signal(signal.SIGALRM, sigalrm_handler)
885 signal.alarm(120) 885 signal.alarm(120)
886 886
887 self._write_file.close() 887 self._write_file.close()
888 888
889 # Print lines as they're logged to the pipe until EOF is reached or readline 889 # Print lines as they're logged to the pipe until EOF is reached or readline
890 # is interrupted by one of the signal handlers above. 890 # is interrupted by one of the signal handlers above.
891 host_ready = False 891 host_ready = False
892 try: 892 for line in iter(self._read_file.readline, ''):
893 for line in iter(self._read_file.readline, ''): 893 if line[:4] == "MSG:":
894 if line[:4] == "MSG:": 894 sys.stderr.write(line[4:])
895 sys.stderr.write(line[4:]) 895 elif line == "READY\n":
896 elif line == "READY\n": 896 host_ready = True
897 host_ready = True 897 else:
898 else: 898 sys.stderr.write("Unrecognized command: " + line)
899 sys.stderr.write("Unrecognized command: " + line)
900 except IOError as e:
901 if e.errno != errno.EINTR:
902 raise
903 print("Log file: %s" % os.environ[LOG_FILE_ENV_VAR], file=sys.stderr) 899 print("Log file: %s" % os.environ[LOG_FILE_ENV_VAR], file=sys.stderr)
904 return host_ready 900 return host_ready
905 901
906 @staticmethod 902 @staticmethod
907 def instance(): 903 def instance():
908 """Returns the singleton instance, if it exists.""" 904 """Returns the singleton instance, if it exists."""
909 return ParentProcessLogger.__instance 905 return ParentProcessLogger.__instance
910 906
911 907
912 def daemonize(): 908 def daemonize():
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 else: 1532 else:
1537 logging.info("Host exited with status %s." % os.WEXITSTATUS(status)) 1533 logging.info("Host exited with status %s." % os.WEXITSTATUS(status))
1538 elif os.WIFSIGNALED(status): 1534 elif os.WIFSIGNALED(status):
1539 logging.info("Host terminated by signal %s." % os.WTERMSIG(status)) 1535 logging.info("Host terminated by signal %s." % os.WTERMSIG(status))
1540 1536
1541 1537
1542 if __name__ == "__main__": 1538 if __name__ == "__main__":
1543 logging.basicConfig(level=logging.DEBUG, 1539 logging.basicConfig(level=logging.DEBUG,
1544 format="%(asctime)s:%(levelname)s:%(message)s") 1540 format="%(asctime)s:%(levelname)s:%(message)s")
1545 sys.exit(main()) 1541 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