[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r22626: {arm} change: using PidFile entry to fetch pid if available (idea (in arm/trunk: . util)



Author: atagar
Date: 2010-07-11 02:54:33 +0000 (Sun, 11 Jul 2010)
New Revision: 22626

Modified:
   arm/trunk/TODO
   arm/trunk/util/torTools.py
Log:
change: using PidFile entry to fetch pid if available (idea by arma)



Modified: arm/trunk/TODO
===================================================================
--- arm/trunk/TODO	2010-07-11 01:38:18 UTC (rev 22625)
+++ arm/trunk/TODO	2010-07-11 02:54:33 UTC (rev 22626)
@@ -23,7 +23,7 @@
           - fetch text via getinfo rather than reading directly?
               conn.get_info("config-text")
         [-] conn panel (for version 1.3.8)
-          - drop page entirely if being run as a client
+          - expand client connections and note location in circuit (entry-exit)
           - check family connections to see if they're alive (VERSION cell
               handshake?)
           - fallback when pid or connection querying via pid is unavailable
@@ -77,6 +77,8 @@
         tricky. Putting this off until revising this section.
   
   * conf panel:
+    * *never* do reverse dns lookups for first hops (could be resolving via
+      tor and hence leaking to the exit)
     * torrc validation doesn't catch if parameters are missing
     * scrolling in the torrc isn't working properly when comments are stripped
         Current method of displaying torrc is pretty stupid (lots of repeated
@@ -109,6 +111,7 @@
       replace the orport, fingerprint, flags, etc)
     * special page for client related information, such as ips of our client
       circuits at the exit
+    * look at vidalia for ideas
     * need to solicit for ideas on what would be most helpful to clients
   * check if batch getInfo/getOption calls provide much performance benefit
   * layout (css) bugs with site

Modified: arm/trunk/util/torTools.py
===================================================================
--- arm/trunk/util/torTools.py	2010-07-11 01:38:18 UTC (rev 22625)
+++ arm/trunk/util/torTools.py	2010-07-11 02:54:33 UTC (rev 22626)
@@ -191,13 +191,14 @@
       print exc
       return None
 
-def getPid(controlPort=9051):
+def getPid(controlPort=9051, pidFilePath=None):
   """
   Attempts to determine the process id for a running tor process, using the
   following:
-  1. "pidof tor"
-  2. "netstat -npl | grep 127.0.0.1:%s" % <tor control port>
-  3. "ps -o pid -C tor"
+  1. GETCONF PidFile
+  2. "pidof tor"
+  3. "netstat -npl | grep 127.0.0.1:%s" % <tor control port>
+  4. "ps -o pid -C tor"
   
   If pidof or ps provide multiple tor instances then their results are
   discarded (since only netstat can differentiate using the control port). This
@@ -205,8 +206,22 @@
   
   Arguments:
     controlPort - control port of the tor process if multiple exist
+    pidFilePath - path to the pid file generated by tor
   """
   
+  # attempts to fetch via the PidFile, failing if:
+  # - the option is unset
+  # - unable to read the file (such as insufficient permissions)
+  
+  if pidFilePath:
+    try:
+      pidFile = open(pidFilePath, "r")
+      pidEntry = pidFile.readline().strip()
+      pidFile.close()
+      
+      if pidEntry.isdigit(): return pidEntry
+    except Exception: pass
+  
   # attempts to resolve using pidof, failing if:
   # - tor's running under a different name
   # - there's multiple instances of tor
@@ -856,7 +871,7 @@
             result = line[2:].split()
             break
       elif key == "pid":
-        result = getPid(int(self.getOption("ControlPort", 9051)))
+        result = getPid(int(self.getOption("ControlPort", 9051)), self.getOption("PidFile"))
       
       # cache value
       if result: self._cachedParam[key] = result