Skip to content

Commit 6424c2a

Browse files
Jehan Binggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0482e8 commit 6424c2a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

convert.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "attr.h"
33
#include "run-command.h"
44
#include "quote.h"
5+
#include "sigchain.h"
56

67
/*
78
* 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)
360361
if (start_command(&child_process))
361362
return error("cannot fork to run external filter %s", params->cmd);
362363

364+
sigchain_push(SIGPIPE, SIG_IGN);
365+
363366
write_err = (write_in_full(child_process.in, params->src, params->size) < 0);
364367
if (close(child_process.in))
365368
write_err = 1;
366369
if (write_err)
367370
error("cannot feed the input to external filter %s", params->cmd);
368371

372+
sigchain_pop(SIGPIPE);
373+
369374
status = finish_command(&child_process);
370375
if (status)
371376
error("external filter %s failed %d", params->cmd, status);

0 commit comments

Comments
 (0)