diff options
| author | Junio C Hamano <gitster@pobox.com> | 2015-03-25 12:54:27 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2015-03-25 12:54:27 -0700 |
| commit | ea1fd481b4e689f143142662a82fb62c9b2efb65 (patch) | |
| tree | a9e2475bf714d67eafee037aa710023495cad21e /run-command.h | |
| parent | d78374e578a1837ee73c45f944c420c6f3f64deb (diff) | |
| parent | c29b3962af3df80a43fab4ead4875bd2ca275e4c (diff) | |
| download | git-ea1fd481b4e689f143142662a82fb62c9b2efb65.tar.xz | |
Merge branch 'jk/run-command-capture'
The run-command interface was easy to abuse and make a pipe for us
to read from the process, wait for the process to finish and then
attempt to read its output, which is a pattern that lead to a
deadlock. Fix such uses by introducing a helper to do this
correctly (i.e. we need to read first and then wait the process to
finish) and also add code to prevent such abuse in the run-command
helper.
* jk/run-command-capture:
run-command: forbid using run_command with piped output
trailer: use capture_command
submodule: use capture_command
wt-status: use capture_command
run-command: introduce capture_command helper
wt_status: fix signedness mismatch in strbuf_read call
wt-status: don't flush before running "submodule status"
Diffstat (limited to 'run-command.h')
| -rw-r--r-- | run-command.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/run-command.h b/run-command.h index d6868dc8c8..263b9662ad 100644 --- a/run-command.h +++ b/run-command.h @@ -71,6 +71,19 @@ 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. + * 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. + * + * 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. + */ +int capture_command(struct child_process *cmd, struct strbuf *buf, size_t hint); + /* * The purpose of the following functions is to feed a pipe by running * a function asynchronously and providing output that the caller reads. |
