run-command: use the async-signal-safe execv instead of execvp
commite3a434468fecca7c14a6bef32050dfa60534fde6
authorBrandon Williams <bmwill@google.com>
Wed, 19 Apr 2017 23:13:20 +0000 (19 16:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Apr 2017 00:55:32 +0000 (20 17:55 -0700)
treeec737bb9ea936b0a8ed4fdc155ee5d8ebd91a594
parent3967e25be11ab96ced71f16b9f082de270a518db
run-command: use the async-signal-safe execv instead of execvp

Convert the function used to exec from 'execvp()' to 'execv()' as the (p)
variant of exec isn't async-signal-safe and has the potential to call malloc
during the path resolution it performs.  Instead we simply do the path
resolution ourselves during the preparation stage prior to forking.  There also
don't exist any portable (p) variants which also take in an environment to use
in the exec'd process.  This allows easy migration to using 'execve()' in a
future patch.

Also, as noted in [1], in the event of an ENOEXEC the (p) variants of
exec will attempt to execute the command by interpreting it with the
'sh' utility.  To maintain this functionality, if 'execv()' fails with
ENOEXEC, start_command will atempt to execute the command by
interpreting it with 'sh'.

[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c