mirror of
https://github.com/rsmarples/dhcpcd.git
synced 2024-11-27 20:14:15 +08:00
Use posix_spawn instead of vfork to avoid signal races.
This commit is contained in:
parent
091c081bd1
commit
3712922130
23
configure.c
23
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,
|
||||
|
Loading…
Reference in New Issue
Block a user