http-backend: cleanup writing to child process
authorMax Kirillov <max@max630.net>
Sun, 10 Jun 2018 15:05:19 +0000 (18:05 +0300)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Jun 2018 20:21:36 +0000 (13:21 -0700)
As explained in [1], we should not assume the reason why the writing has
failed, and even if the reason is that child has existed not the reason
why it have done so. So instead just say that writing has failed.

[1] https://public-inbox.org/git/20180604044408.GD14451@sigill.intra.peff.net/

Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http-backend.c
index adaef16fadfd03f34b8ac5bb496bd51aab292b20..cefdfd6fc601465be4ce0b190f8f2821ce1a8d41 100644 (file)
@@ -279,6 +279,12 @@ static struct rpc_service *select_service(struct strbuf *hdr, const char *name)
        return svc;
 }
 
+static void write_to_child(int out, const unsigned char *buf, ssize_t len, const char *prog_name)
+{
+       if (write_in_full(out, buf, len) < 0)
+               die("unable to write to '%s'", prog_name);
+}
+
 /*
  * This is basically strbuf_read(), except that if we
  * hit max_request_buffer we die (we'd rather reject a
@@ -361,9 +367,8 @@ static void inflate_request(const char *prog_name, int out, int buffer_input)
                                die("zlib error inflating request, result %d", ret);
 
                        n = stream.total_out - cnt;
-                       if (write_in_full(out, out_buf, n) < 0)
-                               die("%s aborted reading request", prog_name);
-                       cnt += n;
+                       write_to_child(out, out_buf, stream.total_out - cnt, prog_name);
+                       cnt = stream.total_out;
 
                        if (ret == Z_STREAM_END)
                                goto done;
@@ -382,8 +387,7 @@ static void copy_request(const char *prog_name, int out)
        ssize_t n = read_request(0, &buf);
        if (n < 0)
                die_errno("error reading request body");
-       if (write_in_full(out, buf, n) < 0)
-               die("%s aborted reading request", prog_name);
+       write_to_child(out, buf, n, prog_name);
        close(out);
        free(buf);
 }