Skip to content

Commit 6b1fae1

Browse files
max630gitster
authored andcommitted
http-backend: cleanup writing to child process
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/[email protected]/ Signed-off-by: Max Kirillov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2c7d17 commit 6b1fae1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

http-backend.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ static struct rpc_service *select_service(struct strbuf *hdr, const char *name)
279279
return svc;
280280
}
281281

282+
static void write_to_child(int out, const unsigned char *buf, ssize_t len, const char *prog_name)
283+
{
284+
if (write_in_full(out, buf, len) < 0)
285+
die("unable to write to '%s'", prog_name);
286+
}
287+
282288
/*
283289
* This is basically strbuf_read(), except that if we
284290
* 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)
361367
die("zlib error inflating request, result %d", ret);
362368

363369
n = stream.total_out - cnt;
364-
if (write_in_full(out, out_buf, n) < 0)
365-
die("%s aborted reading request", prog_name);
366-
cnt += n;
370+
write_to_child(out, out_buf, stream.total_out - cnt, prog_name);
371+
cnt = stream.total_out;
367372

368373
if (ret == Z_STREAM_END)
369374
goto done;
@@ -382,8 +387,7 @@ static void copy_request(const char *prog_name, int out)
382387
ssize_t n = read_request(0, &buf);
383388
if (n < 0)
384389
die_errno("error reading request body");
385-
if (write_in_full(out, buf, n) < 0)
386-
die("%s aborted reading request", prog_name);
390+
write_to_child(out, buf, n, prog_name);
387391
close(out);
388392
free(buf);
389393
}

0 commit comments

Comments
 (0)