-2005-05-26 Jim Meyering <jim@meyering.net>
+2005-05-26 Paul Eggert <eggert@cs.ucla.edu>
* Version 5.3.1.
+ * NEWS: nohup now redirects a tty stdin to an unreadable fd
+ instead of closing it.
+ * doc/coreutils.texi (nohup invocation): Document this.
+ * src/nohup.c (main): Implement this.
+
+2005-05-26 Jim Meyering <jim@meyering.net>
+
* src/expr.c (toarith): Fix a sign error introduced on 2005-01-14.
Reported by David Alan Gilbert.
* tests/expr/basic: Add tests using arithmetic on negative integers.
join now supports a NUL field separator, e.g., "join -t '\0'".
join now detects and reports incompatible options, e.g., "join -t x -t y",
- nohup now closes stdin if it is a terminal, unless POSIXLY_CORRECT is set.
+ If stdin is a terminal, nohup now closes it and then reopens it with an
+ unreadable file descriptor. (This step is skipped if POSIXLY_CORRECT is set.)
This prevents the command from tying up an OpenSSH session after you logout.
stat -f -c %S outputs the fundamental block size (used for block counts).
@vindex POSIXLY_CORRECT
If standard input is a terminal, it is closed so that terminal
sessions do not mistakenly consider the terminal to be used by the
-command. However, this step is skipped if @env{POSIXLY_CORRECT} is
+command. To avoid glitches in poorly-written programs standard input
+is then reopened with an innocuous file descriptor that cannot be read
+from. However, these steps are skipped if @env{POSIXLY_CORRECT} is
set since @acronym{POSIX} requires standard input to be left alone.
@command{nohup} does not automatically put the command it runs in the
main (int argc, char **argv)
{
int saved_stderr_fd = STDERR_FILENO;
+ bool nohup_out = false;
initialize_main (&argc, &argv);
program_name = argv[0];
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))
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. */
}
}
+ /* 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);
{