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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 1, 2016 at 02:06 UTC
12e0437f237ad72df3a2f3f8b067cf8097d792f1
2 files changed
+23
-23
common-main.c
+23
@@ -1,6 +1,27 @@
1
#include "cache.h"
2
#include "exec_cmd.h"
3
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
+
25
int main(int argc, char **av)
26
{
27
/*
@@ -18,5 +39,7 @@ int main(int argc, char **av)
39
40
argv[0] = git_extract_argv0_path(argv[0]);
41
42
+ restore_sigpipe_to_default();
43
+
44
return cmd_main(argc, argv);
45
}
git.c
-23
@@ -609,27 +609,6 @@ static int run_argv(int *argcp, const char ***argv)
609
return done_alias;
610
}
611
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
-
612
int cmd_main(int argc, const char **argv)
613
{
614
const char *cmd;
@@ -639,8 +618,6 @@ int cmd_main(int argc, const char **argv)
618
if (!cmd)
619
cmd = "git-help";
620
642
- restore_sigpipe_to_default();
643
-
621
git_setup_gettext();
622
623
trace_command_performance(argv);