Index: remoting/host/linux/linux_me2me_host.py |
diff --git a/remoting/host/linux/linux_me2me_host.py b/remoting/host/linux/linux_me2me_host.py |
index 864db543f04022ecbe33bde29f715dc38c664d05..dc7f105320c7972e416400b01cc2ae25d8f9a0f0 100755 |
--- a/remoting/host/linux/linux_me2me_host.py |
+++ b/remoting/host/linux/linux_me2me_host.py |
@@ -502,14 +502,15 @@ class Desktop: |
self.host_proc.stdin.close() |
-def get_daemon_pid(): |
+def get_daemon_proc(): |
"""Checks if there is already an instance of this script running, and returns |
- its PID. |
+ a psutil.Process instance for it. |
Returns: |
- The process ID of the existing daemon process, or 0 if the daemon is not |
- running. |
+ A Process instance for the existing daemon process, or None if the daemon |
+ is not running. |
""" |
+ |
uid = os.getuid() |
this_pid = os.getpid() |
@@ -537,11 +538,11 @@ def get_daemon_pid(): |
if len(cmdline) < 2: |
continue |
if cmdline[0] == sys.executable and cmdline[1] == sys.argv[0]: |
- return process.pid |
+ return process |
except (psutil.NoSuchProcess, psutil.AccessDenied): |
continue |
- return 0 |
+ return None |
def choose_x_session(): |
@@ -979,8 +980,8 @@ Web Store: https://chrome.google.com/remotedesktop""" |
# Check for a modal command-line option (start, stop, etc.) |
if options.get_status: |
- pid = get_daemon_pid() |
- if pid != 0: |
+ proc = get_daemon_proc() |
+ if proc is not None: |
Sergey Ulanov
2014/06/18 00:23:58
nit: why not 'proc != None'?
Or I would prefer 'if
Lambros
2014/06/18 00:44:57
I'm following the advice from the Google Python st
Sergey Ulanov
2014/06/18 08:01:27
I didn't know about this. Still, the guide says th
|
print "STARTED" |
elif is_supported_platform(): |
print "STOPPED" |
@@ -991,23 +992,28 @@ Web Store: https://chrome.google.com/remotedesktop""" |
# TODO(sergeyu): Remove --check-running once NPAPI plugin and NM host are |
# updated to always use get-status flag instead. |
if options.check_running: |
- pid = get_daemon_pid() |
- return 0 if pid != 0 else 1 |
+ proc = get_daemon_proc() |
+ return 1 if proc is None else 0 |
if options.stop: |
- pid = get_daemon_pid() |
- if pid == 0: |
+ proc = get_daemon_proc() |
+ if proc is None: |
print "The daemon is not currently running" |
else: |
- print "Killing process %s" % pid |
- os.kill(pid, signal.SIGTERM) |
+ print "Killing process %s" % proc.pid |
+ proc.terminate() |
+ try: |
+ proc.wait(timeout=30) |
+ except psutil.TimeoutExpired: |
+ print "Timed out trying to kill daemon process" |
+ return 1 |
return 0 |
if options.reload: |
- pid = get_daemon_pid() |
- if pid == 0: |
+ proc = get_daemon_proc() |
+ if proc is None: |
return 1 |
- os.kill(pid, signal.SIGHUP) |
+ proc.send_signal(signal.SIGHUP) |
return 0 |
if options.add_user: |
@@ -1099,8 +1105,8 @@ Web Store: https://chrome.google.com/remotedesktop""" |
# Determine whether a desktop is already active for the specified host |
# host configuration. |
- pid = get_daemon_pid() |
- if pid != 0: |
+ proc = get_daemon_proc() |
+ if proc is not None: |
# Debian policy requires that services should "start" cleanly and return 0 |
# if they are already running. |
print "Service already running." |