[arm/master] Dropping functionality to sighup via pkill

commit b16f7b82e403ddc7ccc768a4b79a28a00811c309 Author: Damian Johnson <atagar@torproject.org> Date: Sat Jun 1 19:17:01 2013 -0700 Dropping functionality to sighup via pkill Once I had a phobia of deleting any code that could possibly prove to be useful later. This is a great example: the initial version of arm could reset tor by issuing a pkill to sighup. I later learned that this could also be done far more simpily by issuing a 'SIGNAL RELOAD'. So what did I do? I changed arm to use SIGNAL of course, but I also left the pkill code around just in case I needed it in the future. The only advantage of pkill is that we can sighup tor instances that lack a control port. This might make its way into stem's process module someday if we ever have a need, but arm's implementation is old and unused so it's about time it got deleted. --- src/util/torTools.py | 68 ++++++-------------------------------------------- 1 file changed, 7 insertions(+), 61 deletions(-) diff --git a/src/util/torTools.py b/src/util/torTools.py index 0cb3a22..1ed1bbb 100644 --- a/src/util/torTools.py +++ b/src/util/torTools.py @@ -992,77 +992,23 @@ class Controller: return list(self.controllerEvents) - def reload(self, issueSighup = False): + def reload(self): """ This resets tor (sending a RELOAD signal to the control port) causing tor's - internal state to be reset and the torrc reloaded. This can either be done - by... - - the controller via a RELOAD signal (default and suggested) - conn.send_signal("RELOAD") - - system reload signal (hup) - pkill -sighup tor - - The later isn't really useful unless there's some reason the RELOAD signal - won't do the trick. Both methods raise an IOError in case of failure. - - Arguments: - issueSighup - issues a sighup rather than a controller RELOAD signal + internal state to be reset and the torrc reloaded. """ self.connLock.acquire() - raisedException = None - if self.isAlive(): - if not issueSighup: + try: + if self.isAlive(): try: self.controller.signal(stem.Signal.RELOAD) except Exception, exc: # new torrc parameters caused an error (tor's likely shut down) - raisedException = IOError(str(exc)) - else: - try: - # Redirects stderr to stdout so we can check error status (output - # should be empty if successful). Example error: - # pkill: 5592 - Operation not permitted - # - # note that this may provide multiple errors, even if successful, - # hence this: - # - only provide an error if Tor fails to log a sighup - # - provide the error message associated with the tor pid (others - # would be a red herring) - if not system.is_available("pkill"): - raise IOError("pkill command is unavailable") - - self._isReset = False - pkillCall = os.popen("pkill -sighup ^tor$ 2> /dev/stdout") - pkillOutput = pkillCall.readlines() - pkillCall.close() - - # Give the sighupTracker a moment to detect the sighup signal. This - # is, of course, a possible concurrency bug. However I'm not sure - # of a better method for blocking on this... - waitStart = time.time() - while time.time() - waitStart < 1: - time.sleep(0.1) - if self._isReset: break - - if not self._isReset: - errorLine, torPid = "", self.controller.get_pid(None) - - if torPid: - for line in pkillOutput: - if line.startswith("pkill: %s - " % torPid): - errorLine = line - break - - if errorLine: raise IOError(" ".join(errorLine.split()[3:])) - else: raise IOError("failed silently") - except IOError, exc: - raisedException = exc - - self.connLock.release() - - if raisedException: raise raisedException + raise IOError(str(exc)) + finally: + self.connLock.release() def shutdown(self, force = False): """
participants (1)
-
atagar@torproject.org