Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp * use sigsetjmp()/siglongjump() instead of setjm...



details:   https://anonhg.NetBSD.org/src/rev/8d3c4043e4e0
branches:  trunk
changeset: 477057:8d3c4043e4e0
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Oct 09 03:00:55 1999 +0000

description:
* use sigsetjmp()/siglongjump() instead of setjmp()/longjmp(); the latter
  don't save the signal mask on some foreign systems.
* ensure signal handlers don't use stdio and do reset errno if they
  don't exit with siglongjmp()
* use a common SIGINT handler for {send,recv}request()

diffstat:

 usr.bin/ftp/cmds.c   |  49 ++++++++++++++++-----------
 usr.bin/ftp/extern.h |  10 ++--
 usr.bin/ftp/fetch.c  |  17 +++++----
 usr.bin/ftp/ftp.c    |  91 +++++++++++++++++++++++++++------------------------
 usr.bin/ftp/main.c   |  22 +++++++-----
 usr.bin/ftp/util.c   |  27 ++++++--------
 6 files changed, 117 insertions(+), 99 deletions(-)

diffs (truncated from 667 to 300 lines):

diff -r d22b5eceb606 -r 8d3c4043e4e0 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Sat Oct 09 00:43:32 1999 +0000
+++ b/usr.bin/ftp/cmds.c        Sat Oct 09 03:00:55 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.71 1999/10/05 13:05:39 lukem Exp $  */
+/*     $NetBSD: cmds.c,v 1.72 1999/10/09 03:00:55 lukem Exp $  */
 
 /*-
  * Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -107,7 +107,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.71 1999/10/05 13:05:39 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.72 1999/10/09 03:00:55 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -385,8 +385,9 @@
        }
        mname = argv[0];
        mflag = 1;
-       oldintr = xsignal(SIGINT, mabort);
-       (void)setjmp(jabort);
+       oldintr = xsignal(SIGINT, mintr);
+       if (sigsetjmp(jabort, 1))
+               mabort();
        if (proxy) {
                char *cp;
 
@@ -415,9 +416,7 @@
                                }
                        }
                }
-               (void)xsignal(SIGINT, oldintr);
-               mflag = 0;
-               return;
+               goto cleanupmput;
        }
        for (i = 1; i < argc; i++) {
                char **cpp;
@@ -467,6 +466,7 @@
                }
                globfree(&gl);
        }
+cleanupmput:
        (void)xsignal(SIGINT, oldintr);
        mflag = 0;
 }
@@ -565,13 +565,20 @@
 
 /* ARGSUSED */
 void
-mabort(signo)
+mintr(signo)
        int signo;
 {
+
+       alarmtimer(0);
+       write(fileno(ttyout), "\n", 1);
+       siglongjmp(jabort, 1);
+}
+
+void
+mabort()
+{
        int ointer, oconf;
 
-       alarmtimer(0);
-       putc('\n', ttyout);
        if (mflag && fromatty) {
                ointer = interactive;
                oconf = confirmrest;
@@ -580,13 +587,12 @@
                if (confirm("Continue with", mname)) {
                        interactive = ointer;
                        confirmrest = oconf;
-                       longjmp(jabort, 0);
+                       return;
                }
                interactive = ointer;
                confirmrest = oconf;
        }
        mflag = 0;
-       longjmp(jabort, 0);
 }
 
 /*
@@ -608,8 +614,9 @@
        }
        mname = argv[0];
        mflag = 1;
-       oldintr = xsignal(SIGINT, mabort);
-       (void)setjmp(jabort);
+       oldintr = xsignal(SIGINT, mintr);
+       if (sigsetjmp(jabort, 1))
+               mabort();
        while ((cp = remglob(argv, proxy, NULL)) != NULL) {
                if (*cp == '\0') {
                        mflag = 0;
@@ -1112,8 +1119,9 @@
        }
        mname = argv[0];
        mflag = 1;
-       oldintr = xsignal(SIGINT, mabort);
-       (void)setjmp(jabort);
+       oldintr = xsignal(SIGINT, mintr);
+       if (sigsetjmp(jabort, 1))
+               mabort();
        while ((cp = remglob(argv, 0, NULL)) != NULL) {
                if (*cp == '\0') {
                        mflag = 0;
@@ -1256,8 +1264,9 @@
        dolist = strcmp(argv[0], "mls");
        mname = argv[0];
        mflag = 1;
-       oldintr = xsignal(SIGINT, mabort);
-       (void)setjmp(jabort);
+       oldintr = xsignal(SIGINT, mintr);
+       if (sigsetjmp(jabort, 1))
+               mabort();
        for (i = 1; mflag && i < argc-1; ++i) {
                *mode = (i == 1) ? 'w' : 'a';
                recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
@@ -1667,7 +1676,7 @@
                proxflag = 0;
        }
        pswitch(0);
-       longjmp(abortprox, 1);
+       siglongjmp(abortprox, 1);
 }
 
 void
@@ -1700,7 +1709,7 @@
                code = -1;
                return;
        }
-       if (setjmp(abortprox)) {
+       if (sigsetjmp(abortprox, 1)) {
                code = -1;
                return;
        }
diff -r d22b5eceb606 -r 8d3c4043e4e0 usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h      Sat Oct 09 00:43:32 1999 +0000
+++ b/usr.bin/ftp/extern.h      Sat Oct 09 03:00:55 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.43 1999/10/05 01:16:12 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.44 1999/10/09 03:00:55 lukem Exp $        */
 
 /*-
  * Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -105,8 +105,7 @@
 
 void   abort_remote __P((FILE *));
 void   abortpt __P((int));
-void   abortrecv __P((int));
-void   abortsend __P((int));
+void   abortxfer __P((int));
 void   account __P((int, char **));
 void   alarmtimer __P((int));
 int    another __P((int *, char ***, const char *));
@@ -148,7 +147,7 @@
 char   *hookup __P((char *, char *));
 void   idlecmd __P((int, char **));
 int    initconn __P((void));
-void   intr __P((void));
+void   intr __P((int));
 int    isipv6addr __P((const char *));
 void   list_vertical __P((StringList *));
 void   lcd __P((int, char **));
@@ -156,12 +155,13 @@
 void   lpage __P((int, char **));
 void   lpwd __P((int, char **));
 void   ls __P((int, char **));
-void   mabort __P((int));
+void   mabort __P((void));
 void   macdef __P((int, char **));
 void   makeargv __P((void));
 void   makedir __P((int, char **));
 void   mdelete __P((int, char **));
 void   mget __P((int, char **));
+void   mintr __P((int));
 void   mls __P((int, char **));
 void   modtime __P((int, char **));
 void   mput __P((int, char **));
diff -r d22b5eceb606 -r 8d3c4043e4e0 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Sat Oct 09 00:43:32 1999 +0000
+++ b/usr.bin/ftp/fetch.c       Sat Oct 09 03:00:55 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.87 1999/10/06 08:57:46 lukem Exp $ */
+/*     $NetBSD: fetch.c,v 1.88 1999/10/09 03:00:55 lukem Exp $ */
 
 /*-
  * Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.87 1999/10/06 08:57:46 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.88 1999/10/09 03:00:55 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -1040,7 +1040,7 @@
        }
 
                        /* Trap signals */
