summaryrefslogtreecommitdiffstats
path: root/configure.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-02-02 17:28:22 +0000
committerRoy Marples <roy@marples.name>2008-02-02 17:28:22 +0000
commit3712922130df3936d06d31c166a8f49435428ce7 (patch)
tree476f34d6b31a80d3bfb788d9291f5eedb1a18798 /configure.c
parent091c081bd1e502c36213dc15e9bb966e532359ea (diff)
downloaddhcpcd-3712922130df3936d06d31c166a8f49435428ce7.tar.xz
Use posix_spawn instead of vfork to avoid signal races.
Diffstat (limited to 'configure.c')
-rw-r--r--configure.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/configure.c b/configure.c
index 4fb36c50..c7591c18 100644
--- a/configure.c
+++ b/configure.c
@@ -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,