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

[tor-commits] [arm/master] Improving tor detection for BSD platforms



commit b1fce355c3661324f477e2698a08214035d09c10
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Oct 11 08:47:05 2011 -0700

    Improving tor detection for BSD platforms
    
    Linux and BSD platforms (mac, openbsd, and freebsd) have distinct argument sets
    for their ps resolvers. Taking into account for this for tor detection,
    guessing the family based on uname results then trying both if we guess wrong.
    
    Adding the '-a' argument to get results for all users thanks to Jordi Espasa
    Clofent.
    
    Tested this ps command on Mac and OpenBSD, and just guessing that FreeBSD will
    behave the same.
---
 src/util/torTools.py |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index 34c9adc..a4ab70c 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -350,20 +350,27 @@ def isTorRunning():
   then this returns False.
   """
   
-  # suggestions welcome for making this more reliable
-  commandResults = sysTools.call("ps -A co command")
-  
+  # Linux and the BSD families have different variants of ps. Guess based on
+  # os.uname() results which to try first, then fall back to the other.
+  #
+  # Linux
+  #   -A          - Select all processes. Identical to -e.
+  #   -co command - Shows just the base command.
+  #
+  # Mac / BSD
+  #   -a        - Display information about other users' processes as well as
+  #               your own.
+  #   -o ucomm= - Shows just the ucomm attribute ("name to be used for
+  #               accounting")
+  
+  primaryResolver, secondaryResolver = "ps -A co command", "ps -ao ucomm="
+  
+  if os.uname()[0] in ("Darwin", "FreeBSD", "OpenBSD"):
+    primaryResolver, secondaryResolver = secondaryResolver, primaryResolver
+  
+  commandResults = sysTools.call(primaryResolver)
   if not commandResults:
-    # OpenBSD uses a weird (and largely broken from the looks of it) version of
-    # ps. It lacks the -A argument and according to the man page -j, -l, and -u
-    # all do something similar but they fail.
-    #
-    # ucomm is defined in the man page as 'Alias: comm.  Name to be used for
-    # accounting.' The alias part is a lie (it works, but with an error
-    # message), though this seems to do what we want and prints the bare
-    # command.
-    
-    commandResults = sysTools.call("ps -o ucomm=")
+    commandResults = sysTools.call(secondaryResolver)
   
   if commandResults:
     for cmd in commandResults:



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