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:
parent
839f0f144d
commit
11fe7239df
|
@ -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
|
* Copyright (c) 1983, 1993, 1994
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
|
static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
|
||||||
#else
|
#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
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#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;
|
const char *program;
|
||||||
program = strrchr(rshcmd, '/');
|
program = strrchr(rshcmd, '/');
|
||||||
program = program ? program + 1 : rshcmd;
|
program = program ? program + 1 : rshcmd;
|
||||||
|
if (fd2p)
|
||||||
|
/* ask rcmd to relay signal information */
|
||||||
|
setenv("RCMD_RELAY_SIGNAL", "YES", 1);
|
||||||
switch (af) {
|
switch (af) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
execlp(rshcmd, program, "-4", "-l", remuser,
|
execlp(rshcmd, program, "-4", "-l", remuser,
|
||||||
|
|
|
@ -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
|
* Copyright (c) 1983, 1990, 1993, 1994
|
||||||
|
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1990, 1993, 1994\
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)rsh.c 8.4 (Berkeley) 4/29/95";
|
static char sccsid[] = "@(#)rsh.c 8.4 (Berkeley) 4/29/95";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
@ -76,9 +76,7 @@ int remerr;
|
||||||
static int sigs[] = { SIGINT, SIGTERM, SIGQUIT };
|
static int sigs[] = { SIGINT, SIGTERM, SIGQUIT };
|
||||||
|
|
||||||
static char *copyargs(char **);
|
static char *copyargs(char **);
|
||||||
#ifndef IN_RCMD
|
|
||||||
static void sendsig(int);
|
static void sendsig(int);
|
||||||
#endif
|
|
||||||
static int checkfd(struct pollfd *, int);
|
static int checkfd(struct pollfd *, int);
|
||||||
static void talk(int, sigset_t *, pid_t, int);
|
static void talk(int, sigset_t *, pid_t, int);
|
||||||
__dead static void usage(void);
|
__dead static void usage(void);
|
||||||
|
@ -87,6 +85,7 @@ int orcmd(char **, int, const char *,
|
||||||
const char *, const char *, int *);
|
const char *, const char *, int *);
|
||||||
int orcmd_af(char **, int, const char *,
|
int orcmd_af(char **, int, const char *,
|
||||||
const char *, const char *, int *, int);
|
const char *, const char *, int *, int);
|
||||||
|
static int relay_signal;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -98,7 +97,7 @@ main(int argc, char **argv)
|
||||||
struct protoent *proto;
|
struct protoent *proto;
|
||||||
|
|
||||||
#ifdef IN_RCMD
|
#ifdef IN_RCMD
|
||||||
char *locuser = 0, *loop;
|
char *locuser = 0, *loop, *relay;
|
||||||
#endif /* IN_RCMD */
|
#endif /* IN_RCMD */
|
||||||
int argoff, asrsh, ch, dflag, nflag, one, rem;
|
int argoff, asrsh, ch, dflag, nflag, one, rem;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -133,6 +132,8 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IN_RCMD
|
#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)
|
if ((loop = getenv("RCMD_LOOP")) && strcmp(loop, "YES") == 0)
|
||||||
warnx("rcmd appears to be looping!");
|
warnx("rcmd appears to be looping!");
|
||||||
|
|
||||||
|
@ -152,7 +153,7 @@ main(int argc, char **argv)
|
||||||
if ((name = strdup(pw->pw_name)) == NULL)
|
if ((name = strdup(pw->pw_name)) == NULL)
|
||||||
err(1, "malloc");
|
err(1, "malloc");
|
||||||
while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != -1)
|
while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != -1)
|
||||||
switch(ch) {
|
switch (ch) {
|
||||||
case '4':
|
case '4':
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
break;
|
break;
|
||||||
|
@ -268,16 +269,17 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
(void)sigprocmask(SIG_BLOCK, &nset, &oset);
|
(void)sigprocmask(SIG_BLOCK, &nset, &oset);
|
||||||
|
|
||||||
#ifndef IN_RCMD
|
#ifdef IN_RCMD
|
||||||
for (i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++) {
|
if (!relay_signal)
|
||||||
struct sigaction sa;
|
|
||||||
|
|
||||||
if (sa.sa_handler != SIG_IGN) {
|
|
||||||
sa.sa_handler = sendsig;
|
|
||||||
(void)sigaction(sigs[i], &sa, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#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) {
|
if (!nflag) {
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
@ -390,17 +392,18 @@ done:
|
||||||
exit(0);
|
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];
|
fdp = &fds[1];
|
||||||
nfds = 2;
|
nfds = 2;
|
||||||
fds[0].events = 0;
|
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
|
#endif
|
||||||
|
(void)sigprocmask(SIG_SETMASK, oset, NULL);
|
||||||
fds[1].events = fds[2].events = POLLIN|POLLNVAL|POLLERR|POLLHUP;
|
fds[1].events = fds[2].events = POLLIN|POLLNVAL|POLLERR|POLLHUP;
|
||||||
fds[1].fd = remerr;
|
fds[1].fd = remerr;
|
||||||
fds[2].fd = rem;
|
fds[2].fd = rem;
|
||||||
|
@ -418,8 +421,10 @@ done:
|
||||||
nfds--;
|
nfds--;
|
||||||
fds[1].events = 0;
|
fds[1].events = 0;
|
||||||
#ifdef IN_RCMD
|
#ifdef IN_RCMD
|
||||||
nfds--;
|
if (relay_signal) {
|
||||||
fds[0].events = 0;
|
nfds--;
|
||||||
|
fds[0].events = 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
fdp = &fds[2];
|
fdp = &fds[2];
|
||||||
}
|
}
|
||||||
|
@ -431,7 +436,6 @@ done:
|
||||||
while (nfds);
|
while (nfds);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef IN_RCMD
|
|
||||||
static void
|
static void
|
||||||
sendsig(int sig)
|
sendsig(int sig)
|
||||||
{
|
{
|
||||||
|
@ -440,8 +444,6 @@ sendsig(int sig)
|
||||||
signo = sig;
|
signo = sig;
|
||||||
(void)write(remerr, &signo, 1);
|
(void)write(remerr, &signo, 1);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
copyargs(char **argv)
|
copyargs(char **argv)
|
||||||
|
|
Loading…
Reference in New Issue