-       if (setjmp(httpabort))
+       if (sigsetjmp(httpabort, 1))
                goto cleanup_fetch_url;
        (void)xsignal(SIGQUIT, psummary);
        oldintr = xsignal(SIGINT, aborthttp);
@@ -1213,10 +1213,13 @@
 aborthttp(notused)
        int notused;
 {
+       char msgbuf[100];
+       int len;
 
        alarmtimer(0);
-       fputs("\nHTTP fetch aborted.\n", ttyout);
-       longjmp(httpabort, 1);
+       len = strlcpy(msgbuf, "\nHTTP fetch aborted.\n", sizeof(msgbuf));
+       write(fileno(ttyout), msgbuf, len);
+       siglongjmp(httpabort, 1);
 }
 
 /*
@@ -1619,12 +1622,12 @@
 
        argpos = 0;
 
-       if (setjmp(toplevel)) {
+       if (sigsetjmp(toplevel, 1)) {
                if (connected)
                        disconnect(0, NULL);
                return (argpos + 1);
        }
-       (void)xsignal(SIGINT, (sig_t)intr);
+       (void)xsignal(SIGINT, intr);
        (void)xsignal(SIGPIPE, (sig_t)lostpeer);
 
        /*
diff -r d22b5eceb606 -r 8d3c4043e4e0 usr.bin/ftp/ftp.c
--- a/usr.bin/ftp/ftp.c Sat Oct 09 00:43:32 1999 +0000
+++ b/usr.bin/ftp/ftp.c Sat Oct 09 03:00:55 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.80 1999/10/05 22:04:30 lukem Exp $   */
+/*     $NetBSD: ftp.c,v 1.81 1999/10/09 03:00:56 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.80 1999/10/05 22:04:30 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.81 1999/10/09 03:00:56 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -388,25 +388,28 @@
 cmdabort(notused)
        int notused;
 {
+       int oerrno = errno;
 
        alarmtimer(0);
-       putc('\n', ttyout);
+       write(fileno(ttyout), "\n", 1);
        abrtflag++;
        if (ptflag)
-               longjmp(ptabort, 1);
+               siglongjmp(ptabort, 1);
+       errno = oerrno;
 }
 
 void
 cmdtimeout(notused)
        int notused;
 {
+       int oerrno = errno;
 
        alarmtimer(0);
-       putc('\n', ttyout);
-       (void)fflush(ttyout);
+       write(fileno(ttyout), "\n", 1);
        timeoutflag++;
        if (ptflag)
-               longjmp(ptabort, 1);
+               siglongjmp(ptabort, 1);
+       errno = oerrno;
 }
 
 
@@ -682,18 +685,33 @@
        return nr;
 }
 
-jmp_buf        sendabort;



Home | Main Index | Thread Index | Old Index