Skip to content

Commit 12e0437

Browse files
peffgitster
authored andcommitted
common-main: call restore_sigpipe_to_default()
This is another safety/sanity setup that should be in force everywhere, but which we only applied in git.c. This did catch most cases, since even external commands are typically run via "git ..." (and the restoration applies to sub-processes, too). But there were cases we missed, such as somebody calling git-upload-pack directly via ssh, or scripts which use dashed external commands directly. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57f5d52 commit 12e0437

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

common-main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
#include "cache.h"
22
#include "exec_cmd.h"
33

4+
/*
5+
* Many parts of Git have subprograms communicate via pipe, expect the
6+
* upstream of a pipe to die with SIGPIPE when the downstream of a
7+
* pipe does not need to read all that is written. Some third-party
8+
* programs that ignore or block SIGPIPE for their own reason forget
9+
* to restore SIGPIPE handling to the default before spawning Git and
10+
* break this carefully orchestrated machinery.
11+
*
12+
* Restore the way SIGPIPE is handled to default, which is what we
13+
* expect.
14+
*/
15+
static void restore_sigpipe_to_default(void)
16+
{
17+
sigset_t unblock;
18+
19+
sigemptyset(&unblock);
20+
sigaddset(&unblock, SIGPIPE);
21+
sigprocmask(SIG_UNBLOCK, &unblock, NULL);
22+
signal(SIGPIPE, SIG_DFL);
23+
}
24+
425
int main(int argc, char **av)
526
{
627
/*
@@ -18,5 +39,7 @@ int main(int argc, char **av)
1839

1940
argv[0] = git_extract_argv0_path(argv[0]);
2041

42+
restore_sigpipe_to_default();
43+
2144
return cmd_main(argc, argv);
2245
}

git.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -609,27 +609,6 @@ static int run_argv(int *argcp, const char ***argv)
609609
return done_alias;
610610
}
611611

612-
/*
613-
* Many parts of Git have subprograms communicate via pipe, expect the
614-
* upstream of a pipe to die with SIGPIPE when the downstream of a
615-
* pipe does not need to read all that is written. Some third-party
616-
* programs that ignore or block SIGPIPE for their own reason forget
617-
* to restore SIGPIPE handling to the default before spawning Git and
618-
* break this carefully orchestrated machinery.
619-
*
620-
* Restore the way SIGPIPE is handled to default, which is what we
621-
* expect.
622-
*/
623-
static void restore_sigpipe_to_default(void)
624-
{
625-
sigset_t unblock;
626-
627-
sigemptyset(&unblock);
628-
sigaddset(&unblock, SIGPIPE);
629-
sigprocmask(SIG_UNBLOCK, &unblock, NULL);
630-
signal(SIGPIPE, SIG_DFL);
631-
}
632-
633612
int cmd_main(int argc, const char **argv)
634613
{
635614
const char *cmd;
@@ -639,8 +618,6 @@ int cmd_main(int argc, const char **argv)
639618
if (!cmd)
640619
cmd = "git-help";
641620

642-
restore_sigpipe_to_default();
643-
644621
git_setup_gettext();
645622

646623
trace_command_performance(argv);

0 commit comments

Comments
 (0)