summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-05-12 09:24:56 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-05-12 09:24:56 +0000
commit13620274aedeadaed89e67d7799d16ee2bcec663 (patch)
tree2d63b31bc9c451d58fbe513ac341956efd033f9b
parentb24a3e839105c66212dbd475600ba1af9f1a9d01 (diff)
downloadcoreutils-13620274aedeadaed89e67d7799d16ee2bcec663.tar.xz
(main): nohup now closes stdin if it is a terminal, unless
POSIXLY_CORRECT is set.
-rw-r--r--src/nohup.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/nohup.c b/src/nohup.c
index 45e632661..d0c2c85c0 100644
--- a/src/nohup.c
+++ b/src/nohup.c
@@ -96,6 +96,12 @@ main (int argc, char **argv)
usage (NOHUP_FAILURE);
}
+ /* If standard input is a tty, close it. POSIX requires nohup to
+ leave standard input alone, but that's less useful in practice as
+ it causes a "nohup foo & exit" session to hang with OpenSSH. */
+ if (!getenv ("POSIXLY_CORRECT") && isatty (STDIN_FILENO))
+ close (STDIN_FILENO);
+
/* If standard output is a tty, redirect it (appending) to a file.
First try nohup.out, then $HOME/nohup.out. */
if (isatty (STDOUT_FILENO))
@@ -139,7 +145,7 @@ main (int argc, char **argv)
free (in_home);
}
- /* If stderr is on a tty, redirect it to stdout. */
+ /* If standard error is a tty, redirect it to stdout. */
if (isatty (STDERR_FILENO))
{
/* Save a copy of stderr before redirecting, so we can use the original