]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Change __archive_create_child() signature
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 25 Apr 2020 12:56:12 +0000 (13:56 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Sat, 25 Apr 2020 19:11:59 +0000 (20:11 +0100)
Change the function to return an int - ARCHIVE_OK or ARCHIVE_FAILED,
taking the child as an output argument.

This will allow us to simplify the existing code and have move platform
specifics in the platform files - posix and windows

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
libarchive/archive_read_support_filter_program.c
libarchive/archive_write_add_filter_program.c
libarchive/filter_fork.h
libarchive/filter_fork_posix.c
libarchive/filter_fork_windows.c

index b8bf12886f34e140765f3c7fd6145dca096c11b6..29c8a489a211295314a40fef6da85c3d147611f3 100644 (file)
@@ -401,6 +401,7 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd)
        char *out_buf;
        const char *prefix = "Program: ";
        pid_t child;
+       int ret;
        size_t l;
 
        l = strlen(prefix) + strlen(cmd) + 1;
@@ -426,9 +427,9 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd)
        state->out_buf = out_buf;
        state->out_buf_len = out_buf_len;
 
-       child = __archive_create_child(cmd, &state->child_stdin,
-           &state->child_stdout);
-       if (child == -1) {
+       ret = __archive_create_child(cmd, &state->child_stdin,
+           &state->child_stdout, &child);
+       if (ret != ARCHIVE_OK) {
                free(state->out_buf);
                archive_string_free(&state->description);
                free(state);
index a4bc1d90eda8a81ab9979f2029b47dfe1ce2c415..f64ae4a20b40deed0f16d59fe60db51a8f7efd53 100644 (file)
@@ -212,6 +212,7 @@ __archive_write_program_open(struct archive_write_filter *f,
     struct archive_write_program_data *data, const char *cmd)
 {
        pid_t child;
+       int ret;
 
        if (data->child_buf == NULL) {
                data->child_buf_len = 65536;
@@ -225,9 +226,9 @@ __archive_write_program_open(struct archive_write_filter *f,
                }
        }
 
-       child = __archive_create_child(cmd, &data->child_stdin,
-                   &data->child_stdout);
-       if (child == -1) {
+       ret = __archive_create_child(cmd, &data->child_stdin,
+                   &data->child_stdout, &child);
+       if (ret != ARCHIVE_OK) {
                archive_set_error(f->archive, EINVAL,
                    "Can't launch external program: %s", cmd);
                return (ARCHIVE_FATAL);
index 908e7cdd4ddda83085fb59cb68f251697873d108..be1bc7e8e320dcecfebd3a62fed63152112face1 100644 (file)
@@ -32,8 +32,9 @@
 #error This header is only to be used internally to libarchive.
 #endif
 
-pid_t
-__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout);
+int
+__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
+       pid_t *out_child);
 
 void
 __archive_check_child(int in, int out);
index 02dbd4bb436288550524a8f24322b1511ae82a75..ac255c4f8b202fbcefcd0d90884a1ad325f01ec3 100644 (file)
@@ -72,8 +72,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00
 
 #include "filter_fork.h"
 
-pid_t
-__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout)
+int
+__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
+               pid_t *out_child)
 {
        pid_t child;
        int stdin_pipe[2], stdout_pipe[2], tmp;
@@ -177,7 +178,8 @@ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout)
        fcntl(*child_stdout, F_SETFL, O_NONBLOCK);
        __archive_cmdline_free(cmdline);
 
-       return child;
+       *out_child = child;
+       return ARCHIVE_OK;
 
 #if HAVE_POSIX_SPAWNP
 actions_inited:
@@ -192,7 +194,7 @@ stdin_opened:
        close(stdin_pipe[1]);
 state_allocated:
        __archive_cmdline_free(cmdline);
-       return -1;
+       return ARCHIVE_FAILED;
 }
 
 void
index ad271fe68a1536a5f97ff743ea7b753f117f9972..7db1a0018b9aebe8b20ea0b218c3858771eae447 100644 (file)
@@ -31,8 +31,9 @@
 
 #include "filter_fork.h"
 
-pid_t
-__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout)
+int
+__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
+               pid_t *out_child)
 {
        HANDLE childStdout[2], childStdin[2],childStderr;
        SECURITY_ATTRIBUTES secAtts;
@@ -160,7 +161,8 @@ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout)
        archive_string_free(&cmdline);
        archive_string_free(&fullpath);
        __archive_cmdline_free(acmd);
-       return (childInfo.dwProcessId);
+       *out_child = childInfo.dwProcessId;
+       return ARCHIVE_OK;
 
 fail:
        if (childStdout[0] != INVALID_HANDLE_VALUE)
@@ -176,7 +178,7 @@ fail:
        archive_string_free(&cmdline);
        archive_string_free(&fullpath);
        __archive_cmdline_free(acmd);
-       return (-1);
+       return ARCHIVE_FAILED;
 }
 
 void