[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] PID resolution fallbacks by ps and lsof



commit c62e15023f3f6fe791a5f6fc21f070c6e8f857fb
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Apr 25 19:52:07 2011 -0700

    PID resolution fallbacks by ps and lsof
    
    On Macs all of the current pid resolution tactics fails, so adding a couple
    more that work on that platform.
---
 src/util/torTools.py |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index 0eebd20..08b04c0 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -122,6 +122,8 @@ def getPid(controlPort=9051, pidFilePath=None):
   4. "netstat -npl | grep 127.0.0.1:%s" % <tor control port>
   5. "ps -o pid -C tor"
   6. "sockstat -4l -P tcp -p %i | grep tor" % <tor control port>
+  7. "ps axc | egrep \" tor$\""
+  8. "lsof -wnPi | egrep \"^tor.*:%i\"" % <tor control port>
   
   If pidof or ps provide multiple tor instances then their results are
   discarded (since only netstat can differentiate using the control port). This
@@ -201,6 +203,32 @@ def getPid(controlPort=9051, pidFilePath=None):
       if pid.isdigit(): return pid
   except IOError: pass
   
+  # attempts to resolve via a ps command that works on the mac (this and lsof
+  # are the only resolvers to work on that platform). This fails if:
+  # - tor's running under a different name
+  # - there's multiple instances of tor
+  
+  try:
+    results = sysTools.call("ps axc | egrep \" tor$\"")
+    if len(results) == 1 and len(results[0].split()) > 0:
+      pid = results[0].split()[0]
+      if pid.isdigit(): return pid
+  except IOError: pass
+  
+  # attempts to resolve via lsof - this should work on linux, mac, and bsd -
+  # this fails if:
+  # - tor's running under a different name
+  # - tor's being run as a different user due to permissions
+  # - there are multiple instances of Tor, using the
+  #   same control port on different addresses.
+  
+  try:
+    results = sysTools.call("lsof -wnPi | egrep \"^tor.*:%i\"" % controlPort)
+    if len(results) == 1 and len(results[0].split()) > 1:
+      pid = results[0].split()[1]
+      if pid.isdigit(): return pid
+  except IOError: pass
+  
   return None
 
 def getBsdJailId():

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits