commit-inetutils
[Top][All Lists]
Advanced

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

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1_100-9-g807


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1_100-9-g807de6d
Date: Wed, 16 Oct 2013 18:25:07 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  807de6dd3342a98ed655e0cae783d34e6c9c6ad5 (commit)
      from  096ec84d46960adec56ed2d28eeda2fbd83cdb1f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=807de6dd3342a98ed655e0cae783d34e6c9c6ad5


commit 807de6dd3342a98ed655e0cae783d34e6c9c6ad5
Author: Mats Erik Andersson <address@hidden>
Date:   Wed Oct 16 19:32:06 2013 +0200

    rsh: Kill child process after SIGPIPE.
    
    The default action for SIGPIPE causes the child
    process to remain as an orphaned process, stealing
    stdin from the command line.

diff --git a/ChangeLog b/ChangeLog
index 35ca670..6a3872b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2013-10-16  Mats Erik Andersson  <address@hidden>
+
+       rsh: Kill child process after SIGPIPE.
+       The default action for SIGPIPE will leave the
+       child process running.  This caused, until now
+       and including legacy implementations, blocking
+       of stdin, and to conditionally leave also the
+       remote server running.
+
+       * src/rsh.c (end_of_pipe): New variable.
+       (sigpipe): New function.
+       (talk) [HAVE_SIGACTION]: New variable SA.
+       <parent process>: Assign a signal handler to SIGPIPE.
+       Add `&& !end_of_pipe' to the loop condition, so that
+       talk() returns after SIGPIPE.  The child process will
+       then be killed at the end of main().
+
 2013-10-06  Mats Erik Andersson  <address@hidden>
 
        rsh: Detach input stream.
diff --git a/src/rsh.c b/src/rsh.c
index bf3b47c..87356f2 100644
--- a/src/rsh.c
+++ b/src/rsh.c
@@ -126,9 +126,11 @@ int wlen;
  * rsh - remote shell
  */
 int rfd2;
+int end_of_pipe = 0;           /* Used by parent process.  */
 
 char *copyargs (char **);
 void sendsig (int);
+void sigpipe (int);
 void talk (int, sigset_t *, pid_t, int);
 void warning (const char *, ...);
 
@@ -607,6 +609,9 @@ talk (int null_input_option, sigset_t * osigs, pid_t pid, 
int rem)
   int cc, wc;
   fd_set readfrom, ready, rembits;
   char *bp, buf[BUFSIZ];
+#ifdef HAVE_SIGACTION
+  struct sigaction sa;
+#endif
 
   if (!null_input_option && pid == 0)
     {
@@ -660,9 +665,23 @@ talk (int null_input_option, sigset_t * osigs, pid_t pid, 
int rem)
 
 #ifdef HAVE_SIGACTION
   sigprocmask (SIG_SETMASK, osigs, NULL);
-#else
+#else /* !HAVE_SIGACTION */
   sigsetmask (*osigs);
 #endif
+
+  /* The access to SIGPIPE is neeeded to kill the child process
+   * in an orderly fashion, for example when a command line
+   * pipe fails.  Otherwise the child lives on eternally.
+   */
+#ifdef HAVE_SIGACTION
+  sigemptyset (&sa.sa_mask);
+  sa.sa_flags = SA_RESTART;
+  sa.sa_handler = sigpipe;
+  (void) sigaction (SIGPIPE, &sa, NULL);
+#else /* !HAVE_SIGACTION */
+  signal (SIGPIPE, sigpipe);
+#endif
+
   FD_ZERO (&readfrom);
   FD_SET (rfd2, &readfrom);
   FD_SET (rem, &readfrom);
@@ -725,7 +744,8 @@ talk (int null_input_option, sigset_t * osigs, pid_t pid, 
int rem)
            write (1, buf, cc);
        }
     }
-  while (FD_ISSET (rfd2, &readfrom) || FD_ISSET (rem, &readfrom));
+  while ((FD_ISSET (rfd2, &readfrom) || FD_ISSET (rem, &readfrom))
+        && !end_of_pipe);
 }
 
 void
@@ -753,6 +773,12 @@ sendsig (int sig)
     write (rfd2, &signo, 1);
 }
 
+void
+sigpipe (int sig _GL_UNUSED_PARAMETER)
+{
+  ++end_of_pipe;
+}
+
 #if defined KERBEROS || defined SHISHI
 void
 warning (const char *fmt, ...)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog |   17 +++++++++++++++++
 src/rsh.c |   30 ++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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