Hi!
Since the discussion stopped, can we agree on the following patch? Feel free
to add more documentation on fork() vs vfork() later.
2001-06-15 Rüdiger Kuhlmann <[EMAIL PROTECTED]>
* 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.
* 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/15 20:35:25
@@ -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.37
diff -u -r1.37 acfunctions.m4
--- acfunctions.m4 2001/06/15 17:44:17 1.37
+++ acfunctions.m4 2001/06/15 20:35:30
@@ -1443,12 +1443,74 @@
AU_ALIAS([AC_UTIME_NULL], [AC_FUNC_UTIME_NULL])
-# 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_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_FORK
+# -------------
+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 +1606,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
Index: doc/autoconf.texi
===================================================================
RCS file: /cvs/autoconf/doc/autoconf.texi,v
retrieving revision 1.467
diff -u -r1.467 autoconf.texi
--- doc/autoconf.texi 2001/06/15 17:44:17 1.467
+++ doc/autoconf.texi 2001/06/15 20:38:57
@@ -3233,6 +3233,44 @@
Solaris 2.4), define @code{HAVE_FNMATCH}.
@end defmac
+@defmac AC_FUNC_FORK
+@maindex FUNC_FORK
+@cvindex HAVE_VFORK_H
+@cvindex HAVE_WORKING_FORK
+@cvindex HAVE_WORKING_VFORK
+@cvindex 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
+@code{vfork} 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 with
+previous versions of @command{autoconf} you're encouraged to define it
+yourself in new code:
+@example
+@group
+#if !HAVE_WORKING_VFORK
+# define vfork fork
+#endif
+@end group
+@end example
+In case you prefer to use @code{fork} whereever possible, use this code:
+@example
+@group
+#if HAVE_WORKING_FORK
+# define vfork fork
+#endif
+but still use @code{vfork} whereever it can be used portably.
+@end defmac
+
@defmac AC_FUNC_FSEEKO
@maindex FUNC_FSEEKO
@cvindex _LARGEFILE_SOURCE
@@ -3461,19 +3499,6 @@
@cvindex HAVE_UTIME_NULL
If @samp{utime(@var{file}, NULL)} sets @var{file}'s timestamp to
the present, define @code{HAVE_UTIME_NULL}.
-@end defmac
-
-@defmac AC_FUNC_VFORK
-@maindex FUNC_VFORK
-@cvindex HAVE_VFORK_H
-@cvindex vfork
-If @file{vfork.h} is found, define @code{HAVE_VFORK_H}. If a working
-@code{vfork} 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.
@end defmac
@defmac AC_FUNC_VPRINTF
--
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