Skip to content

Commit c6f1a23

Browse files
peffGit for Windows Build Agent
authored andcommitted
fetch: avoid calling write_or_die()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc7e812 commit c6f1a23

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

fetch-pack.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ static void send_request(struct fetch_pack_args *args,
191191
if (args->stateless_rpc) {
192192
send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);
193193
packet_flush(fd);
194-
} else
195-
write_or_die(fd, buf->buf, buf->len);
194+
} else {
195+
if (write_in_full(fd, buf->buf, buf->len) < 0)
196+
die_errno(_("unable to write to remote"));
197+
}
196198
}
197199

198200
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,
11631165

11641166
/* Send request */
11651167
packet_buf_flush(&req_buf);
1166-
write_or_die(fd_out, req_buf.buf, req_buf.len);
1168+
if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
1169+
die_errno(_("unable to write request to remote"));
11671170

11681171
strbuf_release(&req_buf);
11691172
return ret;

pkt-line.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ static void packet_trace(const char *buf, unsigned int len, int write)
8888
void packet_flush(int fd)
8989
{
9090
packet_trace("0000", 4, 1);
91-
write_or_die(fd, "0000", 4);
91+
if (write_in_full(fd, "0000", 4) < 0)
92+
die_errno(_("unable to write flush packet"));
9293
}
9394

9495
void packet_delim(int fd)
9596
{
9697
packet_trace("0001", 4, 1);
97-
write_or_die(fd, "0001", 4);
98+
if (write_in_full(fd, "0001", 4) < 0)
99+
die_errno(_("unable to write delim packet"));
98100
}
99101

100102
int packet_flush_gently(int fd)

0 commit comments

Comments
 (0)