Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/telnet - deal with a dead tty in ttyflush() by clean...



details:   https://anonhg.NetBSD.org/src/rev/c9a43a01288f
branches:  trunk
changeset: 559608:c9a43a01288f
user:      heas <heas%NetBSD.org@localhost>
date:      Sat Mar 20 23:26:05 2004 +0000

description:
- 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.

diffstat:

 usr.bin/telnet/commands.c |   7 +++----
 usr.bin/telnet/externs.h  |   3 +--
 usr.bin/telnet/network.c  |   6 +++---
 usr.bin/telnet/sys_bsd.c  |  20 +++++++-------------
 usr.bin/telnet/telnet.c   |   5 ++---
 usr.bin/telnet/terminal.c |  20 +++++++++++++-------
 6 files changed, 29 insertions(+), 32 deletions(-)

diffs (211 lines):

diff -r 78356db2f532 -r c9a43a01288f usr.bin/telnet/commands.c
--- a/usr.bin/telnet/commands.c Sat Mar 20 23:10:01 2004 +0000
+++ b/usr.bin/telnet/commands.c Sat Mar 20 23:26:05 2004 +0000
@@ -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 @@
        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*/
diff -r 78356db2f532 -r c9a43a01288f usr.bin/telnet/externs.h
--- a/usr.bin/telnet/externs.h  Sat Mar 20 23:10:01 2004 +0000
+++ b/usr.bin/telnet/externs.h  Sat Mar 20 23:26:05 2004 +0000
@@ -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 @@
     NetTraceFile[];    /* Name of file where debugging output goes */
 
 extern jmp_buf
-    peerdied,
     toplevel;          /* For error conditions. */
 
 
diff -r 78356db2f532 -r c9a43a01288f usr.bin/telnet/network.c
--- a/usr.bin/telnet/network.c  Sat Mar 20 23:10:01 2004 +0000
+++ b/usr.bin/telnet/network.c  Sat Mar 20 23:26:05 2004 +0000
@@ -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 @@
            perror(hostname);
            (void)NetClose(net);
            ring_clear_mark(&netoring);
-           longjmp(peerdied, -1);
+           ExitString("Connection closed by foreign host.\n", 1);
            /*NOTREACHED*/
        }
        n = 0;
diff -r 78356db2f532 -r c9a43a01288f usr.bin/telnet/sys_bsd.c
--- a/usr.bin/telnet/sys_bsd.c  Sat Mar 20 23:10:01 2004 +0000
+++ b/usr.bin/telnet/sys_bsd.c  Sat Mar 20 23:26:05 2004 +0000
@@ -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 @@
             */
            tcsetattr(tin, TCSADRAIN, &tmp_tc);
            old = ttyflush(SYNCHing|flushout);
-           if (old == -2)
-               return;
        } while (old < 0 || old > 1);
     }
 
@@ -527,14 +525,6 @@
 
 /* ARGSUSED */
 SIG_FUNC_RET
-deadpeer(int sig)
-{
-       setcommandmode();
-       longjmp(peerdied, -1);
-}
-
-/* ARGSUSED */
-SIG_FUNC_RET
 intr(int sig)
 {
     if (localchars) {
@@ -595,7 +585,7 @@
 {
     (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 @@
     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);
     }
diff -r 78356db2f532 -r c9a43a01288f usr.bin/telnet/telnet.c
--- a/usr.bin/telnet/telnet.c   Sat Mar 20 23:10:01 2004 +0000
+++ b/usr.bin/telnet/telnet.c   Sat Mar 20 23:26:05 2004 +0000
@@ -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 @@
 #endif
 
 jmp_buf        toplevel = { 0 };
-jmp_buf        peerdied;
 
 int    flushline;
 int    linemode;
diff -r 78356db2f532 -r c9a43a01288f usr.bin/telnet/terminal.c
--- a/usr.bin/telnet/terminal.c Sat Mar 20 23:10:01 2004 +0000
+++ b/usr.bin/telnet/terminal.c Sat Mar 20 23:26:05 2004 +0000
@@ -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 @@
 
 
 /*
- *             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 @@
        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)



Home | Main Index | Thread Index | Old Index