Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp allow a second SIGINT during the "xfer aborted. ...



details:   https://anonhg.NetBSD.org/src/rev/41357f8ff28a
branches:  trunk
changeset: 477059:41357f8ff28a
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Oct 09 12:48:12 1999 +0000

description:
allow a second SIGINT during the "xfer aborted. waiting for remote to finish abort."
stage. if this occurs, just call lostpeer() to close the connection.  whilst this
might be considered brutal, it's also extremely handy if you're impatient or there's
lossage at the remote end.

diffstat:

 usr.bin/ftp/extern.h |   3 ++-
 usr.bin/ftp/ftp.c    |  44 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 38 insertions(+), 9 deletions(-)

diffs (97 lines):

diff -r f4d4924626a7 -r 41357f8ff28a usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h      Sat Oct 09 08:13:00 1999 +0000
+++ b/usr.bin/ftp/extern.h      Sat Oct 09 12:48:12 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.44 1999/10/09 03:00:55 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.45 1999/10/09 12:48:12 lukem Exp $        */
 
 /*-
  * Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -104,6 +104,7 @@
 struct tm;
 
 void   abort_remote __P((FILE *));
+void   abort_squared __P((int));
 void   abortpt __P((int));
 void   abortxfer __P((int));
 void   account __P((int, char **));
diff -r f4d4924626a7 -r 41357f8ff28a usr.bin/ftp/ftp.c
--- a/usr.bin/ftp/ftp.c Sat Oct 09 08:13:00 1999 +0000
+++ b/usr.bin/ftp/ftp.c Sat Oct 09 12:48:12 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.81 1999/10/09 03:00:56 lukem Exp $   */
+/*     $NetBSD: ftp.c,v 1.82 1999/10/09 12:48:12 lukem Exp $   */
 
 /*-
  * Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -103,7 +103,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c      8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.81 1999/10/09 03:00:56 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.82 1999/10/09 12:48:12 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1329,12 +1329,15 @@
                        /*
                         * abort using RFC 959 recommended IP,SYNC sequence
                         */
-       (void)xsignal(SIGINT, SIG_IGN);
-       if (!cpend) {
-               code = -1;
-               goto cleanuprecv;
+       if (! sigsetjmp(xferabort, 1)) {
+                       /* this is the first call */
+               (void)xsignal(SIGINT, abort_squared);
+               if (!cpend) {
+                       code = -1;
+                       goto cleanuprecv;
+               }
+               abort_remote(din);
        }
-       abort_remote(din);
        code = -1;
        if (bytes > 0)
                ptransfer(0);
@@ -1968,7 +1971,11 @@
        fprintf(ttyout, "local: %s remote: %s\n", local, remote);
        return;
 abort:
-       (void)xsignal(SIGINT, SIG_IGN);
+       if (sigsetjmp(xferabort, 1)) {
+               (void)xsignal(SIGINT, oldintr);
+               return;
+       }
+       (void)xsignal(SIGINT, abort_squared);
        ptflag = 0;
        if (strcmp(cmd, "RETR") && !proxy)
                pswitch(1);
@@ -2090,6 +2097,27 @@
        return (new);
 }
 
+/*
+ * abort_squared --
+ *     aborts abort_remote(). lostpeer() is called because if the user is
+ *     too impatient to wait or there's another problem then ftp really
+ *     needs to get back to a known state.
+ */
+void
+abort_squared(dummy)
+       int dummy;
+{
+       char msgbuf[100];
+       int len;
+
+       alarmtimer(0);
+       len = strlcpy(msgbuf, "\nremote abort aborted; closing connection.\n",
+           sizeof(msgbuf));
+       write(fileno(ttyout), msgbuf, len);
+       lostpeer();
+       siglongjmp(xferabort, 1);
+}
+
 void
 abort_remote(din)
        FILE *din;



Home | Main Index | Thread Index | Old Index