autoconf
[Top][All Lists]
Advanced

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

Re: [autoconf] AmigaOS fork()


From: Rüdiger Kuhlmann
Subject: Re: [autoconf] AmigaOS fork()
Date: Tue, 12 Jun 2001 17:01:08 +0200
User-agent: Mutt/1.3.18i

Hi!

>--[Paul Eggert]--<address@hidden>

> * The documentation says that AC_FUNC_FORK "only checks whether `fork'
>   is just a stub."  But that's not correct when not cross-compiling:
>   AC_FUNC_FORK actually runs a program that tries to fork.

Okay, doc fixed.

> * AC_FUNC_FORK outputs a warning if neither fork nor vfork works.  But
>   this warning is unnecessary and is not in the style of autoconf.
>   The whole point of invoking AC_FUNC_FORK is to test whether fork
>   and/or vfork works.

Okay, removed.

> * I found the 'forkvfork' function name and explanation to be quite
>   confusing.  Part of the confusion is because the Unix tradition is
>   that code that uses 'vfork' can be safely changed to use 'fork' if
>   you like.  I don't see why AmigaOS violates the Unix tradition, so
>   long as "if you like" is always equivalent to "never" under AmigaOS.

Okay, I changed the doc to suggest to define vfork yourself, either when
!HAVE_WORKING_VFORK, or if you prefer to use fork, when HAVE_WORKING_FORK.

>   I would replace this code with  
>     #if !HAVE_WORKING_VFORK
>     # define vfork fork
>     #endif

Okay.


2001-06-01 Rüdiger Kuhlmann <address@hidden>
 
        * acfunctions.m4: (AC_FUNC_VFORK) renamed to _AC_FUNC_VFORK. Remove
          AC_DEFINEs and don't guess cross-compilation values.
          (_AC_FUNC_FORK) New, check whether fork() isn't just a stub.
          (AC_FUNC_FORK) New, use _AC_FUNC_VFORK and _AC_FUNC_FORK to
          define HAVE_WORKING_FORK, HAVE_WORKING_VFORK; and vfork to fork
          if vfork doesn't work. Guess values if cross-compiling, but warn.
          (AC_FUNC_GETPGRP, AC_FUNC_WAIT3) Use AC_FUNC_FORK; use vfork, but
          #define vfork to fork if necessary.  to vfork if necessary.
        * acspecific.m4: (AC_SYS_RESTARTABLE_SYSCALLS) ditto.
        * acfunctions: add AC_FUNC_FORK.
        * doc/autoconf.texi: Document AC_FUNC_FORK. Give example to
          define and vfork appropriately.

Index: acfunctions
===================================================================
RCS file: /cvs/autoconf/acfunctions,v
retrieving revision 1.14
diff -u -r1.14 acfunctions
--- acfunctions 2001/05/31 15:44:27     1.14
+++ acfunctions 2001/06/12 14:51:23
@@ -26,6 +26,7 @@
 error          AC_FUNC_ERROR_AT_LINE
 error_at_line  AC_FUNC_ERROR_AT_LINE
 fnmatch                AC_FUNC_FNMATCH
+fork           AC_FUNC_FORK     
 fseeko         AC_FUNC_FSEEKO
 ftello         AC_FUNC_FSEEKO
 getgroups      AC_FUNC_GETGROUPS
@@ -56,7 +57,7 @@
 strftime       AC_FUNC_STRFTIME
 strtod         AC_FUNC_STRTOD
 utime          AC_FUNC_UTIME_NULL
-vfork          AC_FUNC_VFORK
+vfork          AC_FUNC_FORK
 vfprintf       AC_FUNC_VPRINTF
 vprintf                AC_FUNC_VPRINTF
 vsprintf       AC_FUNC_VPRINTF
