git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] fetch: avoid calling write_or_die()

From
Duy Nguyen <pclouds@gmail.com>
Date
Mar 4, 2019, 13:42 UTC
Message-ID
<CACsJy8BWp9+SDwcXv_a6aFN=YSoQN3E7sOGDRm5a6Pi7QhzexQ@mail.gmail.com>
In-Reply-To
<20190303165537.GA23755@sigill.intra.peff.net>
On Sun, Mar 3, 2019 at 11:55 PM Jeff King <peff@peff.net> wrote:
Show 35 quoted lines
>
> The write_or_die() function has one quirk that a caller might not
> expect: when it sees EPIPE from the write() call, it translates that
> into a death by SIGPIPE. This doesn't change the overall behavior (the
> program exits either way), but it does potentially confuse test scripts
> looking for a non-signal exit code.
>
> Let's switch away from using write_or_die() in a few code paths, which
> will give us more consistent exit codes. It also gives us the
> opportunity to write more descriptive error messages, since we have
> context that write_or_die() does not.
>
> Note that this won't do much by itself, since we'd typically be killed
> by SIGPIPE before write_or_die() even gets a chance to do its thing.
> That will be addressed in the next patch.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  fetch-pack.c | 9 ++++++---
>  pkt-line.c   | 6 ++++--
>  2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 812be15d7e..dca249e9d7 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -191,8 +191,10 @@ static void send_request(struct fetch_pack_args *args,
>         if (args->stateless_rpc) {
>                 send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);
>                 packet_flush(fd);
> -       } else
> -               write_or_die(fd, buf->buf, buf->len);
> +       } else {
> +               if (write_in_full(fd, buf->buf, buf->len) < 0)
> +                       die_errno("unable to write to remote");
maybe _() these strings.
Show 39 quoted lines
> +       }
>  }
>
>  static void insert_one_alternate_object(struct fetch_negotiator *negotiator,
> @@ -1163,7 +1165,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
>
>         /* Send request */
>         packet_buf_flush(&req_buf);
> -       write_or_die(fd_out, req_buf.buf, req_buf.len);
> +       if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
> +               die_errno("unable to write request to remote");
>
>         strbuf_release(&req_buf);
>         return ret;
> diff --git a/pkt-line.c b/pkt-line.c
> index d4b71d3e82..093b2f3976 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -88,13 +88,15 @@ static void packet_trace(const char *buf, unsigned int len, int write)
>  void packet_flush(int fd)
>  {
>         packet_trace("0000", 4, 1);
> -       write_or_die(fd, "0000", 4);
> +       if (write_in_full(fd, "0000", 4) < 0)
> +               die_errno("unable to write flush packet");
>  }
>
>  void packet_delim(int fd)
>  {
>         packet_trace("0001", 4, 1);
> -       write_or_die(fd, "0001", 4);
> +       if (write_in_full(fd, "0001", 4) < 0)
> +               die_errno("unable to write delim packet");
>  }
>
>  int packet_flush_gently(int fd)
> --
> 2.21.0.675.g01c085a870
>
-- 
Duy
Previous: Jeff KingNext: Jeff King
Message 15 of 21 in “t5570-git-daemon fails with SIGPIPE on OSX”
  1. SZEDER GáborAug 6, 2018
  2. SZEDER GáborAug 6, 2018
  3. Johannes SchindelinFeb 8, 2019
  4. SZEDER GáborFeb 8, 2019
  5. Jeff KingAug 14, 2018
  6. Jeff KingAug 14, 2018
  7. Johannes SchindelinFeb 8, 2019
  8. Johannes SchindelinFeb 8, 2019
  9. Jeff KingFeb 8, 2019
  10. Johannes SchindelinMar 1, 2019
  11. Jeff KingMar 1, 2019
  12. Johannes SchindelinMar 2, 2019
  13. Jeff KingMar 3, 2019
  14. 1/2 fetch: avoid calling write_or_die()Jeff King, Mar 3, 2019
  15. Duy NguyenMar 4, 2019
  16. Jeff KingMar 5, 2019
  17. 2/2 fetch: ignore SIGPIPE during network operationJeff King, Mar 3, 2019
  18. Junio C HamanoMar 4, 2019
  19. Jeff KingMar 5, 2019
  20. Junio C HamanoMar 3, 2019
  21. Johannes SchindelinMar 3, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.