Skip to content

Commit c0222e7

Browse files
peffgitster
authored andcommitted
trace: stop using write_or_whine_pipe()
The write_or_whine_pipe function does two things: 1. it checks for EPIPE and converts it into a signal death 2. it prints a message to stderr on error The first thing does not help us, and actively hurts. Generally we would simply die from SIGPIPE in this case, unless somebody has taken the time to ignore SIGPIPE for the whole process. And if they _did_ do that, it seems rather silly for the trace code, which otherwise takes pains to continue even in the face of errors (e.g., by not using write_or_die!), to take down the whole process for one specific type of error. Nor does the second thing help us; it just makes it harder to write our error message, because we have to feed bits of it as an argument to write_or_whine_pipe(). Translators never get to see the full message, and it's hard for us to customize it. Let's switch to just using write_in_full() and writing our own error string. For now, the error is identical to what write_or_whine_pipe() would say, but now that it's more under our control, we can improve it in future patches. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c81539b commit c0222e7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

trace.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,23 @@ static int prepare_trace_line(const char *file, int line,
132132
return 1;
133133
}
134134

135+
static void trace_write(struct trace_key *key, const void *buf, unsigned len)
136+
{
137+
if (write_in_full(get_trace_fd(key), buf, len) < 0)
138+
fprintf(stderr, "%s: write error (%s)\n", err_msg, strerror(errno));
139+
}
140+
135141
void trace_verbatim(struct trace_key *key, const void *buf, unsigned len)
136142
{
137143
if (!trace_want(key))
138144
return;
139-
write_or_whine_pipe(get_trace_fd(key), buf, len, err_msg);
145+
trace_write(key, buf, len);
140146
}
141147

142148
static void print_trace_line(struct trace_key *key, struct strbuf *buf)
143149
{
144150
strbuf_complete_line(buf);
145-
146-
write_or_whine_pipe(get_trace_fd(key), buf->buf, buf->len, err_msg);
151+
trace_write(key, buf->buf, buf->len);
147152
strbuf_release(buf);
148153
}
149154

0 commit comments

Comments
 (0)