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).
This commit is contained in:
enami 2014-11-26 23:44:21 +00:00
parent 839f0f144d
commit 11fe7239df
2 changed files with 34 additions and 29 deletions

View File

@ -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 @@ rshrcmd(int af, char **ahost, u_int32_t rport, const char *locuser,
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,

View File

@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1990, 1993, 1994\
#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 @@ int remerr;
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 @@ int orcmd(char **, int, const char *,
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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
}
#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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
(void)sigprocmask(SIG_BLOCK, &nset, &oset);
#ifndef IN_RCMD
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);
}
}
#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 (!nflag) {
pid = fork();
@ -390,17 +392,18 @@ done:
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 @@ done:
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 @@ done:
while (nfds);
}
#ifndef IN_RCMD
static void
sendsig(int sig)
{
@ -440,8 +444,6 @@ sendsig(int sig)
signo = sig;
(void)write(remerr, &signo, 1);
}
#endif
static char *
copyargs(char **argv)