Ignore SIGPIPE when running a filter driver

If a filter is not defined or if it fails, git should behave as if the filter is a no-op passthru. However, if the filter exits before reading all the content, depending on the timing, git could be killed with SIGPIPE when it tries to write to the pipe connected to the filter. Ignore SIGPIPE while processing the filter to give us a chance to check the return value from a failed write, in order to detect and act on this mode of failure in a more controlled way. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jehan Bing committed Feb 20, 2012 at 12:53 UTC 6424c2ad12cf6c3feb533fab9c4dded7514d0f4c
1 file changed +5
convert.c
+5
@@ -2,6 +2,7 @@
2 #include "attr.h"
3 #include "run-command.h"
4 #include "quote.h"
5 +#include "sigchain.h"
6
7 /*
8 * convert.c - convert a file when checking it out and checking it in.
@@ -360,12 +361,16 @@ static int filter_buffer(int in, int out, void *data)
361 if (start_command(&child_process))
362 return error("cannot fork to run external filter %s", params->cmd);
363
364 + sigchain_push(SIGPIPE, SIG_IGN);
365 +
366 write_err = (write_in_full(child_process.in, params->src, params->size) < 0);
367 if (close(child_process.in))
368 write_err = 1;
369 if (write_err)
370 error("cannot feed the input to external filter %s", params->cmd);
371
372 + sigchain_pop(SIGPIPE);
373 +
374 status = finish_command(&child_process);
375 if (status)
376 error("external filter %s failed %d", params->cmd, status);