bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH replace vfork with fork] remove deprecated vfork


From: Minsoo Choo
Subject: [PATCH replace vfork with fork] remove deprecated vfork
Date: Sat, 19 Nov 2022 13:32:11 -0500

---
Dear maintainer,

I highly suggest to replace vfork(2) with fork(2) for several reasons.
First, some systems like macOS have deprecated vfork(2) and encourage
users to use fork(2). This can cause compatibility issues in the future
which will bring build errors on some systems. Furthermore, although I
acknowledge the advantages of using vfork(2), many programmers have
criticized that it is a dangerous practice to use it, and I agree with
that idea. The implementation of fork(2) has been improved on many
operating systems including Linux, therefore I believe that the huge gap between
the performances of vfork(2) and fork(2) does not exist anymore. For
these reasons, I highly suggest to replace vfork(2) with fork(2).

 lib/cdefs.h              |  2 +-
 lib/spawnattr_setflags.c |  3 +--
 lib/spawni.c             | 18 ++----------------
 3 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/lib/cdefs.h b/lib/cdefs.h
index 7b8ed5b34..df25b7ab5 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -696,7 +696,7 @@ _Static_assert (0, "IEEE 128-bits long double requires 
redirection on this platf
 # define __attr_dealloc_free
 #endif
 
-/* Specify that a function such as setjmp or vfork may return
+/* Specify that a function such as setjmp or fork may return
    twice.  */
 #if __GNUC_PREREQ (4, 1)
 # define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
diff --git a/lib/spawnattr_setflags.c b/lib/spawnattr_setflags.c
index 9ddcf62bc..9fb3d167e 100644
--- a/lib/spawnattr_setflags.c
+++ b/lib/spawnattr_setflags.c
@@ -27,8 +27,7 @@
                    | POSIX_SPAWN_SETSIGDEF                                    \
                    | POSIX_SPAWN_SETSIGMASK                                   \
                    | POSIX_SPAWN_SETSCHEDPARAM                                \
-                   | POSIX_SPAWN_SETSCHEDULER                                 \
-                   | POSIX_SPAWN_USEVFORK)
+                   | POSIX_SPAWN_SETSCHEDULER)
 
 /* Store flags in the attribute structure.  */
 int
diff --git a/lib/spawni.c b/lib/spawni.c
index b3b3b56f3..25178ed0e 100644
--- a/lib/spawni.c
+++ b/lib/spawni.c
@@ -74,7 +74,6 @@
 # define sigismember __sigismember
 # define sigprocmask __sigprocmask
 # define strchrnul __strchrnul
-# define vfork __vfork
 #endif
 
 
@@ -871,24 +870,11 @@ __spawni (pid_t *pid, const char *file,
   short int flags = attrp == NULL ? 0 : attrp->_flags;
 
   /* Avoid gcc warning
-       "variable 'flags' might be clobbered by 'longjmp' or 'vfork'"  */
+       "variable 'flags' might be clobbered by 'longjmp' or 'fork'"  */
   (void) &flags;
 
   /* Generate the new process.  */
-#if HAVE_VFORK
-  if ((flags & POSIX_SPAWN_USEVFORK) != 0
-      /* If no major work is done, allow using vfork.  Note that we
-         might perform the path searching.  But this would be done by
-         a call to execvp(), too, and such a call must be OK according
-         to POSIX.  */
-      || ((flags & (POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF
-                    | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER
-                    | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS)) == 0
-          && file_actions == NULL))
-    new_pid = vfork ();
-  else
-#endif
-    new_pid = fork ();
+  new_pid = fork ();
 
   if (new_pid != 0)
     {

base-commit: 08ba9aaebff69a02cbb794c6213314fd09dd5ec5
-- 
2.37.1 (Apple Git-137.1)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]