Source-Changes-HG archive

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

[src/trunk]: src Changes done in rsh.c rev. 1.36 was incomplete. As chuq poi...



details:   https://anonhg.NetBSD.org/src/rev/60dd3521ae2e
branches:  trunk
changeset: 804166:60dd3521ae2e
user:      enami <enami%NetBSD.org@localhost>
date:      Wed Nov 26 23:44:21 2014 +0000

description:
Changes done in rsh.c rev. 1.36 was incomplete.  As chuq pointed
in private mail, it broke rcp(1).

To achieve the documented behavior and to fix long standing incorrect
rsh(1) behavior which I've tried to fix in rev. 1.36, rcmd(1) should have
two operation mode; whether it should relay signal information on
auxiliary channel or not, depending on the argument `fd2p' passed to rcmd(3).
So, make rcmd(1) behave differntly depending on the environment variable and
set it when necessary in rcmd(3) according to how auxiliary channel
is set up by rcmd(3).

diffstat:

 lib/libc/net/rcmd.c |   7 ++++-
 usr.bin/rsh/rsh.c   |  54 +++++++++++++++++++++++++++-------------------------
 2 files changed, 33 insertions(+), 28 deletions(-)

diffs (173 lines):

diff -r 3dfe572bf4a6 -r 60dd3521ae2e lib/libc/net/rcmd.c
--- a/lib/libc/net/rcmd.c       Wed Nov 26 22:50:22 2014 +0000
+++ b/lib/libc/net/rcmd.c       Wed Nov 26 23:44:21 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rcmd.c,v 1.70 2014/09/18 13:58:20 christos Exp $       */
+/*     $NetBSD: rcmd.c,v 1.71 2014/11/26 23:44:21 enami Exp $  */
 
 /*
  * Copyright (c) 1983, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)rcmd.c     8.3 (Berkeley) 3/26/94";
 #else
-__RCSID("$NetBSD: rcmd.c,v 1.70 2014/09/18 13:58:20 christos Exp $");
+__RCSID("$NetBSD: rcmd.c,v 1.71 2014/11/26 23:44:21 enami Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -464,6 +464,9 @@
                        const char *program;
                        program = strrchr(rshcmd, '/');
                        program = program ? program + 1 : rshcmd;
+                       if (fd2p)
+                               /* ask rcmd to relay signal information */
+                               setenv("RCMD_RELAY_SIGNAL", "YES", 1);
                        switch (af) {
                        case AF_INET:
                                execlp(rshcmd, program, "-4", "-l", remuser,
diff -r 3dfe572bf4a6 -r 60dd3521ae2e usr.bin/rsh/rsh.c
--- a/usr.bin/rsh/rsh.c Wed Nov 26 22:50:22 2014 +0000
+++ b/usr.bin/rsh/rsh.c Wed Nov 26 23:44:21 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rsh.c,v 1.37 2014/10/30 06:13:50 dholland Exp $        */
+/*     $NetBSD: rsh.c,v 1.38 2014/11/26 23:44:21 enami Exp $   */
 
 /*-
  * Copyright (c) 1983, 1990, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)rsh.c      8.4 (Berkeley) 4/29/95";
 #else
-__RCSID("$NetBSD: rsh.c,v 1.37 2014/10/30 06:13:50 dholland Exp $");
+__RCSID("$NetBSD: rsh.c,v 1.38 2014/11/26 23:44:21 enami Exp $");
 #endif
 #endif /* not lint */
 
@@ -76,9 +76,7 @@
 static int sigs[] = { SIGINT, SIGTERM, SIGQUIT };
 
 static char   *copyargs(char **);
-#ifndef IN_RCMD
 static void    sendsig(int);
-#endif
 static int     checkfd(struct pollfd *, int);
 static void    talk(int, sigset_t *, pid_t, int);
 __dead static void     usage(void);
@@ -87,6 +85,7 @@
     const char *, const char *, int *);
 int     orcmd_af(char **, int, const char *,
     const char *, const char *, int *, int);
+static int     relay_signal;
 #endif
 
 int
@@ -98,7 +97,7 @@
        struct protoent *proto;
 
 #ifdef IN_RCMD
-       char    *locuser = 0, *loop;
+       char    *locuser = 0, *loop, *relay;
 #endif /* IN_RCMD */
        int argoff, asrsh, ch, dflag, nflag, one, rem;
        size_t i;
@@ -133,6 +132,8 @@
        }
 
 #ifdef IN_RCMD
+       if ((relay = getenv("RCMD_RELAY_SIGNAL")) && strcmp(relay, "YES") == 0)
+               relay_signal = 1;
        if ((loop = getenv("RCMD_LOOP")) && strcmp(loop, "YES") == 0)
                warnx("rcmd appears to be looping!");
 
@@ -152,7 +153,7 @@
        if ((name = strdup(pw->pw_name)) == NULL)
                err(1, "malloc");
        while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != -1)
-               switch(ch) {
+               switch (ch) {
                case '4':
                        family = AF_INET;
                        break;
@@ -268,16 +269,17 @@
 
        (void)sigprocmask(SIG_BLOCK, &nset, &oset);
 
-#ifndef IN_RCMD
-       for (i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++) {
-               struct sigaction sa;
+#ifdef IN_RCMD
+       if (!relay_signal)
+#endif
+               for (i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++) {
+                       struct sigaction sa;
 
-               if (sa.sa_handler != SIG_IGN) {
-                       sa.sa_handler = sendsig;
-                       (void)sigaction(sigs[i], &sa, NULL);
+                       if (sa.sa_handler != SIG_IGN) {
+                               sa.sa_handler = sendsig;
+                               (void)sigaction(sigs[i], &sa, NULL);
+                       }
                }
-       }
-#endif
 
        if (!nflag) {
                pid = fork();
@@ -390,17 +392,18 @@
                exit(0);
        }
 
-#ifdef IN_RCMD
-       fdp = &fds[0];
-       nfds = 3;
-       fds[0].events = POLLIN|POLLNVAL|POLLERR|POLLHUP;
-       fds[0].fd = 2;
-#else
-       (void)sigprocmask(SIG_SETMASK, oset, NULL);
        fdp = &fds[1];
        nfds = 2;
        fds[0].events = 0;
+#ifdef IN_RCMD
+       if (relay_signal) {
+               fdp = &fds[0];
+               nfds = 3;
+               fds[0].events = POLLIN|POLLNVAL|POLLERR|POLLHUP;
+               fds[0].fd = 2;
+       } else
 #endif
+               (void)sigprocmask(SIG_SETMASK, oset, NULL);
        fds[1].events = fds[2].events = POLLIN|POLLNVAL|POLLERR|POLLHUP;
        fds[1].fd = remerr;
        fds[2].fd = rem;
@@ -418,8 +421,10 @@
                        nfds--;
                        fds[1].events = 0;
 #ifdef IN_RCMD
-                       nfds--;
-                       fds[0].events = 0;
+                       if (relay_signal) {
+                               nfds--;
+                               fds[0].events = 0;
+                       }
 #endif
                        fdp = &fds[2];
                }
@@ -431,7 +436,6 @@
        while (nfds);
 }
 
-#ifndef IN_RCMD
 static void
 sendsig(int sig)
 {
@@ -440,8 +444,6 @@
        signo = sig;
        (void)write(remerr, &signo, 1);
 }
-#endif
-
 
 static char *
 copyargs(char **argv)



Home | Main Index | Thread Index | Old Index