[tor-commits] [arm/master] Dropping arm.util.system.getProcessName()
atagar at torproject.org
atagar at torproject.org
Tue Sep 3 02:54:30 UTC 2013
commit 6176b9a87c8a4d8ca3f60f953d2d8ca9e276813f
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Sep 2 13:23:39 2013 -0700
Dropping arm.util.system.getProcessName()
Replacing this bit of functionality with a stem function named
get_name_by_pid(). Actually, we weren't using this function's caching nor
exceptions which was silly. Oh, and the ps command we ran had a bug so it was
busted when the process had arguments. Go me.
---
arm/controller.py | 8 ++++++--
arm/util/sysTools.py | 50 --------------------------------------------------
2 files changed, 6 insertions(+), 52 deletions(-)
diff --git a/arm/controller.py b/arm/controller.py
index 71d6adc..f6a1f6e 100644
--- a/arm/controller.py
+++ b/arm/controller.py
@@ -25,7 +25,7 @@ from stem.control import State, Controller
from arm.util import connections, hostnames, panel, sysTools, torConfig, torTools
-from stem.util import conf, enum, log
+from stem.util import conf, enum, log, system
ARM_CONTROLLER = None
@@ -546,7 +546,11 @@ def startTorMonitor(startTime):
if torPid:
# use the tor pid to help narrow connection results
- torCmdName = sysTools.getProcessName(torPid, "tor")
+ torCmdName = system.get_name_by_pid(torPid)
+
+ if torCmdName is None:
+ torCmdName = "tor"
+
connections.getResolver(torCmdName, torPid, "tor")
else:
# constructs singleton resolver and, if tor isn't connected, initizes
diff --git a/arm/util/sysTools.py b/arm/util/sysTools.py
index af38ced..3763826 100644
--- a/arm/util/sysTools.py
+++ b/arm/util/sysTools.py
@@ -8,7 +8,6 @@ import threading
from stem.util import conf, log, proc, str_tools, system
-PROCESS_NAME_CACHE = {} # mapping of pids to their process names
RESOURCE_TRACKERS = {} # mapping of pids to their resource tracker instances
# Runtimes for system calls, used to estimate cpu usage. Entries are tuples of
@@ -61,55 +60,6 @@ def getFileErrorMsg(exc):
return excStr
-def getProcessName(pid, default = None, cacheFailure = True):
- """
- Provides the name associated with the given process id. This isn't available
- on all platforms.
-
- Arguments:
- pid - process id for the process being returned
- default - result if the process name can't be retrieved (raises an
- IOError on failure instead if undefined)
- cacheFailure - if the lookup fails and there's a default then caches the
- default value to prevent further lookups
- """
-
- if pid in PROCESS_NAME_CACHE:
- return PROCESS_NAME_CACHE[pid]
-
- processName, raisedExc = "", None
-
- # fetch it from proc contents if available
- if proc.is_available():
- try:
- processName = proc.get_stats(pid, proc.Stat.COMMAND)[0]
- except IOError, exc:
- raisedExc = exc
-
- # fall back to querying via ps
- if not processName:
- # the ps call formats results as:
- # COMMAND
- # tor
- psCall = system.call("ps -p %s -o command" % pid)
-
- if psCall and len(psCall) >= 2 and not " " in psCall[1]:
- processName, raisedExc = psCall[1].strip(), None
- else:
- raisedExc = ValueError("Unexpected output from ps: %s" % psCall)
-
- if raisedExc:
- if default == None: raise raisedExc
- else:
- if cacheFailure:
- PROCESS_NAME_CACHE[pid] = default
-
- return default
- else:
- processName = os.path.basename(processName)
- PROCESS_NAME_CACHE[pid] = processName
- return processName
-
def getResourceTracker(pid, noSpawn = False):
"""
Provides a running singleton ResourceTracker instance for the given pid.
More information about the tor-commits
mailing list