summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-08-01 08:47:33 +0000
committerJim Meyering <jim@meyering.net>2002-08-01 08:47:33 +0000
commit2a41097fd7ec3697f6c8ca9b357c1225518bc36a (patch)
treeed9cbb3c53a749edbd42237f614ea8993a2b41d7 /src
parent901688234a2be2ad9c1f20976660c9905f8f24a4 (diff)
downloadcoreutils-2a41097fd7ec3697f6c8ca9b357c1225518bc36a.tar.xz
Change behavior to conform to POSIX 1003.1-2001:
- Do not adjust scheduling priority. - Redirects stderr to stdout, if stderr is not a terminal. - Exit status is now 126 if command was found but not invoked, 127 if nohup failed or if command was not found. Fix bug: command was run if nohup.out wasn't writeable.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/nohup.sh52
1 files changed, 22 insertions, 30 deletions
diff --git a/src/nohup.sh b/src/nohup.sh
index 2e70408b1..6e720c907 100755
--- a/src/nohup.sh
+++ b/src/nohup.sh
@@ -34,7 +34,7 @@ Report bugs to <@PACKAGE_BUGREPORT@>."
if [ $# -eq 0 ]; then
echo >&2 "$usage"
echo >&2 "$usage_try"
- exit 1
+ exit 127
fi
fail=0
@@ -42,46 +42,38 @@ case $# in
1 )
case "z${1}" in
z--help )
- echo "$usage" || fail=1; echo "$usage_help" || fail=1; exit $fail;;
+ echo "$usage" || fail=127; echo "$usage_help" || fail=127
+ exit $fail;;
z--version )
- echo "nohup (@GNU_PACKAGE@) @VERSION@" || fail=1; exit $fail;;
+ echo "nohup (@GNU_PACKAGE@) @VERSION@" || fail=127
+ exit $fail;;
* ) ;;
esac
;;
* ) ;;
esac
-# Make sure we get GNU nice, if possible; also allow
-# it to be somewhere else in PATH if not installed yet.
-# But do not modify PATH itself.
-IFS="${IFS= }"; save_ifs="$IFS"; IFS=":"
-nicepath="@bindir@:$PATH"
-niceprog="nice"
-for nicedir in $nicepath; do
- test -z "$nicedir" && nicedir="."
- if test -x "$nicedir/nice"; then
- niceprog="$nicedir/nice"
- break
- fi
-done
-IFS="$save_ifs"
-
trap "" 1
-oldmask=`umask`; umask 077
-# Only redirect the output if the user didn't already do it.
+
+# Redirect stdout if the user didn't already do it.
if [ -t 1 ]; then
+ oldmask=`umask`; umask 077
# If we cannot write to the current directory, use the home directory.
- if cat /dev/null >> nohup.out; then
- echo "nohup: appending output to \`nohup.out'" 2>&1
- umask $oldmask
- exec "$niceprog" -n 5 -- "$@" >> nohup.out 2>&1
+ if exec >> nohup.out; then
+ echo "nohup: appending output to \`nohup.out'" >&2
+ elif exec >> "$HOME/nohup.out"; then
+ echo "nohup: appending output to \`$HOME/nohup.out'" >&2
else
- cat /dev/null >> $HOME/nohup.out
- echo "nohup: appending output to \`$HOME/nohup.out'" 2>&1
- umask $oldmask
- exec "$niceprog" -n 5 -- "$@" >> $HOME/nohup.out 2>&1
+ echo "nohup: cannot append to either \`nohup.out' or \`$HOME/nohup.out'" \
+ >&2
+ exit 127
fi
-else
umask $oldmask
- exec "$niceprog" -n 5 -- "$@"
fi
+
+# Redirect stderr if the user didn't already do it.
+if [ -t 2 ]; then
+ exec 2>&1
+fi
+
+exec -- "$@"