Index: acfunctions.m4
===================================================================
RCS file: /cvs/autoconf/acfunctions.m4,v
retrieving revision 1.36
diff -u -r1.36 acfunctions.m4
--- acfunctions.m4      2001/06/12 14:46:13     1.36
+++ acfunctions.m4      2001/06/12 14:51:33
@@ -599,7 +599,8 @@
 # AC_FUNC_GETPGRP
 # ---------------
 AC_DEFUN([AC_FUNC_GETPGRP],
-[AC_CACHE_CHECK(whether getpgrp takes no argument, ac_cv_func_getpgrp_void,
+[AC_REQUIRE([AC_FUNC_FORK])dnl
+AC_CACHE_CHECK(whether getpgrp takes no argument, ac_cv_func_getpgrp_void,
 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
 /*
  * If this system has a BSD-style getpgrp(),
@@ -609,6 +610,9 @@
  */
 #include <stdio.h>
 #include <sys/types.h>
+#if HAVE_WORKING_VFORK
+# define vfork fork
+#endif
 
 int     pid;
 int     pg1, pg2, pg3, pg4;
@@ -628,7 +632,7 @@
   if (pg2 == pg4 && pg1 == pg3 && pg2 == pg3)
     exit (0);
 
-  child = fork ();
+  child = vfork ();
   if (child < 0)
     exit(1);
   else if (child == 0)
@@ -1442,13 +1446,75 @@
 # -----------------
 AU_ALIAS([AC_UTIME_NULL], [AC_FUNC_UTIME_NULL])
 
+
+# AC_FUNC_FORK
+# -------------
+AC_DEFUN([AC_FUNC_FORK],
+  [AC_REQUIRE([AC_TYPE_PID_T])dnl
+  AC_CHECK_HEADERS(unistd.h vfork.h)
+  AC_CHECK_FUNCS(fork vfork)
+  ac_cv_func_fork_works=$ac_cv_func_fork
+  if test "x$ac_cv_func_fork" = xyes; then
+    _AC_FUNC_FORK
+  fi
+  if test "x$ac_cv_func_fork_works" = xcross"; then
+    case "$host" in
+      *-*-amigaos* | *-*-msdosdjgpp*)
+        # Override, as these systems have only a dummy fork() stub
+        ac_cv_func_fork_works=no
+        ;;
+      *)
+        ac_cv_func_fork_works=yes
+        ;;
+    esac
+    AC_MSG_WARN(CROSS: Result $ac_cv_func_fork_works guessed due to 
cross-compiling.)
+  fi
+  ac_cv_func_vfork_works=$ac_cv_func_vfork
+  if test "x$ac_cv_func_vfork" = xyes; then
+    _AC_FUNC_VFORK
+  fi;
+  if test "x$ac_cv_func_fork_works" = xcross"; then
+    ac_cv_func_vfork_works=ac_cv_func_vfork
+    AC_MSG_WARN(CROSS: Result $ac_cv_func_vfork_works guessed due to 
cross-compiling.)
+  fi
+  
+  if test "x$ac_cv_func_vfork_works" = xyes; then
+    AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define if `vfork' works.])
+  else
+    AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
+  fi
+  if test "x$ac_cv_func_fork_works" = xyes; then
+    AC_DEFINE(HAVE_WORKING_FORK, 1, [Define if `fork' works.])
+  endif
+])# AC_FUNC_FORK
+
 
-# AC_FUNC_VFORK
+# _AC_FUNC_FORK
 # -------------
-AC_DEFUN([AC_FUNC_VFORK],
-[AC_REQUIRE([AC_TYPE_PID_T])dnl
-AC_CHECK_HEADERS(unistd.h vfork.h)
-AC_CACHE_CHECK(for working vfork, ac_cv_func_vfork_works,
+AC_DEFUN([_AC_FUNC_FORK],
+  [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
+    [AC_RUN_IFELSE([/* By Rüdiger Kuhlmann. */
+      #include <sys/types.h>
+      #if HAVE_UNISTD_H
+      # include <unistd.h>
+      #endif
+      /* Some systems only have a dummy stub for fork() */
+      int main ()
+      {
+        if (fork() < 0)
+          exit (1);
+        exit (0);
+      }],
+    [ac_cv_func_fork_works=yes],
+    [ac_cv_func_fork_works=no],
+    [ac_cv_func_fork_works=cross])])]
+)# _AC_FUNC_FORK
+
+
+# _AC_FUNC_VFORK
+# -------------
+AC_DEFUN([_AC_FUNC_VFORK],
+[AC_CACHE_CHECK(for working vfork, ac_cv_func_vfork_works,
 [AC_TRY_RUN([/* Thanks to Paul Eggert for this test.  */
 #include <stdio.h>
 #include <sys/types.h>
@@ -1544,17 +1610,17 @@
 }],
             [ac_cv_func_vfork_works=yes],
             [ac_cv_func_vfork_works=no],
-            [AC_CHECK_FUNC(vfork)
-ac_cv_func_vfork_works=$ac_cv_func_vfork])])
-if test "x$ac_cv_func_vfork_works" = xno; then
-  AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
-fi
-])# AC_FUNC_VFORK
+            [ac_cv_func_vfork_works=cross])])
+])# _AC_FUNC_VFORK
+
 
