[tor-commits] [stem/master] Check for /proc read permissions when determining if it's available

atagar at torproject.org atagar at torproject.org
Sun Dec 7 20:52:30 UTC 2014


commit 500fd38a7d09e883257d84dd67bc7014f4f47085
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Dec 7 11:48:30 2014 -0800

    Check for /proc read permissions when determining if it's available
    
    On Gentoo proc permissions are locked down, causing our tests to fail...
    
      ======================================================================
      ERROR: test_get_connections
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/var/tmp/portage/net-libs/stem-1.2.2_p20141208/work/stem-1.2.2_p20141208/test/integ/util/connection.py", line 27, in test_get_connections
          connections = get_connections(resolver, process_pid = tor_pid)
        File "/var/tmp/portage/net-libs/stem-1.2.2_p20141208/work/stem-1.2.2_p20141208/stem/util/connection.py", line 177, in get_connections
          return [Connection(*conn) for conn in stem.util.proc.connections(process_pid)]
        File "/var/tmp/portage/net-libs/stem-1.2.2_p20141208/work/stem-1.2.2_p20141208/stem/util/proc.py", line 404, in connections
          raise exc
      IOError: unable to read '/proc/net/tcp': [Errno 13] Permission denied: '/proc/net/tcp'
    
      ----------------------------------------------------------------------
    
    I'm tempted to change our 'is proc available?' check, but the platform only
    restricts /proc/net/*, so only doing this for connection resolution.
---
 stem/util/connection.py |    2 +-
 test/integ/util/proc.py |    3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/stem/util/connection.py b/stem/util/connection.py
index f5ca3f4..c94b6fe 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -272,7 +272,7 @@ def system_resolvers(system = None):
 
   # proc resolution, by far, outperforms the others so defaults to this is able
 
-  if stem.util.proc.is_available():
+  if stem.util.proc.is_available() and os.access('/proc/net/tcp', os.R_OK) and os.access('/proc/net/udp', os.R_OK):
     resolvers = [Resolver.PROC] + resolvers
 
   return resolvers
diff --git a/test/integ/util/proc.py b/test/integ/util/proc.py
index cad0114..1047912 100644
--- a/test/integ/util/proc.py
+++ b/test/integ/util/proc.py
@@ -90,6 +90,9 @@ class TestProc(unittest.TestCase):
     elif not test.runner.get_runner().is_ptraceable():
       test.runner.skip(self, '(DisableDebuggerAttachment is set)')
       return
+    elif not os.access('/proc/net/tcp', os.R_OK) or not os.access('/proc/net/udp', os.R_OK):
+      test.runner.skip(self, '(proc lacks read permissions)')
+      return
 
     # making a controller connection so that we have something to query for
     with runner.get_tor_socket():





More information about the tor-commits mailing list