run-command: move check_pipe() from write_or_die to run_command

Move check_pipe() to run_command and make it public. This is necessary to call the function from pkt-line in a subsequent patch. While at it, make async_exit() static to run_command.c as it is no longer used from outside. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Schneider committed Oct 16, 2016 at 16:20 UTC b992fe104ecde5a362a31d610de96518f398d5c0
3 files changed +16 -16
run-command.c
+15 -2
@@ -634,7 +634,7 @@ int in_async(void)
634 return !pthread_equal(main_thread, pthread_self());
635 }
636
637 -void NORETURN async_exit(int code)
637 +static void NORETURN async_exit(int code)
638 {
639 pthread_exit((void *)(intptr_t)code);
640 }
@@ -684,13 +684,26 @@ int in_async(void)
684 return process_is_async;
685 }
686
687 -void NORETURN async_exit(int code)
687 +static void NORETURN async_exit(int code)
688 {
689 exit(code);
690 }
691
692 #endif
693
694 +void check_pipe(int err)
695 +{
696 + if (err == EPIPE) {
697 + if (in_async())
698 + async_exit(141);
699 +
700 + signal(SIGPIPE, SIG_DFL);
701 + raise(SIGPIPE);
702 + /* Should never happen, but just in case... */
703 + exit(141);
704 + }
705 +}
706 +
707 int start_async(struct async *async)
708 {
709 int need_in, need_out;
run-command.h
+1 -1
@@ -139,7 +139,7 @@ struct async {
139 int start_async(struct async *async);
140 int finish_async(struct async *async);
141 int in_async(void);
142 -void NORETURN async_exit(int code);
142 +void check_pipe(int err);
143
144 /**
145 * This callback should initialize the child process and preload the
write_or_die.c
-13
@@ -1,19 +1,6 @@
1 #include "cache.h"
2 #include "run-command.h"
3
4 -static void check_pipe(int err)
5 -{
6 - if (err == EPIPE) {
7 - if (in_async())
8 - async_exit(141);
9 -
10 - signal(SIGPIPE, SIG_DFL);
11 - raise(SIGPIPE);
12 - /* Should never happen, but just in case... */
13 - exit(141);
14 - }
15 -}
16 -
4 /*
5 * Some cases use stdio, but want to flush after the write
6 * to get error handling (and to get better interactive