]> git.ipfire.org Git - thirdparty/git.git/commit - run-command.h
run-command: add pipe_command helper
authorJeff King <peff@peff.net>
Fri, 17 Jun 2016 23:38:47 +0000 (19:38 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 18 Jun 2016 00:03:56 +0000 (17:03 -0700)
commit96335bcf4d64c29add3692fb41671190123cf44e
tree079533fb3d349577395d95f0047e13a73f9b70a4
parent4322353bfb53a83e6657af50603d3521ee9d7d0c
run-command: add pipe_command helper

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c
run-command.h