Check the unzip child process for errors and pass the upwards. Also, avoid child...
[oweals/opkg-lede.git] / libbb / unzip.c
index 186da594a45c8fff04bb3748fbd769cf391615a1..7ff07a515364745fecd233dc6cc14474b2d16841 100644 (file)
@@ -46,6 +46,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 #include "libbb.h"
 
 static FILE *in_file, *out_file;
@@ -149,6 +150,14 @@ static void flush_window(void)
        }
 
        if (fwrite(window, 1, outcnt, out_file) != outcnt) {
+               /*
+                * The Parent process may not be interested in all the data we have,
+                * in which case it will rudely close its end of the pipe and
+                * wait for us to exit.
+                */
+               if (errno == EPIPE)
+                       _exit(EXIT_SUCCESS);
+
                error_msg("Couldnt write");
                _exit(EXIT_FAILURE);
        }
@@ -917,6 +926,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
        }
 #endif
 
+       signal(SIGPIPE, SIG_IGN);
+
        /* Allocate all global buffers (for DYN_ALLOC option) */
        window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(unsigned char)));
        outcnt = 0;