Change __archive_create_child() signature
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>
This commit is contained in:
1 parent
df072ed4ce
commit
4626d75d37
5 files changed
+23
-16
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user