[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/release] fix: Accounting for multiple results from lsof
commit 12077adddb88f1a2e7ae2f8e0078c54ce3e70fd2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Apr 26 08:32:50 2011 -0700
fix: Accounting for multiple results from lsof
When querying lsof from the python process this can provide multiple results
with the same pid. The second is from the lsof query itself (this was observed
with an earlier change for querying our own process). Accounting for this by
checking all pid results from the query to see if they're in agreement.
---
src/util/torTools.py | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/util/torTools.py b/src/util/torTools.py
index 08b04c0..f4a29af 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -224,8 +224,20 @@ def getPid(controlPort=9051, pidFilePath=None):
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]
+
+ # This can result in multiple entries with the same pid (maybe from the
+ # query itself?). Checking all lines to see if they have the same pid.
+
+ if results:
+ pid = ""
+
+ for line in results:
+ lineComp = line.split()
+
+ if len(lineComp) >= 2 and (not pid or lineComp[1] == pid):
+ pid = lineComp[1]
+ else: raise IOError
+
if pid.isdigit(): return pid
except IOError: pass
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits