Skip to content
  • Jeff King's avatar
    run-command: add pipe_command helper · 96335bcf
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    96335bcf