*/
/* This implementation of posix_spawn is only suitable for the needs of dhcpcd
- * but it could easily be extended to other applications.
- * Also, it does rely on the system being able to modify signals safely within
- * the vfork process which is undefined behaviour, but seems sane in testing. */
+ * but it could easily be extended to other applications. */
#include <sys/types.h>
#include <sys/wait.h>
volatile int error;
error = 0;
+#ifdef THERE_IS_NO_FORK
+ /* Pray we can sanely modify signal foo */
p = vfork();
+#else
+ p = fork();
+#endif
switch (p) {
case -1:
return errno;
posix_spawnattr_setsigmask(&attr, &dhcpcd_sigset);
errno = 0;
i = posix_spawn(&pid, argv[0], NULL, &attr, argv, env);
- if (i)
+ if (i) {
+ errno = i;
return -1;
+ }
return pid;
}
env[++elen] = '\0';
pid = exec_script(argv, env);
- if (pid == -1) {
- syslog(LOG_ERR, "exec_script: %m");
- status = -1;
- } else if (pid != 0) {
+ if (pid == -1)
+ syslog(LOG_ERR, "exec_script: %s: %m", argv[0]);
+ else if (pid != 0) {
/* Wait for the script to finish */
while (waitpid(pid, &status, 0) == -1) {
if (errno != EINTR) {
while (*ep)
free(*ep++);
free(env);
- return status;
+ return WEXITSTATUS(status);
}
static struct rt *