]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If there are no file actions or dangerous attributes then use
authorRoy Marples <roy@marples.name>
Fri, 21 Feb 2014 15:51:42 +0000 (15:51 +0000)
committerRoy Marples <roy@marples.name>
Fri, 21 Feb 2014 15:51:42 +0000 (15:51 +0000)
vfork(2) instead of fork(2) in our compat posix_spawn(3) function.

compat/posix_spawn.c
compat/posix_spawn.h

index 822425e750d1225090a219fd6ddf666aed01db27..0cb142e55ca5b7a55bcb42869a8f92b8c7056ef8 100644 (file)
@@ -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:
index fe6958c49c9c3546a595d6ee847b1dd78851d37e..ccfb0f0c14d83531b83ce9118c9c54f25992ab2a 100644 (file)
@@ -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 *);