[tor-commits] [stem/master] Only using TAKEOWNERSHIP if we're on the local system
atagar at torproject.org
atagar at torproject.org
Sun Dec 9 07:43:51 UTC 2012
commit 120907822f06fd476f2c47b7135e816cd730b1c7
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Dec 8 23:41:21 2012 -0800
Only using TAKEOWNERSHIP if we're on the local system
We were using TAKEOWNERSHIP if our pid matched tor's __OwningControllerProcess.
However, doing this doesn't make sense if we're connecting remotely. Caught by
Robert on...
https://trac.torproject.org/7666
---
stem/control.py | 4 ++--
stem/socket.py | 16 ++++++++++++++++
test/integ/process.py | 2 +-
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index be589d9..8d9784e 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1511,7 +1511,7 @@ class Controller(BaseController):
owning_pid = self.get_conf("__OwningControllerProcess", None)
- if owning_pid == str(os.getpid()):
+ if owning_pid == str(os.getpid()) and self.get_socket().is_localhost():
response = self.msg("TAKEOWNERSHIP")
stem.response.convert("SINGLELINE", response)
@@ -1524,7 +1524,7 @@ class Controller(BaseController):
except stem.ControllerError, exc:
log.warn("We were unable to reset tor's __OwningControllerProcess configuration. It will continue to periodically check if our pid exists. (%s)" % response)
else:
- log.warn("We were unable assert ownership of tor through TAKEOWNERSHIP, despite being configured to be the owning process thrugh __OwningControllerProcess. (%s)" % response)
+ log.warn("We were unable assert ownership of tor through TAKEOWNERSHIP, despite being configured to be the owning process through __OwningControllerProcess. (%s)" % response)
def _handle_event(self, event_message):
stem.response.convert("EVENT", event_message, arrived_at = time.time())
diff --git a/stem/socket.py b/stem/socket.py
index 4cbfb3e..adfc83e 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -18,6 +18,7 @@ as instances of the :class:`~stem.response.ControlMessage` class.
|- send - sends a message to the socket
|- recv - receives a ControlMessage from the socket
|- is_alive - reports if the socket is known to be closed
+ |- is_localhost - returns if the socket is for the local system or not
|- connect - connects a new socket
|- close - shuts down the socket
+- __enter__ / __exit__ - manages socket connection
@@ -145,6 +146,15 @@ class ControlSocket(object):
return self._is_alive
+ def is_localhost(self):
+ """
+ Returns if the connection is for the local system or not.
+
+ :returns: **bool** that's **True** if the connection is for the local host and **False** otherwise
+ """
+
+ return False
+
def connect(self):
"""
Connects to a new socket, closing our previous one if we're already
@@ -300,6 +310,9 @@ class ControlPort(ControlSocket):
return self._control_port
+ def is_localhost(self):
+ return self._control_addr == "127.0.0.1"
+
def _make_socket(self):
try:
control_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -339,6 +352,9 @@ class ControlSocketFile(ControlSocket):
return self._socket_path
+ def is_localhost(self):
+ return True
+
def _make_socket(self):
try:
control_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
diff --git a/test/integ/process.py b/test/integ/process.py
index ee21d5a..5811e37 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -113,7 +113,7 @@ class TestProcess(unittest.TestCase):
# needing to a _get_pid() helper but after much head scratching I haven't
# been able to mock os.getpid() or posix.getpid().
- sleep_process = subprocess.Popen(['sleep', '10'])
+ sleep_process = subprocess.Popen(['sleep', '60'])
mocking.mock(stem.process._get_pid, mocking.return_value(str(sleep_process.pid)))
tor_process = stem.process.launch_tor_with_config(
More information about the tor-commits
mailing list