[tor-commits] [arm/master] Moving missing pid notice to the starter

atagar at torproject.org atagar at torproject.org
Tue Sep 17 00:55:40 UTC 2013


commit c551d65f32e7077fcc01188b6fb2e27341d0e0f8
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Sep 16 17:35:48 2013 -0700

    Moving missing pid notice to the starter
    
    I'd like to axe the start_arm() function if able so moving this notification to
    the starter.
---
 arm/controller.py |   13 ++++---------
 arm/settings.cfg  |    1 +
 arm/starter.py    |    8 ++++++++
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/arm/controller.py b/arm/controller.py
index 2d5866b..b6b1b9f 100644
--- a/arm/controller.py
+++ b/arm/controller.py
@@ -514,15 +514,6 @@ def start_arm(start_time):
   :param float start_time: unix timestamp for when arm was started
   """
 
-  # attempts to fetch the tor pid, warning if unsuccessful (this is needed for
-  # checking its resource usage, among other things)
-
-  controller = torTools.getConn().controller
-  tor_pid = controller.get_pid(None)
-
-  if not tor_pid:
-    log.warn("Unable to determine Tor's pid. Some information, like its resource usage will be unavailable.")
-
   # adds events needed for arm functionality to the torTools REQ_EVENTS
   # mapping (they're then included with any setControllerEvents call, and log
   # a more helpful error if unavailable)
@@ -534,6 +525,8 @@ def start_arm(start_time):
     # functioning. It'll have circuits, but little else. If this is the case then
     # notify the user and tell them what they can do to fix it.
 
+    controller = torTools.getConn().controller
+
     if controller.get_conf("DisableDebuggerAttachment", None) == "1":
       log.notice("Tor is preventing system utilities like netstat and lsof from working. This means that arm can't provide you with connection information. You can change this by adding 'DisableDebuggerAttachment 0' to your torrc and restarting tor. For more information see...\nhttps://trac.torproject.org/3313")
       connections.getResolver("tor").setPaused(True)
@@ -544,6 +537,8 @@ def start_arm(start_time):
       # if Tor's connected or not.
       torTools.getConn().addStatusListener(connResetListener)
 
+      tor_pid = controller.get_pid(None)
+
       if tor_pid:
         # use the tor pid to help narrow connection results
         tor_cmd = system.get_name_by_pid(tor_pid)
diff --git a/arm/settings.cfg b/arm/settings.cfg
index e9564b4..0d5227c 100644
--- a/arm/settings.cfg
+++ b/arm/settings.cfg
@@ -60,6 +60,7 @@ msg.tor_is_running_as_root Tor is currently running with root permissions. This
 msg.arm_is_running_as_root Arm is currently running with root permissions. This isn't a good idea, nor should it be necessary. Try starting arm with "sudo -u {tor_user} arm" instead.
 msg.config_not_found No armrc loaded, using defaults. You can customize arm by placing a configuration file at {path} (see the armrc.sample for its options).
 msg.unable_to_read_config Failed to load configuration (using defaults): "{error}"
+msg.unable_to_determine_pid Unable to determine Tor's pid. Some information, like its resource usage will be unavailable.
 
 # Important tor configuration options (shown by default)
 config.important BandwidthRate
diff --git a/arm/starter.py b/arm/starter.py
index 93d8ff2..0e4ca9e 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -46,6 +46,7 @@ CONFIG = stem.util.conf.config_dict("arm", {
   'msg.arm_is_running_as_root': '',
   'msg.config_not_found': '',
   'msg.unable_to_read_config': '',
+  'msg.unable_to_determine_pid': '',
 })
 
 # Our default arguments. The _get_args() function provides a named tuple of
@@ -372,6 +373,13 @@ def main():
 
   os.putenv("LANG", "C")
 
+  # check that we'll be able to get tor's pid later
+
+  try:
+    controller.get_pid()
+  except ValueError:
+    stem.util.log.warn(CONFIG['msg.unable_to_determine_pid'])
+
   # If using our LANG variable for rendering multi-byte characters lets us
   # get unicode support then then use it. This needs to be done before
   # initializing curses.



More information about the tor-commits mailing list