bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nohup definition should be changed


From: Paul Eggert
Subject: Re: nohup definition should be changed
Date: Thu, 12 May 2005 01:57:45 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Your message about nohup's problems had me nodding in agreement, as similar
problems have happened to me.  Are there any objections to my
installing this patch into GNU coreutils?

2005-05-12  Paul Eggert  <address@hidden>

        * NEWS: nohup now closes stdin if it is a terminal, unless
        POSIXLY_CORRECT is set.  This fixes a glitch noted by Wayne Pollock in
        
<https://www.opengroup.org/sophocles/show_mail.tpl?source=L&listname=austin-group-l&id=8341>.
        * doc/coreutils.texi (nohup invocation): Document this.
        * src/nohup.c (main): Implement this.

Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.287
diff -p -u -r1.287 NEWS
--- NEWS        8 May 2005 16:52:43 -0000       1.287
+++ NEWS        12 May 2005 08:51:40 -0000
@@ -139,6 +139,9 @@ GNU coreutils NEWS                      
   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.
+  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).
   stat -f's default output format has been changed to output this size as well.
   stat -f recognizes file systems of type XFS and JFS
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.256
diff -p -u -r1.256 coreutils.texi
--- doc/coreutils.texi  6 May 2005 17:57:35 -0000       1.256
+++ doc/coreutils.texi  12 May 2005 08:51:41 -0000
@@ -12568,6 +12568,12 @@ regardless of the current umask settings
 If standard error is a terminal, it is redirected to the same file
 descriptor as the (possibly-redirected) standard output.
 
address@hidden 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
+set since @acronym{POSIX} requires standard input to be left alone.
+
 @command{nohup} does not automatically put the command it runs in the
 background; you must do that explicitly, by ending the command line
 with an @samp{&}.  Also, @command{nohup} does not change the
Index: src/nohup.c
===================================================================
RCS file: /fetish/cu/src/nohup.c,v
retrieving revision 1.23
diff -p -u -r1.23 nohup.c
--- src/nohup.c 23 Apr 2005 05:57:33 -0000      1.23
+++ src/nohup.c 12 May 2005 08:51:41 -0000
@@ -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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]