[tor-commits] [torsocks/pending-changes] Display correct error message when the wrapped program cannot be found in $PATH.

ioerror at torproject.org ioerror at torproject.org
Sun Jan 27 04:10:02 UTC 2013


commit 5c9a88dfc62c85b49ca7f023af4c03d7d61fb3c8
Author: intrigeri <intrigeri at boum.org>
Date:   Mon Jan 30 17:55:42 2012 +0100

    Display correct error message when the wrapped program cannot be found in $PATH.
---
 src/torsocks.in   |    9 ++++++++-
 src/usewithtor.in |    9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/torsocks.in b/src/torsocks.in
index 53db2fc..678f854 100755
--- a/src/torsocks.in
+++ b/src/torsocks.in
@@ -63,6 +63,11 @@
 # Tamas Szerb <toma at rulez.org>
 # Modified by Robert Hogan <robert at roberthogan.net> April 16th 2006
 
+not_found () {
+    echo "ERROR: $1 cannot be found in PATH." >&2
+    exit 1
+}
+
 set_id () {
     echo "ERROR: $1 is set${2}id. torsocks will not work on a set${2}id executable." >&2
     exit 1
@@ -133,7 +138,9 @@ case "$1" in
 
     if [ $# -gt 0 ]
     then
-      if [ -u `which "$1"` ]; then
+      if ! which "$1" >/dev/null 2>&1; then
+          not_found $1
+      elif [ -u `which "$1"` ]; then
           set_id $1 u
       elif [ -g `which "$1"` ]; then
           set_id $1 g
diff --git a/src/usewithtor.in b/src/usewithtor.in
index 0a1e42d..e606760 100644
--- a/src/usewithtor.in
+++ b/src/usewithtor.in
@@ -42,6 +42,11 @@ usage () {
 	echo "Usage: $0 [-hv] <command> [<options>...]"
 }
 
+not_found () {
+	echo "ERROR: $1 cannot be found in PATH." >&2
+	exit 1
+}
+
 set_id () {
 	echo "ERROR: $1 is set${2}id. usewithtor will not work on a set${2}id executable." >&2
 	exit 1
@@ -68,7 +73,9 @@ while [ "$1" ]; do
 	esac
 done
 
-if [ -u `which "$1"` ]; then
+if ! which "$1" >/dev/null 2>&1; then
+	not_found $1
+elif [ -u `which "$1"` ]; then
 	set_id $1 u
 elif [ -g `which "$1"` ]; then
 	set_id $1 g





More information about the tor-commits mailing list