summaryrefslogtreecommitdiff
path: root/src/nohup.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-05-26 19:27:50 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-05-26 19:27:50 +0000
commit8597e1fd2d4014aa8fe7c1848a48cba455eb8070 (patch)
tree391c68f549a7383a5ddb0830ecc9c7b56e7fe1b9 /src/nohup.c
parent3d8bc90af37c384ad944b57324adf469038d9802 (diff)
downloadcoreutils-8597e1fd2d4014aa8fe7c1848a48cba455eb8070.tar.xz
nohup now redirects a tty stdin to an unreadable fd instead of closing it.
Diffstat (limited to 'src/nohup.c')
-rw-r--r--src/nohup.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/nohup.c b/src/nohup.c
index ba8b3c1f3..b4208fd74 100644
--- a/src/nohup.c
+++ b/src/nohup.c
@@ -75,6 +75,7 @@ int
main (int argc, char **argv)
{
int saved_stderr_fd = STDERR_FILENO;
+ bool nohup_out = false;
initialize_main (&argc, &argv);
program_name = argv[0];
@@ -96,12 +97,6 @@ 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))
@@ -143,6 +138,7 @@ main (int argc, char **argv)
error (0, 0, _("appending output to %s"), quote (file));
free (in_home);
+ nohup_out = true;
}
/* If standard error is a tty, redirect it to stdout. */
@@ -168,6 +164,25 @@ main (int argc, char **argv)
}
}
+ /* If standard input is a tty, replace it with a file descriptor
+ that exists but gives you an error if you try to read 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 (nohup_out)
+ dup (STDOUT_FILENO);
+ else
+ {
+ /* This doesn't give you an error on older systems if you're
+ root, but there's no portable way to fix this and it's
+ not worth worrying about these days. */
+ open ("/", O_RDONLY);
+ }
+ }
+
signal (SIGHUP, SIG_IGN);
{