commit 3731bba464e22dc5501b7b9ae62c29ebc34ad7ba Author: Damian Johnson atagar@torproject.org Date: Sun Oct 16 17:27:57 2011 -0700
Adding BSD compatability to system.is_running
Copying over an arm fix I made earlier this week from util.torTools.isTorRunning so that it would work on OSX/FreeBSD/OpenBSD. --- stem/util/system.py | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py index 3c520e8..bdada9b 100644 --- a/stem/util/system.py +++ b/stem/util/system.py @@ -61,7 +61,27 @@ def is_running(command, suppress_exc = True): OSError if this can't be determined and suppress_exc is False """
- command_listing = 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") + + primary_resolver, secondary_resolver = "ps -A co command", "ps -ao ucomm=" + + if os.uname()[0] in ("Darwin", "FreeBSD", "OpenBSD"): + primary_resolver, secondary_resolver = secondary_resolver, primary_resolver + + command_listing = call(primary_resolver) + if not command_listing: + command_listing = call(secondary_resolver)
if command_listing: return command in command_listing
tor-commits@lists.torproject.org