[tor-commits] [arm/master] Failing over when proc fails to get the uptime

atagar at torproject.org atagar at torproject.org
Mon Sep 17 00:18:08 UTC 2012


commit 74567bb166c68584e3d1459f98e1ea08d09927c3
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Sep 16 17:13:07 2012 -0700

    Failing over when proc fails to get the uptime
    
    The header panel caches tor's start time which is great... unless the following
    happens.
    
    1. We try to fetch the start time via proc contents and fail.
    2. The header panel caches the None result.
    3. Arm later discovers that proc is unusable and turns it off, but it's too
       late since the header panel has cached the result.
    
    Accounting for this by failing over to 'ps' whenever the proc query fails.
    Issue caught by drforbin on...
    https://trac.torproject.org/6862
    
    Only testing done was a basic sanity test that arm runs against a relay.
---
 src/util/torTools.py |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index 5b70c6a..a4d49c7 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -2370,16 +2370,20 @@ class Controller(TorCtl.PostEventListener):
         myPid = self.getMyPid()
         
         if myPid:
-          try:
-            if procTools.isProcAvailable():
+          if procTools.isProcAvailable():
+            try:
               result = float(procTools.getStats(myPid, procTools.Stat.START_TIME)[0])
-            else:
+            except: pass
+          
+          if not result:
+            # if we're either not using proc or it fails then try using ps
+            try:
               psCall = sysTools.call("ps -p %s -o etime" % myPid)
               
               if psCall and len(psCall) >= 2:
                 etimeEntry = psCall[1].strip()
                 result = time.time() - uiTools.parseShortTimeLabel(etimeEntry)
-          except: pass
+            except: pass
       elif key == "authorities":
         # There's two configuration options that can overwrite the default
         # authorities: DirServer and AlternateDirAuthority.



More information about the tor-commits mailing list