David Turner <[email protected]> writes:
> packet_write calls write_or_die, which dies with a sigpipe even if
> calling code has explicitly blocked that signal.
>
> Add packet_write_gently and packet_flush_gently, which don't. Soon,
> we will use this for communication with git index-helper, which, being
> merely an optimization, should be permitted to die without disrupting
> clients.
>
> Signed-off-by: David Turner <[email protected]>
> ---
Looks quite sensible. Thanks.
> pkt-line.c | 18 ++++++++++++++++++
> pkt-line.h | 2 ++
> 2 files changed, 20 insertions(+)
>
> diff --git a/pkt-line.c b/pkt-line.c
> index 62fdb37..f964446 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -91,6 +91,12 @@ void packet_flush(int fd)
> write_or_die(fd, "0000", 4);
> }
>
> +int packet_flush_gently(int fd)
> +{
> + packet_trace("0000", 4, 1);
> + return write_in_full(fd, "0000", 4) != 4;
> +}
> +
> void packet_buf_flush(struct strbuf *buf)
> {
> packet_trace("0000", 4, 1);
> @@ -130,6 +136,18 @@ void packet_write(int fd, const char *fmt, ...)
> write_or_die(fd, buf.buf, buf.len);
> }
>
> +int packet_write_gently(int fd, const char *fmt, ...)
> +{
> + static struct strbuf buf = STRBUF_INIT;
> + va_list args;
> +
> + strbuf_reset(&buf);
> + va_start(args, fmt);
> + format_packet(&buf, fmt, args);
> + va_end(args);
> + return write_in_full(fd, buf.buf, buf.len) != buf.len;
> +}
> +
> void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
> {
> va_list args;
> diff --git a/pkt-line.h b/pkt-line.h
> index 3cb9d91..deffcb5 100644
> --- a/pkt-line.h
> +++ b/pkt-line.h
> @@ -20,7 +20,9 @@
> * side can't, we stay with pure read/write interfaces.
> */
> void packet_flush(int fd);
> +int packet_flush_gently(int fd);
> void packet_write(int fd, const char *fmt, ...) __attribute__((format
> (printf, 2, 3)));
> +int packet_write_gently(int fd, const char *fmt, ...) __attribute__((format
> (printf, 2, 3)));
> void packet_buf_flush(struct strbuf *buf);
> void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
> __attribute__((format (printf, 2, 3)));
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html