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

Re: Arm Release 1.4.0



Hans Schnehl <torvallenator@xxxxxxxxx> wrote:

> On Sun, Dec 05, 2010 at 01:02:16PM +0100, Fabian Keil wrote:
> > Damian Johnson <atagar1@xxxxxxxxx> wrote:
> > 
> > > Hi all. I've checked in the resolver fixes (thank Fabian and Hans!)
> > > and a test tarball is available at:
> > > 
> > > http://www.atagar.com/transfer/tmp/arm_bsdTest.tar.bz2
> > > http://www.atagar.com/transfer/tmp/arm_bsdTest.tar.bz2.asc
> > 
> > Thanks.
> Thanks, too.  BTW where is the git repo, please ?   

I don't think there is an official git repository.

> To Fabian, instead of adding another patch:
> Running 'pgrep tor' might show  multiple results, anything containing the string
> 'tor' will present it's pid.

Good point.
 
> On 7 it's 'pgrep -x' to get an exact match of the argument ,see man pgrep(1).

It's -x on CURRENT, too. Patch attached.

I also attached one to get the pid through sockstat. I think changing
it to additionally filter for the control port address would get the
most reliable results.

Fabian
From cdb53450e64c38a5792b10328790dee49be32371 Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@xxxxxxxxxxxxx>
Date: Sun, 5 Dec 2010 15:09:26 +0100
Subject: [PATCH 1/2] Use pgrep's -x flag. Pointed out by Hans Schnehl

---
 src/util/torTools.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index 077c2e1..056b066 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -96,7 +96,7 @@ def getPid(controlPort=9051, pidFilePath=None):
   2. "pidof tor"
   3. "netstat -npl | grep 127.0.0.1:%s" % <tor control port>
   4. "ps -o pid -C tor"
-  5. "pgrep tor"
+  5. "pgrep -x tor"
   
   If pidof or ps provide multiple tor instances then their results are
   discarded (since only netstat can differentiate using the control port). This
@@ -155,7 +155,7 @@ def getPid(controlPort=9051, pidFilePath=None):
   # - tor is running under a different name
   # - there are multiple instances of tor
   try:
-    results = sysTools.call("pgrep tor")
+    results = sysTools.call("pgrep -x tor")
     if len(results) == 1 and len(results[0].split()) == 1:
       pid = results[0].strip()
       if pid.isdigit(): return pid
-- 
1.7.3.2

From fc8f0f7be7590a6bde2c2efaaa84f36be5af1136 Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@xxxxxxxxxxxxx>
Date: Sun, 5 Dec 2010 15:24:50 +0100
Subject: [PATCH 2/2] Add sockstat as another way to get the tor pid.

---
 src/util/torTools.py |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index 056b066..1a36f71 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -96,7 +96,8 @@ def getPid(controlPort=9051, pidFilePath=None):
   2. "pidof tor"
   3. "netstat -npl | grep 127.0.0.1:%s" % <tor control port>
   4. "ps -o pid -C tor"
-  5. "pgrep -x tor"
+  5. "sockstat -4l -P tcp -p %i | grep tor" % <tor control port>
+  6. "pgrep -x tor"
   
   If pidof or ps provide multiple tor instances then their results are
   discarded (since only netstat can differentiate using the control port). This
@@ -151,6 +152,20 @@ def getPid(controlPort=9051, pidFilePath=None):
       if pid.isdigit(): return pid
   except IOError: pass
   
+  # attempts to resolve using sockstat, failing if:
+  # - tor is running under a different name
+  # - there are multiple instances of Tor, using the
+  #   same control port on different addresses.
+  #
+  # XXX: both issues could be solved by filtering for the
+  #      control port IP address instead of the process name.
+  try:
+    results = sysTools.call("sockstat -4l -P tcp -p %i | grep tor" % controlPort)
+    if len(results) == 1 and len(results[0].split()) == 7:
+      pid = results[0].split()[2]
+      if pid.isdigit(): return pid
+  except IOError: pass
+
   # attempts to resolve using pgrep, failing if:
   # - tor is running under a different name
   # - there are multiple instances of tor
-- 
1.7.3.2

Attachment: signature.asc
Description: PGP signature