+# AU::AC_FUNC_VFORK
+# ------------
+AU_ALIAS([AC_FUNC_VFORK], [AC_FUNC_FORK])
 
 # AU::AC_VFORK
 # ------------
-AU_ALIAS([AC_VFORK], [AC_FUNC_VFORK])
+AU_ALIAS([AC_VFORK], [AC_FUNC_FORK])
 
 
 # AC_FUNC_VPRINTF
@@ -1578,12 +1644,16 @@
 # AC_FUNC_WAIT3
 # -------------
 AC_DEFUN([AC_FUNC_WAIT3],
-[AC_CACHE_CHECK(for wait3 that fills in rusage, ac_cv_func_wait3_rusage,
+[AC_REQUIRE([AC_FUNC_FORK])dnl
+AC_CACHE_CHECK(for wait3 that fills in rusage, ac_cv_func_wait3_rusage,
 [AC_TRY_RUN(
 [#include <sys/types.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <stdio.h>
+#if !HAVE_WORKING_VFORK
+# define vfork fork
+#endif
 /* HP-UX has wait3 but does not fill in rusage at all.  */
 int
 main ()
@@ -1598,7 +1668,7 @@
   r.ru_stime.tv_sec = 0;
   r.ru_stime.tv_usec = 0;
   r.ru_majflt = r.ru_minflt = 0;
-  switch (fork ())
+  switch (vfork ())
     {
     case 0: /* Child.  */
       sleep(1); /* Give up the CPU.  */
Index: acspecific.m4
===================================================================
RCS file: /cvs/autoconf/acspecific.m4,v
retrieving revision 1.340
diff -u -r1.340 acspecific.m4
--- acspecific.m4       2001/06/12 14:46:13     1.340
+++ acspecific.m4       2001/06/12 14:51:41
@@ -495,6 +495,7 @@
 # interrupted by a signal, define `HAVE_RESTARTABLE_SYSCALLS'.
 AC_DEFUN([AC_SYS_RESTARTABLE_SYSCALLS],
 [AC_REQUIRE([AC_HEADER_SYS_WAIT])dnl
+AC_REQUIRE([AC_FUNC_FORK])dnl
 AC_CHECK_HEADERS(unistd.h)
 AC_CACHE_CHECK(for restartable system calls, ac_cv_sys_restartable_syscalls,
 [AC_RUN_IFELSE([AC_LANG_SOURCE(
@@ -510,6 +511,9 @@
 #if HAVE_SYS_WAIT_H
 # include <sys/wait.h>
 #endif
+#if !HAVE_WORKING_VFORK
+# define vfork fork
+#endif
 
 /* Some platforms explicitly require an extern "C" signal handler
    when using C++. */
@@ -522,7 +526,7 @@
 int
 main ()
 {
-  int i = fork (), status;
+  int i = vfork (), status;
 
   if (i == 0)
     {
Index: doc/autoconf.texi
===================================================================
RCS file: /cvs/autoconf/doc/autoconf.texi,v
retrieving revision 1.463
diff -u -r1.463 autoconf.texi
--- doc/autoconf.texi   2001/06/12 14:46:13     1.463
+++ doc/autoconf.texi   2001/06/12 14:54:18
@@ -3229,6 +3229,43 @@
 Solaris 2.4), define @code{HAVE_FNMATCH}.
 @end defmac
 
address@hidden AC_FUNC_FORK
address@hidden FUNC_FORK
address@hidden HAVE_VFORK_H
address@hidden HAVE_WORKING_FORK
address@hidden HAVE_WORKING_VFORK
address@hidden vfork
+This macro checks for the @code{fork} and @code{vfork} functions. If a
+working @code{fork} is found, define @code{HAVE_WORKING_FORK}. This macro
+checks whether @code{fork} is just a stub by trying to run it.
+
+If @file{vfork.h} is found, define @code{HAVE_VFORK_H}. If a working
address@hidden is found, define @code{HAVE_WORKING_VFORK}. Otherwise,
+define @code{vfork} to be @code{fork} for backward compatibility. This macro
+checks for several known errors in implementations of @code{vfork} and
+considers the system to not have a working @code{vfork} if it detects any of
+them. It is not considered to be an implementation error if a child's
+invocation of @code{signal} modifies the parent's signal handler, since
+child processes rarely change their signal handlers.
+
+Since this macro defines @code{vfork} only for backward compatibility,
+you're encouraged to define it yourself in new code:
address@hidden
address@hidden
+#if !HAVE_WORKING_VFORK
+# define vfork fork
+#endif
address@hidden group
address@hidden example
+In case you prefer to use @code{fork} whereever possible, use this code:
address@hidden
address@hidden
+#if HAVE_WORKING_FORK
+# define vfork fork
+#endif
+but still use @code{vfork} whereever it can be used portably.
address@hidden defmac
+
 @defmac AC_FUNC_FSEEKO
 @maindex FUNC_FSEEKO
 @cvindex _LARGEFILE_SOURCE
@@ -3459,19 +3496,6 @@
 the present, define @code{HAVE_UTIME_NULL}.
 @end defmac
 
address@hidden AC_FUNC_VFORK
address@hidden FUNC_VFORK
address@hidden HAVE_VFORK_H
address@hidden vfork
-If @file{vfork.h} is found, define @code{HAVE_VFORK_H}.  If a working
address@hidden is not found, define @code{vfork} to be @code{fork}.  This
-macro checks for several known errors in implementations of @code{vfork}
-and considers the system to not have a working @code{vfork} if it
-detects any of them.  It is not considered to be an implementation error
-if a child's invocation of @code{signal} modifies the parent's signal
-handler, since child processes rarely change their signal handlers.
address@hidden defmac
-
 @defmac AC_FUNC_VPRINTF
 @maindex FUNC_VPRINTF
 @cvindex HAVE_VPRINTF
@@ -6929,7 +6953,22 @@
 @end table
 
 
address@hidden
+AC_LANG_PUSH(Fortran 77)
+# Perform some tests on Fortran 77.
+# ...
+AC_LANG_POP(Fortran 77)
address@hidden example
address@hidden defmac
 
address@hidden AC_REQUIRE_CPP
address@hidden REQUIRE_CPP
+Ensure that whichever preprocessor would currently be used for tests has
+been found.  Calls @code{AC_REQUIRE} (@pxref{Prerequisite Macros}) with an
+argument of either @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP},
+depending on which language is current.
address@hidden defmac
+
 
 @c ====================================================== Results of Tests.
 
@@ -9534,6 +9573,11 @@
 @defmac AC_FUNC_CHECK
 @maindex FUNC_CHECK
 @code{AC_CHECK_FUNC}
address@hidden defmac
+
address@hidden AC_FUNC_VFORK
address@hidden FUNC_VFORK
address@hidden
 @end defmac
 
 @defmac AC_GCC_TRADITIONAL



-- 
A "No" uttered from deepest conviction is better and greater than a
"Yes" merely uttered to please, or what is worse, to avoid trouble.
                -- Mahatma Ghandi



reply via email to

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