Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.sbin/pkg_install/lib Pull up rev. 1.24 to netbsd-1-...



details:   https://anonhg.NetBSD.org/src/rev/0f2d67152575
branches:  netbsd-1-5
changeset: 489353:0f2d67152575
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Sun Sep 03 04:18:42 2000 +0000

description:
Pull up rev. 1.24 to netbsd-1-5 branch, OK'd by thorpej:

 > When downloading and extracting a file (in ftp:
 > 'get pkg.tgz "| cd /var/tmp/inst ; gunzip | tar -x -f -"'), handle
 > two cases better:
 >
 > 1. Timing out ftp connections: Make sure the hanging pipeline gets a ^C
 >    (SIGINT), and wait until the ftp prompt is available again. Else we
 >    may nuke away tar's working dir, and it may be displeased.
 > 2. One of the commands from the pipeline exiting: caught via SIGCHLD;
 >    for this signal to be delivered, a empty handler is needed)
 >
 > Adresses PR 10925 by Greg A. Woods <woods%planix.com@localhost>

diffstat:

 usr.sbin/pkg_install/lib/ftpio.c |  41 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 6 deletions(-)

diffs (107 lines):

diff -r 83c877c20c50 -r 0f2d67152575 usr.sbin/pkg_install/lib/ftpio.c
--- a/usr.sbin/pkg_install/lib/ftpio.c  Sun Sep 03 04:17:49 2000 +0000
+++ b/usr.sbin/pkg_install/lib/ftpio.c  Sun Sep 03 04:18:42 2000 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: ftpio.c,v 1.20.2.3 2000/08/29 04:13:15 hubertf Exp $   */
+/*     $NetBSD: ftpio.c,v 1.20.2.4 2000/09/03 04:18:42 hubertf Exp $   */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ftpio.c,v 1.20.2.3 2000/08/29 04:13:15 hubertf Exp $");
+__RCSID("$NetBSD: ftpio.c,v 1.20.2.4 2000/09/03 04:18:42 hubertf Exp $");
 #endif
 
 /*
@@ -37,7 +37,7 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
-#include <sys/signal.h>
+#include <signal.h>
 #include <assert.h>
 #include <ctype.h>
 #include <err.h>
@@ -80,7 +80,7 @@
 static int      needclose=0;
 static int      ftp_started=0;
 static fds      ftpio;
-
+static int      ftp_pid;
 
 /*
  * expect "str" (a regular expression) on file descriptor "fd", storing
@@ -122,7 +122,7 @@
 
     memset(buf, '\n', sizeof(buf));
 
-    timeout.tv_sec=10*60;      /* seconds until next message from tar */
+    timeout.tv_sec=10*60;    /* seconds until next message from tar */
     timeout.tv_usec=0;
     done=0;
     retval=0;
@@ -140,6 +140,22 @@
            break;
        case 0:
            warnx("expect: select() timeout");
+           /* need to send ftp coprocess SIGINT to make it stop
+            * downloading into dir that we'll blow away in a second */
+           kill(ftp_pid, SIGINT);
+
+           /* Wait until ftp coprocess is responsive again 
+            * XXX Entering recursion here!
+            */
+           rc = ftp_cmd("cd .\n", "\n(550|250).*\n");
+           if (rc != 250) {
+                   /* now we have a really good reason to bail out ;) */
+           }
+           /* ftp is at command prompt again, and will wait for our
+            * next command. If we were downloading, we can now safely
+            * continue and remove the dir that the tar command was
+            * expanding to */
+                   
            done = 1;   /* hope that's ok */
            retval = -1;
            break;
@@ -241,7 +257,7 @@
        return -1;
     }
 
-    rc1=fork();
+    rc1 = fork();
     switch (rc1) {
     case -1:
            /* Error */
@@ -281,6 +297,7 @@
            
            ftpio.command = command_pipe[1];
            ftpio.answer  = answer_pipe[0];
+           ftp_pid = rc1;                      /* to ^C transfers */
            
            fcntl(ftpio.command, F_SETFL, O_NONBLOCK);
            fcntl(ftpio.answer , F_SETFL, O_NONBLOCK);
@@ -293,6 +310,17 @@
 
 
 /*
+ * Dummy signal handler to detect if the ftp(1) coprocess or
+ * and of the processes of the tar/gzip pipeline dies. 
+ */
+static void
+sigchld_handler (int n)
+{
+       /* Make select(2) return EINTR */
+}
+
+
+/*
  * SIGPIPE only happens when there's something wrong with the FTP
  * coprocess. In that case, set mark to not try to close shut down
  * the coprocess.
@@ -397,6 +425,7 @@
                
                needclose=1;
                signal(SIGPIPE, sigpipe_handler);
+               signal(SIGCHLD, sigchld_handler);
 
                if ((expect(ftpio.answer, "\n(221|250|221|550).*\n", &rc) != 0)
                    || rc != 250) {



Home | Main Index | Thread Index | Old Index