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

[tor-commits] [arm/master] Adding OSX support for the getPwd utility



commit 92ac1930143e51689396563877087d1070a246bd
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Oct 15 14:03:32 2011 -0700

    Adding OSX support for the getPwd utility
    
    BSD platforms lack either pwdx or proc contents with this information. However,
    this is available via lsof. Using this for BSD platforms. This was tested by
    running sysTools.getPwd() on OSX - hopefully it should work on Free/OpenBSD
    too. Fix is thanks to Sebastian.
    
    https://trac.torproject.org/projects/tor/ticket/4236
---
 src/util/sysTools.py |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/util/sysTools.py b/src/util/sysTools.py
index 98361e5..4bb0667 100644
--- a/src/util/sysTools.py
+++ b/src/util/sysTools.py
@@ -174,6 +174,23 @@ def getPwd(pid):
       PWD_CACHE[pid] = pwd
       return pwd
     except IOError: pass # fall back to pwdx
+  elif os.uname()[0] in ("Darwin", "FreeBSD", "OpenBSD"):
+    # BSD neither useres the above proc info nor does it have pwdx. Use lsof to
+    # determine this instead:
+    # https://trac.torproject.org/projects/tor/ticket/4236
+    #
+    # ~$ lsof -a -p 75717 -d cwd -Fn
+    # p75717
+    # n/Users/atagar/tor/src/or
+    
+    try:
+      results = call("lsof -a -p %s -d cwd -Fn" % pid)
+      
+      if results and len(results) == 2 and results[1].startswith("n/"):
+        pwd = results[1][1:].strip()
+        PWD_CACHE[pid] = pwd
+        return pwd
+    except IOError, exc: pass
   
   try:
     # pwdx results are of the form:

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