#include <unistd.h>
#include "libbb.h"
-extern FILE *gz_open(FILE *compressed_file, int *pid)
+FILE *
+gz_open(FILE *compressed_file, int *pid)
{
int unzip_pipe[2];
return(fdopen(unzip_pipe[0], "r"));
}
-extern void gz_close(int gunzip_pid)
+int
+gz_close(int gunzip_pid)
{
- if (waitpid(gunzip_pid, NULL, 0) == -1) {
- perror_msg("%s wait", __FUNCTION__);
+ int status;
+ int ret;
+
+ if (waitpid(gunzip_pid, &status, 0) == -1) {
+ perror_msg("%s: waitpid", __FUNCTION__);
+ return -1;
+ }
+
+ if (WIFSIGNALED(status)) {
+ error_msg("%s: unzip process killed by signal %d\n",
+ __FUNCTION__, WTERMSIG(status));
+ return -1;
+ }
+
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ error_msg("%s: Your system is broken: got status %d from waitpid\n",
+ __FUNCTION__, status);
+ return -1;
}
+
+ if ((ret = WEXITSTATUS(status))) {
+ error_msg("%s: unzip process failed with return code %d.\n",
+ __FUNCTION__, ret);
+ return -1;
+ }
+
+ return 0;
}
const char *filename, int *err);
extern int unzip(FILE *l_in_file, FILE *l_out_file);
-extern void gz_close(int gunzip_pid);
+extern int gz_close(int gunzip_pid);
extern FILE *gz_open(FILE *compressed_file, int *pid);
int make_directory (const char *path, long mode, int flags);
char *output_buffer = NULL;
char *ared_file = NULL;
char ar_magic[8];
+ int gz_err;
*err = 0;
extract_function, prefix,
file_list, err);
fclose(uncompressed_stream);
- gz_close(gunzip_pid);
+ gz_err = gz_close(gunzip_pid);
+ if (gz_err)
+ *err = -1;
free_header_ar(ar_header);
break;
}
free_header_tar(tar_header);
fclose(uncompressed_stream);
- gz_close(gunzip_pid);
+ gz_err = gz_close(gunzip_pid);
+ if (gz_err)
+ *err = -1;
free_header_tar(tar_header);
break;
}
free_header_tar(tar_header);
}
fclose(unzipped_opkg_stream);
- gz_close(unzipped_opkg_pid);
+ gz_err = gz_close(unzipped_opkg_pid);
+ if (gz_err)
+ *err = -1;
goto cleanup;
} else {
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include "libbb.h"
static FILE *in_file, *out_file;
}
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);
}
}
#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;