From: Roy Marples Date: Sat, 2 Feb 2008 17:28:22 +0000 (+0000) Subject: Use posix_spawn instead of vfork to avoid signal races. X-Git-Tag: v3.2.3~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3712922130df3936d06d31c166a8f49435428ce7;p=thirdparty%2Fdhcpcd.git Use posix_spawn instead of vfork to avoid signal races. --- diff --git a/configure.c b/configure.c index 4fb36c50..c7591c18 100644 --- a/configure.c +++ b/configure.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,8 @@ #include "logger.h" #include "socket.h" +extern char **environ; + static int file_in_path (const char *file) { char *p = getenv ("PATH"); @@ -87,9 +90,9 @@ static int file_in_path (const char *file) static int exec_cmd (const char *cmd, const char *args, ...) { va_list va; - pid_t pid; char **argv; int n = 1; + int ret; va_start (va, args); while (va_arg (va, char *) != NULL) @@ -105,19 +108,13 @@ static int exec_cmd (const char *cmd, const char *args, ...) n++; va_end (va); - if ((pid = vfork ()) == 0) { - if (execvp (cmd, argv) && errno != ENOENT) - logger (LOG_ERR, "error executing \"%s\": %s", - cmd, strerror (errno)); - _exit (0); - } else if (pid == -1) { - logger (LOG_ERR, "vfork: %s", strerror (errno)); - free (argv); - return (-1); - } - + errno = 0; + ret = posix_spawnp (NULL, argv[0], NULL, NULL, argv, environ); + if (ret != 0 || errno != 0) + logger (LOG_ERR, "error executing \"%s\": %s", + cmd, strerror (errno)); free (argv); - return (0); + return (ret); } static void exec_script (const char *script, const char *infofile,