Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/pkg_install/lib Add more error checking, and tell t...



details:   https://anonhg.NetBSD.org/src/rev/472166357fa1
branches:  trunk
changeset: 526010:472166357fa1
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Tue Apr 23 10:14:59 2002 +0000

description:
Add more error checking, and tell the user what's up when he runs
into descriptor-shortage. Can be caused when installing deeply-nested
binary pkgs like kde.

diffstat:

 usr.sbin/pkg_install/lib/ftpio.c |  28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diffs (63 lines):

diff -r 103735a01cc1 -r 472166357fa1 usr.sbin/pkg_install/lib/ftpio.c
--- a/usr.sbin/pkg_install/lib/ftpio.c  Tue Apr 23 10:11:39 2002 +0000
+++ b/usr.sbin/pkg_install/lib/ftpio.c  Tue Apr 23 10:14:59 2002 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: ftpio.c,v 1.34 2001/12/30 04:46:21 hubertf Exp $       */
+/*     $NetBSD: ftpio.c,v 1.35 2002/04/23 10:14:59 hubertf Exp $       */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ftpio.c,v 1.34 2001/12/30 04:46:21 hubertf Exp $");
+__RCSID("$NetBSD: ftpio.c,v 1.35 2002/04/23 10:14:59 hubertf Exp $");
 #endif
 
 /*
@@ -261,6 +261,12 @@
        return -1;
     }
 
+    if (command_pipe[0] == -1 || command_pipe[1] == -1 ||
+       answer_pipe[0] == -1  || answer_pipe[1] == -1 ) {
+       warn("setupCoproc: pipe() returned bogus descriptor");
+       return -1;
+    }
+
     rc1 = fork();
     switch (rc1) {
     case -1:
@@ -274,11 +280,17 @@
            /* Child */
            
            (void) close(command_pipe[1]);
-           dup2(command_pipe[0], 0);
+           rc1 = dup2(command_pipe[0], 0);
+            if (rc1 == -1) {
+                    err(1, "setupCoproc: dup2 failed (command_pipe[0])");
+            }
            (void) close(command_pipe[0]);
            
            (void) close(answer_pipe[0]);
-           dup2(answer_pipe[1], 1);
+           rc1 = dup2(answer_pipe[1], 1);
+            if (rc1 == -1) {
+                    err(1, "setupCoproc: dup2 failed (answer_pipe[1])");
+            }
            (void) close(answer_pipe[1]);
            
            setbuf(stdout, NULL);
@@ -456,7 +468,15 @@
                /* get FDs of our coprocess */
                
                ftpio.command = dup(atoi(tmp1));
+               if (ftpio.command == -1 ) {
+                       warnx("command dup() failed, increase 'descriptors' limit");
+                       return -1;
+               }
                ftpio.answer  = dup(atoi(tmp2));
+               if (ftpio.answer == -1 ) {
+                       warnx("answer dup() failed, increase 'descriptors' limit");
+                       return -1;
+               }
                
                if (Verbose)
                        printf("Reusing FDs %s/%s for communication to FTP coprocess\n", tmp1, tmp2);



Home | Main Index | Thread Index | Old Index