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

[tor-commits] [stem/master] get_pid_by_port() unavailable on Mac OSX



commit 2fc1c420818bff19437a2b74713223a410d9898e
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jun 23 11:47:24 2012 -0700

    get_pid_by_port() unavailable on Mac OSX
    
    Tests for get_pid_by_port() are failing on Mac OSX 10.5.8 because sockstat is
    unavailable and lsof neither provides ports nor accepts the flags we need.
    Noting this in the pydocs/comments, and skipping its integ tests when on a mac.
---
 stem/util/system.py       |   16 +++++++++++++++-
 test/integ/util/system.py |    6 ++++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/stem/util/system.py b/stem/util/system.py
index 73fd47e..b4c326f 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -8,6 +8,7 @@ best-effort, providing None if the lookup fails.
 ::
 
   is_windows - checks if we're running on windows
+  is_mac - checks if we're running on a mac
   is_bsd - checks if we're running on the bsd family of operating systems
   is_available - determines if a command is availabe on this system
   is_running - determines if a given process is running
@@ -58,6 +59,15 @@ def is_windows():
   
   return platform.system() == "Windows"
 
+def is_mac():
+  """
+  Checks if we are running on Mac OSX.
+  
+  :returns: bool to indicate if we're on a Mac
+  """
+  
+  return platform.system() == "Darwin"
+
 def is_bsd():
   """
   Checks if we are within the BSD family of operating systems. This presently
@@ -260,7 +270,8 @@ def get_pid_by_port(port):
     2. sockstat -4l -P tcp -p <port>
     3. lsof -wnP -iTCP -sTCP:LISTEN | grep ":<port>"
   
-  Most queries limit results to listening TCP connections.
+  Most queries limit results to listening TCP connections. This function likely
+  won't work on Mac OSX.
   
   :param int port: port where the process we're looking for is listening
   
@@ -301,6 +312,7 @@ def get_pid_by_port(port):
   
   # attempts to resolve using sockstat, failing if:
   # - sockstat doesn't accept the -4 flag (BSD only)
+  # - sockstat isn't available (encountered with OSX 10.5.8)
   # - there are multiple instances using the same port on different addresses
   #
   # flags:
@@ -334,6 +346,8 @@ def get_pid_by_port(port):
   
   # resolves using lsof which works on both Linux and BSD, only failing if:
   # - lsof is unavailable (not included by default on OpenBSD)
+  # - lsof doesn't provide the port ip/port, nor accept the -i and -s args
+  #   (encountered with OSX 10.5.8)
   # - the process being run as a different user due to permissions
   # - there are multiple instances using the same port on different addresses
   #
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 174357e..7999cbb 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -201,6 +201,9 @@ class TestSystem(unittest.TestCase):
     if not _has_port():
       test.runner.skip(self, "(test instance has no port)")
       return
+    elif stem.util.system.is_mac():
+      test.runner.skip(self, "(resolvers unavailable)")
+      return
     elif not runner.is_ptraceable():
       test.runner.skip(self, "(DisableDebuggerAttachment is set)")
       return
@@ -271,6 +274,9 @@ class TestSystem(unittest.TestCase):
     elif not stem.util.system.is_available("lsof"):
       test.runner.skip(self, "(lsof unavailable)")
       return
+    elif stem.util.system.is_mac():
+      test.runner.skip(self, "(resolvers unavailable)")
+      return
     elif not runner.is_ptraceable():
       test.runner.skip(self, "(DisableDebuggerAttachment is set)")
       return



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