summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2004-05-26 18:18:00 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2004-05-26 18:18:00 +0000
commitff29469fca330b41980c40fcad9f5fdaeba68bd9 (patch)
tree6a4f0d0869669b2df6fb8153171803908e2a458c
parent4f22c400434365c1af3c92ce2e09b772225c198d (diff)
if one process is killed, kill the other ourself; various ok
-rw-r--r--usr.bin/tip/acu.c6
-rw-r--r--usr.bin/tip/cmds.c31
-rw-r--r--usr.bin/tip/cu.c5
-rw-r--r--usr.bin/tip/tip.c20
-rw-r--r--usr.bin/tip/tip.h5
-rw-r--r--usr.bin/tip/tipout.c10
6 files changed, 42 insertions, 35 deletions
diff --git a/usr.bin/tip/acu.c b/usr.bin/tip/acu.c
index c949c68e762..df0ae79b774 100644
--- a/usr.bin/tip/acu.c
+++ b/usr.bin/tip/acu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acu.c,v 1.9 2003/06/03 02:56:18 millert Exp $ */
+/* $OpenBSD: acu.c,v 1.10 2004/05/26 18:17:58 deraadt Exp $ */
/* $NetBSD: acu.c,v 1.4 1996/12/29 10:34:03 cgd Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93";
#endif
-static const char rcsid[] = "$OpenBSD: acu.c,v 1.9 2003/06/03 02:56:18 millert Exp $";
+static const char rcsid[] = "$OpenBSD: acu.c,v 1.10 2004/05/26 18:17:58 deraadt Exp $";
#endif /* not lint */
#include "tip.h"
@@ -174,7 +174,7 @@ disconnect(reason)
}
static void
-acuabort(s)
+acuabort(int s)
{
signal(s, SIG_IGN);
longjmp(jmpbuf, 1);
diff --git a/usr.bin/tip/cmds.c b/usr.bin/tip/cmds.c
index 370b3ccd49d..8d7cfeb5132 100644
--- a/usr.bin/tip/cmds.c
+++ b/usr.bin/tip/cmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmds.c,v 1.18 2004/02/20 20:34:32 deraadt Exp $ */
+/* $OpenBSD: cmds.c,v 1.19 2004/05/26 18:17:58 deraadt Exp $ */
/* $NetBSD: cmds.c,v 1.7 1997/02/11 09:24:03 mrg Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
#endif
-static const char rcsid[] = "$OpenBSD: cmds.c,v 1.18 2004/02/20 20:34:32 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: cmds.c,v 1.19 2004/05/26 18:17:58 deraadt Exp $";
#endif /* not lint */
#include "tip.h"
@@ -63,8 +63,7 @@ void intcopy(); /* interrupt routine for file transfers */
* get a file from the remote host
*/
void
-getfl(c)
- char c;
+getfl(char c)
{
char buf[256], *cp, *expand();
@@ -94,8 +93,7 @@ getfl(c)
* Cu-like take command
*/
void
-cu_take(cc)
- char cc;
+cu_take(char cc)
{
int fd, argc;
char line[BUFSIZ], *expand(), *cp;
@@ -139,7 +137,7 @@ transfer(buf, fd, eofchars)
parwrite(FD, buf, size(buf));
quit = 0;
- kill(pid, SIGIOT);
+ kill(tipout_pid, SIGIOT);
read(repdes[0], (char *)&ccc, 1); /* Wait until read process stops */
/*
@@ -296,7 +294,7 @@ transmit(fd, eofchars, command)
time_t start_t, stop_t;
sig_t f;
- kill(pid, SIGIOT); /* put TIPOUT into a wait state */
+ kill(tipout_pid, SIGIOT); /* put TIPOUT into a wait state */
stop = 0;
f = signal(SIGINT, stopsnd);
tcsetattr(0, TCSAFLUSH, &defchars);
@@ -422,8 +420,7 @@ cu_put(cc)
* wait for echo & handle timeout
*/
void
-send(c)
- int c;
+send(int c)
{
char cc;
int retry = 0;
@@ -473,7 +470,7 @@ pipeout(c)
putchar(c);
if (prompt("Local command? ", buf, sizeof(buf)))
return;
- kill(pid, SIGIOT); /* put TIPOUT into a wait state */
+ kill(tipout_pid, SIGIOT); /* put TIPOUT into a wait state */
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
tcsetattr(0, TCSAFLUSH, &defchars);
@@ -516,7 +513,7 @@ pipeout(c)
* 2 <-> local tty out
*/
void
-consh(c)
+consh(int c)
{
char buf[256];
int status, p;
@@ -526,7 +523,7 @@ consh(c)
putchar(c);
if (prompt("Local command? ", buf, sizeof(buf)))
return;
- kill(pid, SIGIOT); /* put TIPOUT into a wait state */
+ kill(tipout_pid, SIGIOT); /* put TIPOUT into a wait state */
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
tcsetattr(0, TCSAFLUSH, &defchars);
@@ -567,7 +564,7 @@ consh(c)
* Escape to local shell
*/
void
-shell()
+shell(void)
{
int status;
char *cp;
@@ -609,7 +606,7 @@ setscript()
/*
* enable TIPOUT side for dialogue
*/
- kill(pid, SIGEMT);
+ kill(tipout_pid, SIGEMT);
if (boolean(value(SCRIPT)))
write(fildes[1], value(RECORD), size(value(RECORD)));
write(fildes[1], "\n", 1);
@@ -646,7 +643,7 @@ tipabort(msg)
char *msg;
{
- kill(pid, SIGTERM);
+ kill(tipout_pid, SIGTERM);
disconnect(msg);
if (msg != NOSTR)
printf("\r\n%s", msg);
@@ -747,7 +744,7 @@ variable()
vlex(buf);
if (vtable[BEAUTIFY].v_access&CHANGED) {
vtable[BEAUTIFY].v_access &= ~CHANGED;
- kill(pid, SIGSYS);
+ kill(tipout_pid, SIGSYS);
}
if (vtable[SCRIPT].v_access&CHANGED) {
vtable[SCRIPT].v_access &= ~CHANGED;
diff --git a/usr.bin/tip/cu.c b/usr.bin/tip/cu.c
index 949efec9ce1..5a65aa030e5 100644
--- a/usr.bin/tip/cu.c
+++ b/usr.bin/tip/cu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cu.c,v 1.14 2003/06/03 02:56:18 millert Exp $ */
+/* $OpenBSD: cu.c,v 1.15 2004/05/26 18:17:59 deraadt Exp $ */
/* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
#endif
-static const char rcsid[] = "$OpenBSD: cu.c,v 1.14 2003/06/03 02:56:18 millert Exp $";
+static const char rcsid[] = "$OpenBSD: cu.c,v 1.15 2004/05/26 18:17:59 deraadt Exp $";
#endif /* not lint */
#include "tip.h"
@@ -135,6 +135,7 @@ cumain(argc, argv)
signal(SIGQUIT, cleanup);
signal(SIGHUP, cleanup);
signal(SIGTERM, cleanup);
+ signal(SIGCHLD, SIG_IGN);
/*
* The "cu" host name is used to define the
diff --git a/usr.bin/tip/tip.c b/usr.bin/tip/tip.c
index 3e862851d7e..fbc0af68445 100644
--- a/usr.bin/tip/tip.c
+++ b/usr.bin/tip/tip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tip.c,v 1.22 2003/10/15 22:33:18 deraadt Exp $ */
+/* $OpenBSD: tip.c,v 1.23 2004/05/26 18:17:59 deraadt Exp $ */
/* $NetBSD: tip.c,v 1.13 1997/04/20 00:03:05 mellon Exp $ */
/*
@@ -40,7 +40,7 @@ static const char copyright[] =
#if 0
static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
#endif
-static const char rcsid[] = "$OpenBSD: tip.c,v 1.22 2003/10/15 22:33:18 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: tip.c,v 1.23 2004/05/26 18:17:59 deraadt Exp $";
#endif /* not lint */
/*
@@ -55,7 +55,7 @@ static const char rcsid[] = "$OpenBSD: tip.c,v 1.22 2003/10/15 22:33:18 deraadt
int disc = TTYDISC; /* tip normally runs this way */
void intprompt();
void timeout();
-void cleanup();
+void cleanup(int);
char PNbuf[256]; /* This limits the size of a number */
int
@@ -138,6 +138,7 @@ notnumber:
(void)signal(SIGQUIT, cleanup);
(void)signal(SIGHUP, cleanup);
(void)signal(SIGTERM, cleanup);
+ (void)signal(SIGCHLD, SIG_IGN);
if ((i = hunt(system)) == 0) {
printf("all ports busy\n");
@@ -203,12 +204,12 @@ cucommon:
i = fcntl(FD, F_GETFL);
if (i == -1) {
perror("fcntl");
- cleanup();
+ cleanup(0);
}
i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK);
if (i == -1) {
perror("fcntl");
- cleanup();
+ cleanup(0);
}
tcgetattr(0, &defterm);
@@ -236,7 +237,8 @@ cucommon:
* so, fork one process for local side and one for remote.
*/
printf(cumode ? "Connected\r\n" : "\07connected\r\n");
- if ((pid = fork()))
+ tipin_pid = getpid();
+ if ((tipout_pid = fork()))
tipin();
else
tipout();
@@ -245,7 +247,7 @@ cucommon:
}
void
-cleanup()
+cleanup(int signo)
{
daemon_uid();
@@ -253,6 +255,10 @@ cleanup()
if (odisc)
ioctl(0, TIOCSETD, (char *)&odisc);
unraw();
+ if (signo && tipout_pid) {
+ kill(tipout_pid, signo);
+ wait(NULL);
+ }
exit(0);
}
diff --git a/usr.bin/tip/tip.h b/usr.bin/tip/tip.h
index c976ab20492..88429c5cad1 100644
--- a/usr.bin/tip/tip.h
+++ b/usr.bin/tip/tip.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tip.h,v 1.17 2003/10/15 22:33:18 deraadt Exp $ */
+/* $OpenBSD: tip.h,v 1.18 2004/05/26 18:17:59 deraadt Exp $ */
/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */
/*
@@ -245,7 +245,8 @@ int AC; /* open file descriptor to dialer (v831 only) */
int vflag; /* print .tiprc initialization sequence */
int noesc; /* no `~' escape char */
int sfd; /* for ~< operation */
-int pid; /* pid of tipout */
+pid_t tipin_pid; /* pid of tipin */
+pid_t tipout_pid; /* pid of tipout */
uid_t uid, euid; /* real and effective user id's */
gid_t gid, egid; /* real and effective group id's */
int stop; /* stop transfer session flag */
diff --git a/usr.bin/tip/tipout.c b/usr.bin/tip/tipout.c
index 57ca3e356ef..e84ec4113bb 100644
--- a/usr.bin/tip/tipout.c
+++ b/usr.bin/tip/tipout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tipout.c,v 1.10 2003/06/03 02:56:18 millert Exp $ */
+/* $OpenBSD: tipout.c,v 1.11 2004/05/26 18:17:59 deraadt Exp $ */
/* $NetBSD: tipout.c,v 1.5 1996/12/29 10:34:12 cgd Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)tipout.c 8.1 (Berkeley) 6/6/93";
#endif
-static const char rcsid[] = "$OpenBSD: tipout.c,v 1.10 2003/06/03 02:56:18 millert Exp $";
+static const char rcsid[] = "$OpenBSD: tipout.c,v 1.11 2004/05/26 18:17:59 deraadt Exp $";
#endif /* not lint */
#include "tip.h"
@@ -95,11 +95,13 @@ intEMT()
}
void
-intTERM()
+intTERM(int signo)
{
if (boolean(value(SCRIPT)) && fscript != NULL)
fclose(fscript);
+ if (signo && tipin_pid)
+ kill(tipin_pid, signo);
exit(0);
}
@@ -140,7 +142,7 @@ tipout()
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
sigprocmask(SIG_BLOCK, &mask, NULL);
- intTERM();
+ intTERM(0);
/*NOTREACHED*/
}
continue;