Cleanup gz_close().
[oweals/opkg-lede.git] / libbb / gz_open.c
index dbaf3bb023bceebd90694a4b7282fea0241a9692..0ed14173a5c389bea2d658997e9aa7d82beab38f 100644 (file)
@@ -34,11 +34,11 @@ extern FILE *gz_open(FILE *compressed_file, int *pid)
        int unzip_pipe[2];
 
        if (pipe(unzip_pipe)!=0) {
-               error_msg("pipe error");
+               perror_msg("%s: pipe: ", __FUNCTION__);
                return(NULL);
        }
        if ((*pid = fork()) == -1) {
-               error_msg("fork failed");
+               perror_msg("%s: fork: ", __FUNCTION__);
                return(NULL);
        }
        if (*pid==0) {
@@ -51,8 +51,16 @@ extern FILE *gz_open(FILE *compressed_file, int *pid)
                exit(EXIT_SUCCESS);
        }
        close(unzip_pipe[1]);
-       if (unzip_pipe[0] == -1) {
-               error_msg("gzip stream init failed");
-       }
        return(fdopen(unzip_pipe[0], "r"));
 }
+
+extern void gz_close(int gunzip_pid)
+{
+       if (kill(gunzip_pid, SIGTERM) == -1) {
+               perror_msg_and_die("%s: kill(gunzip_pid): ", __FUNCTION__);
+       }
+
+       if (waitpid(gunzip_pid, NULL, 0) == -1) {
+               perror_msg("%s wait: ", __FUNCTION__);
+       }
+}