From: Eric Sunshine <sunshine@sunshineco.com>
To: Jeff King <peff@peff.net>
Cc: Git List <git@vger.kernel.org>,
Michael J Gruber <git@drmicha.warpmail.net>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 4/7] run-command: add pipe_command helper
Date: Fri, 17 Jun 2016 16:03:18 -0400 [thread overview]
Message-ID: <CAPig+cR-Z+dpKN0dG_BG7JWRBZeo4Xtpa1HQAU1Tt3WRunsrXg@mail.gmail.com> (raw)
In-Reply-To: <20160616093745.GD15851@sigill.intra.peff.net>
On Thu, Jun 16, 2016 at 5:37 AM, Jeff King <peff@peff.net> wrote:
> We already have capture_command(), which captures the stdout
> of a command in a way that avoids deadlocks. But sometimes
> we need to do more I/O, like capturing stderr as well, or
> sending data to stdin. It's easy to write code that
> deadlocks racily in these situations depending on how fast
> the command reads its input, or in which order it writes its
> output.
>
> Let's give callers an easy interface for doing this the
> right way, similar to what capture_command() did for the
> simple case.
>
> The whole thing is backed by a generic poll() loop that can
> feed an arbitrary number of buffers to descriptors, and fill
> an arbitrary number of strbufs from other descriptors. This
> seems like overkill, but the resulting code is actually a
> bit cleaner than just handling the three descriptors
> (because the output code for stdout/stderr is effectively
> duplicated, so being able to loop is a benefit).
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> diff --git a/run-command.h b/run-command.h
> @@ -79,17 +79,34 @@ int run_command_v_opt(const char **argv, int opt);
> /**
> - * 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
Did you mean s/returns/Returns/ ?
> + * 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; capture_command handles that automatically.
s/capture_command/pipe_command/
> + */
> +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);
> +
next prev parent reply other threads:[~2016-06-17 20:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 9:32 [PATCH 0/7] gpg-interface cleanups Jeff King
2016-06-16 9:33 ` [PATCH 1/7] gpg-interface: use child_process.args Jeff King
2016-06-16 9:34 ` [PATCH 2/7] verify_signed_buffer: drop pbuf variable Jeff King
2016-06-16 9:35 ` [PATCH 3/7] verify_signed_buffer: use tempfile object Jeff King
2016-06-16 9:37 ` [PATCH 4/7] run-command: add pipe_command helper Jeff King
2016-06-17 20:03 ` Eric Sunshine [this message]
2016-06-17 23:28 ` Jeff King
2016-06-17 23:31 ` Eric Sunshine
2016-06-16 9:38 ` [PATCH 5/7] verify_signed_buffer: use pipe_command Jeff King
2016-06-16 9:39 ` [PATCH 6/7] sign_buffer: " Jeff King
2016-06-16 9:42 ` [PATCH 7/7] gpg-interface: check gpg signature creation status Jeff King
2016-06-16 18:20 ` [PATCH 0/7] gpg-interface cleanups Junio C Hamano
2016-06-17 9:20 ` Michael J Gruber
2016-06-17 9:21 ` Jeff King
2016-06-17 23:38 ` [PATCH v2 " Jeff King
2016-06-17 23:38 ` [PATCH v2 1/7] gpg-interface: use child_process.args Jeff King
2016-06-17 23:38 ` [PATCH v2 2/7] verify_signed_buffer: drop pbuf variable Jeff King
2016-06-17 23:38 ` [PATCH v2 3/7] verify_signed_buffer: use tempfile object Jeff King
2016-06-17 23:38 ` [PATCH v2 4/7] run-command: add pipe_command helper Jeff King
2016-06-17 23:38 ` [PATCH v2 5/7] verify_signed_buffer: use pipe_command Jeff King
2016-06-17 23:38 ` [PATCH v2 6/7] sign_buffer: " Jeff King
2016-06-17 23:38 ` [PATCH v2 7/7] gpg-interface: check gpg signature creation status Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPig+cR-Z+dpKN0dG_BG7JWRBZeo4Xtpa1HQAU1Tt3WRunsrXg@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).