]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Unify reader and writer filter process handling
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Jun 2025 21:28:26 +0000 (23:28 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Jun 2025 21:28:26 +0000 (23:28 +0200)
Use pid_t since waitpid returns a pid_t. Also check for a negative
return value in writer as well to avoid reading the possibly
unitialized status value.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_read_support_filter_program.c
libarchive/archive_write_add_filter_program.c

index 55c617c9cb5a432195171e92e88daba2c7bb9de1..2c8e45302d8eb25d9c37d284e8ffac587ee76c64 100644 (file)
@@ -110,7 +110,7 @@ struct program_filter {
        pid_t            child;
 #endif
        int              exit_status;
-       int              waitpid_return;
+       pid_t            waitpid_return;
        int              child_stdin, child_stdout;
 
        char            *out_buf;
@@ -248,7 +248,7 @@ child_stop(struct archive_read_filter *self, struct program_filter *state)
        if (state->waitpid_return < 0) {
                /* waitpid() failed?  This is ugly. */
                archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
-                   "Child process exited badly");
+                   "Error closing child process");
                return (ARCHIVE_WARN);
        }
 
index 66ace04cfb15a7bb53332fbe7a7e5f8945156ed8..f12db33738833d1b85de1e45ac41702e553719e7 100644 (file)
@@ -330,6 +330,7 @@ __archive_write_program_close(struct archive_write_filter *f,
     struct archive_write_program_data *data)
 {
        int ret, status;
+       pid_t pid;
        ssize_t bytes_read;
 
        if (data->child == 0)
@@ -373,11 +374,12 @@ cleanup:
                close(data->child_stdin);
        if (data->child_stdout != -1)
                close(data->child_stdout);
-       while (waitpid(data->child, &status, 0) == -1 && errno == EINTR)
-               continue;
+       do {
+               pid = waitpid(data->child, &status, 0);
+       } while (pid == -1 && errno == EINTR);
        data->child = 0;
 
-       if (status != 0) {
+       if (pid < 0 || status != 0) {
                archive_set_error(f->archive, EIO,
                    "Error closing program: %s", data->program_name);
                ret = ARCHIVE_FATAL;