- deal with a dead tty in ttyflush() by cleaning-up and exiting instead of

returning a failure code and processing that all the way up the stack.
- deal with a dead peer similarly and do it without setjmp/longjmp() (at
  christos' request).

These fix bin/20304 and my own observations when the remote abruptly closes
the connection.
This commit is contained in:
heas 2004-03-20 23:26:05 +00:00
parent d5561e39ff
commit 209ebbab46
6 changed files with 29 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: commands.c,v 1.58 2004/01/05 23:23:37 jmmv Exp $ */
/* $NetBSD: commands.c,v 1.59 2004/03/20 23:26:05 heas Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@ -63,7 +63,7 @@
#if 0
static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
#else
__RCSID("$NetBSD: commands.c,v 1.58 2004/01/05 23:23:37 jmmv Exp $");
__RCSID("$NetBSD: commands.c,v 1.59 2004/03/20 23:26:05 heas Exp $");
#endif
#endif /* not lint */
@ -2399,8 +2399,7 @@ tn(int argc, char *argv[])
env_export((unsigned char *)"USER", NULL);
}
(void) call(status, "status", "notmuch", 0);
if (setjmp(peerdied) == 0)
telnet(user);
telnet(user);
(void) NetClose(net);
ExitString("Connection closed by foreign host.\n",1);
/*NOTREACHED*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs.h,v 1.30 2003/08/07 11:16:09 agc Exp $ */
/* $NetBSD: externs.h,v 1.31 2004/03/20 23:26:05 heas Exp $ */
/*
* Copyright (c) 1988, 1990, 1993
@ -190,7 +190,6 @@ extern char
NetTraceFile[]; /* Name of file where debugging output goes */
extern jmp_buf
peerdied,
toplevel; /* For error conditions. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: network.c,v 1.16 2003/08/07 11:16:10 agc Exp $ */
/* $NetBSD: network.c,v 1.17 2004/03/20 23:26:05 heas Exp $ */
/*
* Copyright (c) 1988, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93";
#else
__RCSID("$NetBSD: network.c,v 1.16 2003/08/07 11:16:10 agc Exp $");
__RCSID("$NetBSD: network.c,v 1.17 2004/03/20 23:26:05 heas Exp $");
#endif
#endif /* not lint */
@ -155,7 +155,7 @@ netflush(void)
perror(hostname);
(void)NetClose(net);
ring_clear_mark(&netoring);
longjmp(peerdied, -1);
ExitString("Connection closed by foreign host.\n", 1);
/*NOTREACHED*/
}
n = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_bsd.c,v 1.30 2004/02/24 15:12:53 wiz Exp $ */
/* $NetBSD: sys_bsd.c,v 1.31 2004/03/20 23:26:05 heas Exp $ */
/*
* Copyright (c) 1988, 1990, 1993
@ -34,7 +34,7 @@
#if 0
from: static char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
#else
__RCSID("$NetBSD: sys_bsd.c,v 1.30 2004/02/24 15:12:53 wiz Exp $");
__RCSID("$NetBSD: sys_bsd.c,v 1.31 2004/03/20 23:26:05 heas Exp $");
#endif
#endif /* not lint */
@ -310,8 +310,6 @@ TerminalNewMode(int f)
*/
tcsetattr(tin, TCSADRAIN, &tmp_tc);
old = ttyflush(SYNCHing|flushout);
if (old == -2)
return;
} while (old < 0 || old > 1);
}
@ -525,14 +523,6 @@ NetSetPgrp(int fd)
* Various signal handling routines.
*/
/* ARGSUSED */
SIG_FUNC_RET
deadpeer(int sig)
{
setcommandmode();
longjmp(peerdied, -1);
}
/* ARGSUSED */
SIG_FUNC_RET
intr(int sig)
@ -595,7 +585,7 @@ sys_telnet_init(void)
{
(void) signal(SIGINT, intr);
(void) signal(SIGQUIT, intr2);
(void) signal(SIGPIPE, deadpeer);
(void) signal(SIGPIPE, SIG_IGN);
(void) signal(SIGWINCH, sendwin);
(void) signal(SIGTSTP, susp);
(void) signal(SIGINFO, ayt);
@ -738,6 +728,10 @@ process_rings(int netin, int netout, int netex, int ttyin, int ttyout,
if (set[0].revents & POLLOUT) {
returnValue |= netflush();
}
if (set[1].revents & (POLLHUP|POLLNVAL))
return(-1);
if (set[1].revents & POLLOUT) {
returnValue |= (ttyflush(SYNCHing|flushout) > 0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: telnet.c,v 1.27 2003/11/17 11:16:10 wiz Exp $ */
/* $NetBSD: telnet.c,v 1.28 2004/03/20 23:26:05 heas Exp $ */
/*
* Copyright (c) 1988, 1990, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
#else
__RCSID("$NetBSD: telnet.c,v 1.27 2003/11/17 11:16:10 wiz Exp $");
__RCSID("$NetBSD: telnet.c,v 1.28 2004/03/20 23:26:05 heas Exp $");
#endif
#endif /* not lint */
@ -147,7 +147,6 @@ unsigned char telopt_environ = TELOPT_NEW_ENVIRON;
#endif
jmp_buf toplevel = { 0 };
jmp_buf peerdied;
int flushline;
int linemode;

View File

@ -1,4 +1,4 @@
/* $NetBSD: terminal.c,v 1.13 2003/08/07 11:16:11 agc Exp $ */
/* $NetBSD: terminal.c,v 1.14 2004/03/20 23:26:05 heas Exp $ */
/*
* Copyright (c) 1988, 1990, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
#else
__RCSID("$NetBSD: terminal.c,v 1.13 2003/08/07 11:16:11 agc Exp $");
__RCSID("$NetBSD: terminal.c,v 1.14 2004/03/20 23:26:05 heas Exp $");
#endif
#endif /* not lint */
@ -73,10 +73,10 @@ init_terminal(void)
/*
* Send as much data as possible to the terminal.
* Send as much data as possible to the terminal, else exits if
* it encounters a permanent failure when writing to the tty.
*
* Return value:
* -2: Permanent error writing to FD.
* -1: No useful work done, data waiting to go out.
* 0: No data was waiting, so nothing was done.
* 1: All waiting data was written out.
@ -117,10 +117,16 @@ ttyflush(int drop)
ring_consumed(&ttyoring, n);
}
if (n < 0) {
if (errno == EAGAIN)
if (errno == EAGAIN || errno == EINTR) {
return -1;
else
return -2;
} else {
ring_consumed(&ttyoring, ring_full_count(&ttyoring));
setconnmode(0);
setcommandmode();
NetClose(net);
fprintf(stderr, "Connection closed by foreign host.\n");
exit(1);
}
}
if (n == n0) {
if (n0)