diff --git a/run-command.c b/run-command.c index 13fa452e8c3d5a5e20e24a969d53ce7ade4019bf..3add1d66ac344feab2ca39ee6fff663628c5fe32 100644 --- a/run-command.c +++ b/run-command.c @@ -633,6 +633,11 @@ int in_async(void) return !pthread_equal(main_thread, pthread_self()); } +void NORETURN async_exit(int code) +{ + pthread_exit((void *)(intptr_t)code); +} + #else static struct { @@ -678,6 +683,11 @@ int in_async(void) return process_is_async; } +void NORETURN async_exit(int code) +{ + exit(code); +} + #endif int start_async(struct async *async) diff --git a/run-command.h b/run-command.h index 12bb26c2a6155750203babfec47b08e8bde0ad27..c0969c7695f6b550b382b5704ceb9b2c23b3e3e0 100644 --- a/run-command.h +++ b/run-command.h @@ -121,5 +121,6 @@ struct async { int start_async(struct async *async); int finish_async(struct async *async); int in_async(void); +void NORETURN async_exit(int code); #endif diff --git a/write_or_die.c b/write_or_die.c index e7afe7a295e586d58313e82e87b22de347aef7a1..49e80aa222132c3c151b79bd37749d92a12f745a 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -1,8 +1,12 @@ #include "cache.h" +#include "run-command.h" static void check_pipe(int err) { if (err == EPIPE) { + if (in_async()) + async_exit(141); + signal(SIGPIPE, SIG_DFL); raise(SIGPIPE); /* Should never happen, but just in case... */