]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Use posix_spawn instead of vfork to avoid signal races.
authorRoy Marples <roy@marples.name>
Sat, 2 Feb 2008 17:28:22 +0000 (17:28 +0000)
committerRoy Marples <roy@marples.name>
Sat, 2 Feb 2008 17:28:22 +0000 (17:28 +0000)
configure.c

index 4fb36c5015bc900a803f0fde9a01b7908317e96e..c7591c18e16d8820cfe1fcdc295b08e04701f958 100644 (file)
@@ -40,6 +40,7 @@
 #include <errno.h>
 #include <netdb.h>
 #include <resolv.h>
+#include <spawn.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -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,