[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [torbrowser/master] [Linux] Properly detect being run from a GUI program started by startx
commit e38c3b482d537efd140b7cc6b290df50312449e2
Author: Robert Ransom <rransom.8774@xxxxxxxxx>
Date: Wed Aug 24 02:55:08 2011 -0400
[Linux] Properly detect being run from a GUI program started by startx
(cherry picked from commit bd0cdaafaa4b53c258fd6ba591d4be1c4e8ead96)
---
src/RelativeLink/RelativeLink.sh | 47 +++++++++++++++++++++++++++++--------
1 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/src/RelativeLink/RelativeLink.sh b/src/RelativeLink/RelativeLink.sh
index e5239a6..a6287bc 100755
--- a/src/RelativeLink/RelativeLink.sh
+++ b/src/RelativeLink/RelativeLink.sh
@@ -7,21 +7,52 @@
#
# Copyright 2010 The Tor Project. See LICENSE for licensing information.
+# First, make sure DISPLAY is set. If it isn't, we're hosed; scream
+# at stderr and die.
+if [ "x$DISPLAY" = "x" ]; then
+ echo "The Tor Browser Bundle for Linux must be run within the X Window System." >&2
+ echo "Exiting." >&2
+ exit 1
+fi
+
+# Determine whether we are running in a terminal. If we are, we
+# should send our error messages to stderr...
+ARE_WE_RUNNING_IN_A_TERMINAL=0
+if [ -t 1 -o -t 2 ]; then
+ ARE_WE_RUNNING_IN_A_TERMINAL=1
+fi
+
+# ...unless we're running in the same terminal as startx or xinit. In
+# that case, the user is probably running us from a GUI file manager
+# in an X session started by typing startx at the console.
+#
+# Hopefully, the local ps command supports BSD-style options. (The ps
+# commands usually used on Linux and FreeBSD do; do any other OSes
+# support running Linux binaries?)
+ps T 2>/dev/null |grep startx 2>/dev/null |grep -v grep 2>&1 >/dev/null
+not_running_in_same_terminal_as_startx="$?"
+ps T 2>/dev/null |grep xinit 2>/dev/null |grep -v grep 2>&1 >/dev/null
+not_running_in_same_terminal_as_xinit="$?"
+
+# not_running_in_same_terminal_as_foo has the value 1 if we are *not*
+# running in the same terminal as foo.
+if [ "$not_running_in_same_terminal_as_startx" -eq 0 -o \
+ "$not_running_in_same_terminal_as_xinit" -eq 0 ]; then
+ ARE_WE_RUNNING_IN_A_TERMINAL=0
+fi
+
# Complain about an error, by any means necessary.
# Usage: complain message
# message must not begin with a dash.
complain () {
# If we're being run in a terminal, complain there.
- #
- # FIXME Hopefully the user didn't run startx on the console and then
- # double-click 'start-tor-browser' in a GUI file manager.
- if [ -t 2 ]; then
+ if [ "$ARE_WE_RUNNING_IN_A_TERMINAL" -ne 0 ]; then
echo "$1" >&2
return
fi
- # Otherwise, hope that we're being run in a GUI of some sort,
- # and try to pop up a message there in the nicest way
+ # Otherwise, we're being run by a GUI program of some sort;
+ # try to pop up a message in the GUI in the nicest way
# possible.
#
# In mksh, non-existent commands return 127; I'll assume all
@@ -30,10 +61,6 @@ complain () {
# close button, so we do need to look at the exact exit code,
# not just assume the command failed to display a message if
# it returns non-zero.)
- #
- # If DISPLAY isn't set, the first command on the list will
- # fail with a non-127 exit code; that feels wrong somehow, but
- # there's nothing better we can do in that case anyway.
# First, try zenity.
zenity --error --text="$1"
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits