diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-07-06 13:38:12 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-06 13:38:12 -0700 |
commit | ed0f7bdec93478e280c9faa2a8ffb13a183cda09 (patch) | |
tree | 9cf0d27c9613aacbb38339d009c0e961840d79b1 /run-command.h | |
parent | 1d77bed8b02d902f11310f578debe933b90791f6 (diff) | |
parent | efee9553a4f97b2ecd8f49be19606dd4cf7d9c28 (diff) | |
download | git-ed0f7bdec93478e280c9faa2a8ffb13a183cda09.tar.gz |
Merge branch 'jk/gpg-interface-cleanup'
A new run-command API function pipe_command() is introduced to
sanely feed data to the standard input while capturing data from
the standard output and the standard error of an external process,
which is cumbersome to hand-roll correctly without deadlocking.
The codepath to sign data in a prepared buffer with GPG has been
updated to use this API to read from the status-fd to check for
errors (instead of relying on GPG's exit status).
* jk/gpg-interface-cleanup:
gpg-interface: check gpg signature creation status
sign_buffer: use pipe_command
verify_signed_buffer: use pipe_command
run-command: add pipe_command helper
verify_signed_buffer: use tempfile object
verify_signed_buffer: drop pbuf variable
gpg-interface: use child_process.args
Diffstat (limited to 'run-command.h')
-rw-r--r-- | run-command.h | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/run-command.h b/run-command.h index 11f76b04ed..50666497ae 100644 --- a/run-command.h +++ b/run-command.h @@ -79,17 +79,34 @@ int run_command_v_opt(const char **argv, int opt); int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env); /** - * Execute the given command, capturing its stdout in the given strbuf. + * Execute the given command, sending "in" to its stdin, and capturing its + * stdout and stderr in the "out" and "err" strbufs. Any of the three may + * be NULL to skip processing. + * * Returns -1 if starting the command fails or reading fails, and otherwise - * returns the exit code of the command. The output collected in the - * buffer is kept even if the command returns a non-zero exit. The hint field - * gives a starting size for the strbuf allocation. + * returns the exit code of the command. Any output collected in the + * buffers is kept even if the command returns a non-zero exit. The hint fields + * gives starting sizes for the strbuf allocations. * * The fields of "cmd" should be set up as they would for a normal run_command - * invocation. But note that there is no need to set cmd->out; the function - * sets it up for the caller. + * invocation. But note that there is no need to set the in, out, or err + * fields; pipe_command handles that automatically. + */ +int pipe_command(struct child_process *cmd, + const char *in, size_t in_len, + struct strbuf *out, size_t out_hint, + struct strbuf *err, size_t err_hint); + +/** + * Convenience wrapper around pipe_command for the common case + * of capturing only stdout. */ -int capture_command(struct child_process *cmd, struct strbuf *buf, size_t hint); +static inline int capture_command(struct child_process *cmd, + struct strbuf *out, + size_t hint) +{ + return pipe_command(cmd, NULL, 0, out, hint, NULL, 0); +} /* * The purpose of the following functions is to feed a pipe by running |