From: Roy Marples Date: Fri, 21 Feb 2014 15:51:42 +0000 (+0000) Subject: If there are no file actions or dangerous attributes then use X-Git-Tag: v6.3.0~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=11a06bb9b129a3dd3c872e142bd3334cf560bb54;p=thirdparty%2Fdhcpcd.git If there are no file actions or dangerous attributes then use vfork(2) instead of fork(2) in our compat posix_spawn(3) function. --- diff --git a/compat/posix_spawn.c b/compat/posix_spawn.c index 822425e7..0cb142e5 100644 --- a/compat/posix_spawn.c +++ b/compat/posix_spawn.c @@ -74,21 +74,31 @@ posix_spawnattr_handle(const posix_spawnattr_t *attrp) return 0; } +inline static int +is_vfork_safe(short int flags) +{ + return !(flags & (POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK)); +} + int -posix_spawn(pid_t *pid, const char * path, - __unused void *arg, +posix_spawn(pid_t *pid, const char *path, + const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]) { + short int flags; pid_t p; volatile int error; error = 0; + flags = attrp ? attrp->posix_attr_flags : 0; + if (file_actions == NULL && is_vfork_safe(flags)) + p = vfork(); + else #ifdef THERE_IS_NO_FORK - /* Pray we can sanely modify signal foo */ - p = vfork(); + return ENOSYS; #else - p = fork(); + p = fork(); #endif switch (p) { case -1: diff --git a/compat/posix_spawn.h b/compat/posix_spawn.h index fe6958c4..ccfb0f0c 100644 --- a/compat/posix_spawn.h +++ b/compat/posix_spawn.h @@ -38,8 +38,13 @@ typedef struct { sigset_t posix_attr_sigdefault; } posix_spawnattr_t; -int posix_spawn(pid_t *, const char *, void *, const posix_spawnattr_t *, - char *const [], char *const []); +typedef struct { +// int unused; +} posix_spawn_file_actions_t; + +int posix_spawn(pid_t *, const char *, + const posix_spawn_file_actions_t *, const posix_spawnattr_t *, + char *const [], char *const []); int posix_spawnattr_init(posix_spawnattr_t *); int posix_spawnattr_setflags(posix_spawnattr_t *, short); int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *);