run-command: block signals between fork and execve
commit45afb1ca9c28855096c94926e5b16dfbcde7381f
authorEric Wong <e@80x24.org>
Wed, 19 Apr 2017 23:13:27 +0000 (19 16:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Apr 2017 00:55:32 +0000 (20 17:55 -0700)
tree0f9edd2f8b31c420d03e24336881c50308437d54
parente503cd6ed336d70d716e194ef6c5469330bea9da
run-command: block signals between fork and execve

Signal handlers of the parent firing in the forked child may
have unintended side effects.  Rather than auditing every signal
handler we have and will ever have, block signals while forking
and restore default signal handlers in the child before execve.

Restoring default signal handlers is required because
execve does not unblock signals, it only restores default
signal handlers.  So we must restore them with sigprocmask
before execve, leaving a window when signal handlers
we control can fire in the child.  Continue ignoring
ignored signals, but reset the rest to defaults.

Similarly, disable pthread cancellation to future-proof our code
in case we start using cancellation; as cancellation is
implemented with signals in glibc.

Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c