This reverts commit c5d3d198dcbceac928f430e2a9450ca58d6c0890. --- src/command.c | 64 +++++++------------------------------------------- src/guestfs-internal.h | 3 --- 2 files changed, 9 insertions(+), 58 deletions(-) diff --git a/src/command.c b/src/command.c index a92012d..126cc49 100644 --- a/src/command.c +++ b/src/command.c @@ -409,7 +409,7 @@ debug_command (struct command *cmd) } static int -run_command (struct command *cmd, bool get_stdout_fd, bool get_stderr_fd) +run_command (struct command *cmd) { struct sigaction sa; int i, fd, max_fd, r; @@ -421,11 +421,8 @@ run_command (struct command *cmd, bool get_stdout_fd, bool get_stderr_fd) struct rlimit rlimit; #endif - get_stdout_fd = get_stdout_fd || cmd->stdout_callback != NULL; - get_stderr_fd = get_stderr_fd || cmd->capture_errors; - /* Set up a pipe to capture command output and send it to the error log. */ - if (get_stderr_fd) { + if (cmd->capture_errors) { if (pipe2 (errorfd, O_CLOEXEC) == -1) { perrorf (cmd->g, "pipe2"); goto error; @@ -433,7 +430,7 @@ run_command (struct command *cmd, bool get_stdout_fd, bool get_stderr_fd) } /* Set up a pipe to capture stdout for the callback. */ - if (get_stdout_fd) { + if (cmd->stdout_callback) { if (pipe2 (outfd, O_CLOEXEC) == -1) { perrorf (cmd->g, "pipe2"); goto error; @@ -448,14 +445,14 @@ run_command (struct command *cmd, bool get_stdout_fd, bool get_stderr_fd) /* In parent, return to caller. */ if (cmd->pid > 0) { - if (get_stderr_fd) { + if (cmd->capture_errors) { close (errorfd[1]); errorfd[1] = -1; cmd->errorfd = errorfd[0]; errorfd[0] = -1; } - if (get_stdout_fd) { + if (cmd->stdout_callback) { close (outfd[1]); outfd[1] = -1; cmd->outfd = outfd[0]; @@ -466,15 +463,15 @@ run_command (struct command *cmd, bool get_stdout_fd, bool get_stderr_fd) } /* Child process. */ - if (get_stderr_fd) { + if (cmd->capture_errors) { close (errorfd[0]); - if (!get_stdout_fd) + if (!cmd->stdout_callback) dup2 (errorfd[1], 1); dup2 (errorfd[1], 2); close (errorfd[1]); } - if (get_stdout_fd) { + if (cmd->stdout_callback) { close (outfd[0]); dup2 (outfd[1], 1); close (outfd[1]); @@ -693,7 +690,7 @@ guestfs_int_cmd_run (struct command *cmd) if (cmd->g->verbose) debug_command (cmd); - if (run_command (cmd, false, false) == -1) + if (run_command (cmd) == -1) return -1; if (loop (cmd) == -1) @@ -702,49 +699,6 @@ guestfs_int_cmd_run (struct command *cmd) return wait_command (cmd); } -/* Fork, run the command, and returns the pid of the command, - * and its stdout and stderr file descriptors. - * - * Returns the exit status. Test it using WIF* macros. - * - * On error: Calls error(g) and returns -1. - */ -int -guestfs_int_cmd_run_async (struct command *cmd, pid_t *pid, - int *stdout_fd, int *stderr_fd) -{ - finish_command (cmd); - - if (cmd->g->verbose) - debug_command (cmd); - - if (run_command (cmd, stdout_fd != NULL, stderr_fd != NULL) == -1) - return -1; - - if (pid) - *pid = cmd->pid; - if (stdout_fd) - *stdout_fd = cmd->outfd; - if (stderr_fd) - *stderr_fd = cmd->errorfd; - - return 0; -} - -/* Wait for the command to finish. - * - * The command MUST have been started with guestfs_int_cmd_run_async. - * - * Returns the exit status. Test it using WIF* macros. - * - * On error: Calls error(g) and returns -1. - */ -int -guestfs_int_cmd_wait (struct command *cmd) -{ - return wait_command (cmd); -} - void guestfs_int_cmd_close (struct command *cmd) { diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index 665dc93..22e8e06 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -20,7 +20,6 @@ #define GUESTFS_INTERNAL_H_ #include <stdbool.h> -#include <sys/types.h> #include <libintl.h> @@ -878,8 +877,6 @@ extern void guestfs_int_cmd_clear_capture_errors (struct command *); extern void guestfs_int_cmd_clear_close_files (struct command *); extern void guestfs_int_cmd_set_child_callback (struct command *, cmd_child_callback child_callback, void *data); extern int guestfs_int_cmd_run (struct command *); -extern int guestfs_int_cmd_run_async (struct command *, pid_t *pid, int *stdout_fd, int *stderr_fd); -extern int guestfs_int_cmd_wait (struct command *); extern void guestfs_int_cmd_close (struct command *); #ifdef HAVE_ATTRIBUTE_CLEANUP -- 2.5.0