[tbb-commits] [tor-browser-bundle/master] Log Tor Browser output to file and disown the process.
mikeperry at torproject.org
mikeperry at torproject.org
Thu Jun 26 00:44:09 UTC 2014
commit c2bd8a5f070e771623aebfb66e95e9e954e5522d
Author: Isis Lovecruft <isis at torproject.org>
Date: Tue May 27 19:47:02 2014 +0000
Log Tor Browser output to file and disown the process.
This will log all Tor Browser's output to ``tbb-debug.log`` in the Tor
Browser $HOME directory.
After starting the Firefox process, we grab Firefox's PID and do a dance
where we wait up to 15 seconds to see if Firefox died (which still is
considered to have happened even if the popup window that another Tor
Browser is running has not been exited out of). If Firefox isn't dead,
we disown the process from the shell and report that exit code. If
Firefox did die somewhere, we do:
wait "$pid"
exitcode="$?"
in order to get the exitcode from the backgrounded Firefox process. The
call to ``wait`` here doesn't actually wait, because it's only called if
the call to ``kill -0 "$pid"`` exited with non-0 status (meaning that
the process has died).
As a last case fallback, in case something really weird happened, for
example if Firefox didn't die within those 15 seconds that we were
waiting, and then it somehow died all-of-a-sudden right before the
if test -z "${exitcode}" [...]
line, then we exit with a code 66.
* CHANGES RelativeLink/RelativeLink.sh to log to tbb-debug.log file,
and then disown the Firefox process, so that we're not leaving a
shell open forever (or leaving the shell to decide where the output
is going to end up).
---
RelativeLink/RelativeLink.sh | 45 +++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/RelativeLink/RelativeLink.sh b/RelativeLink/RelativeLink.sh
index 4e6b7bb..86a40d9 100755
--- a/RelativeLink/RelativeLink.sh
+++ b/RelativeLink/RelativeLink.sh
@@ -284,20 +284,41 @@ setControlPortPasswd ${TOR_CONTROL_PASSWD:='"secret"'}
# XXX: Debug mode for Firefox??
-# not in debug mode, run proceed normally
printf "Launching Tor Browser for Linux in ${HOME}...\n"
cd "${HOME}"
-# XXX Someday we should pass whatever command-line arguments we got
-# (probably filenames or URLs) to Firefox.
-# !!! Dash above comment! Now we pass command-line arguments we got (except --debug) to Firefox.
+logfile=${PWD}/tbb-debug.log
+touch $logfile && printf "Logging Tor Browser output to file: %s\n" "${logfile}"
+
+# !!! We pass command-line arguments we got (except --debug) to Firefox.
# !!! Use at your own risk!
# Adding --class for fixing bug 11102.
-TOR_CONTROL_PASSWD=${TOR_CONTROL_PASSWD} ./firefox --class "Tor Browser" \
- -profile TorBrowser/Data/Browser/profile.default "${@}"
-exitcode="$?"
-if [ "$exitcode" -ne 0 ]; then
- complain "Tor Browser exited abnormally. Exit code: $exitcode"
- exit "$exitcode"
-else
- printf '\nTor Browser exited cleanly.\n'
+TOR_CONTROL_PASSWD=${TOR_CONTROL_PASSWD} ./firefox --class "Tor Browser" \
+ -profile TorBrowser/Data/Browser/profile.default "${@}" > $logfile 2>&1 </dev/null &
+
+pid="$!"
+
+for second in `seq 1 15` ; do
+ sleep 1
+ # Doing `kill -0` doesn't send a signal to the process, but it'll yell
+ # "No such process" if that process doesn't exist (i.e. it already died):
+ if `kill -0 $pid 2>&1 >/dev/null` ; then
+ wait "$pid"
+ exitcode="$?"
+ complain "Tor Browser exited abnormally. Exit code: $exitcode "
+ exit "$exitcode"
+ else
+ continue
+ fi
+done
+
+if test -z "${exitcode}" ; then
+ if test -z "$(kill -0 $pid 2>&1 >/dev/null)" ; then
+ printf "Running Tor Browser process (PID %s) in background...\n" "$pid"
+ disown "$pid"
+ exitcode="0"
+ else
+ exitcode="66" # Something odd happened
+ fi
fi
+
+exit "$exitcode"
More information about the tbb-commits
mailing list