autoconf cleanup for AC_FUNC_GETPGRP and GETPGRP_VOID

Paul Eggert eggert at twinsun.com
Tue Sep 18 03:56:09 EST 2001


> From: Akim Demaille <akim at epita.fr>
> Date: 17 Sep 2001 11:22:19 +0200
> 
> | 2001-09-16  Tim Van Holder  <tim.van.holder at pandora.be>
> | 	* lib/autoconf/functions.m4: (AC_FUNC_GETPGRP) Don't rely on
> | 	setpgrp() being present.

I looked into that problem a bit more.  Several programs use
AC_FUNC_GETPGRP and GETPGRP_VOID, including Bash, Gawk, and OpenSSH,
but they use it only to decide whether they must pass an arg (either 0
or getpid()) to getpgrp, which is the only sane thing to do in my
opinion.  And I noticed that Vile avoids AC_FUNC_GETPGRP entirely,
just checking whether getpgrp(0) is allowed; I think this is a better
test, as it matches how programs actually use GETPGRP_VOID.

So here is a patch to simplify this ancient cruft so that it works the
way that Vile does things.  This patch shouldn't require any change to
any of the programs I looked into, but I'll CC: this to bug-bash,
bug-gawk, and openssh-unix-dev to give them a heads-up.

2001-09-17  Paul Eggert  <eggert at twinsun.com>

	* doc/autoconf.texi (Particular Functions): AC_FUNC_GETPGRP
	now merely checks whether it is an error to pass an argument
	to getpgrp.

	* lib/autoconf/functions.m4 (_AC_FUNC_GETPGRP_TEST): Remove.
	(AC_FUNC_GETPGRP): Don't bother with a runtime test.  Just check
	whether it is a (compile-time) error to pass an argument to
	getpgrp.  This simpler test supports the revised documentation,
	and is all that AC_FUNC_GETPGRP's users really need.

diff -ru autoconf/doc/autoconf.texi autoconf-fix1/doc/autoconf.texi
--- autoconf/doc/autoconf.texi	Mon Sep 17 17:05:37 2001
+++ autoconf-fix1/doc/autoconf.texi	Mon Sep 17 17:46:43 2001
@@ -3577,11 +3577,24 @@
 @defmac AC_FUNC_GETPGRP
 @acindex FUNC_GETPGRP
 @cvindex GETPGRP_VOID
+ at c @fuindex getpgid
 @c @fuindex getpgrp
+ at prindex @code{getpgid}
 @prindex @code{getpgrp}
-If @code{getpgrp} takes no argument (the @sc{posix.1} version), define
- at code{GETPGRP_VOID}.  Otherwise, it is the @sc{bsd} version, which takes
-a process ID as an argument.  This macro does not check whether
+Define @code{GETPGRP_VOID} if it is an error to pass 0 to
+ at code{getpgrp}; this is the @sc{posix.1} behavior.  On older BSD
+systems, you must pass 0 to @code{getpgrp}, as it takes an argument and
+behaves like @sc{posix.1}'s @code{getpgid}.
+
+ at example
+#if GETPGRP_VOID
+  pid = getpgrp ();
+#else
+  pid = getpgrp (0);
+#endif
+ at end example
+
+This macro does not check whether
 @code{getpgrp} exists at all; if you need to work in that situation,
 first call @code{AC_CHECK_FUNC} for @code{getpgrp}.
 @end defmac
diff -ru autoconf/lib/autoconf/functions.m4 autoconf-fix1/lib/autoconf/functions.m4
--- autoconf/lib/autoconf/functions.m4	Wed Aug 22 17:52:14 2001
+++ autoconf-fix1/lib/autoconf/functions.m4	Mon Sep 17 17:28:59 2001
@@ -594,91 +594,20 @@
                          [Define if you have the `getmntent' function.])])])
 
 
-# _AC_FUNC_GETPGRP_TEST
-# ---------------------
-# A program that exits with success iff `getpgrp' seems to ignore its
-# argument.
-m4_define([_AC_FUNC_GETPGRP_TEST],
-[AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
-[[
-/*
- * If this system has a BSD-style getpgrp(),
- * which takes a pid argument, exit unsuccessfully.
- *
- * Snarfed from Chet Ramey's bash pgrp.c test program
- */
-
-int     pid;
-int     pg1, pg2, pg3, pg4;
-int     ng, np, s, child;
-
-int
-main ()
-{
-  pid = getpid ();
-  pg1 = getpgrp (0);
-  pg2 = getpgrp ();
-  pg3 = getpgrp (pid);
-  pg4 = getpgrp (1);
-
-  /* If all of these values are the same, it's pretty sure that we're
-     on a system that ignores getpgrp's first argument.  */
-  if (pg2 == pg4 && pg1 == pg3 && pg2 == pg3)
-    exit (0);
-
-  child = fork ();
-  if (child < 0)
-    exit(1);
-  else if (child == 0)
-    {
-      np = getpid ();
-      /*  If this is Sys V, this will not work; pgrp will be set to np
-	 because setpgrp just changes a pgrp to be the same as the
-	 pid.  */
-      setpgrp (np, pg1);
-      ng = getpgrp (0);        /* Same result for Sys V and BSD */
-      if (ng == pg1)
-  	exit (1);
-      else
-  	exit (0);
-    }
-  else
-    {
-      wait (&s);
-      exit (s>>8);
-    }
-}]])
-])# _AC_FUNC_GETPGRP_TEST
-
-
 # AC_FUNC_GETPGRP
 # ---------------
-# Figure out whether getpgrp takes an argument or not.  Try first using
-# prototypes (AC_COMPILE), and if the compiler is of no help, try a runtime
-# test.
+# Figure out whether getpgrp requires zero arguments.
 AC_DEFUN([AC_FUNC_GETPGRP],
-[AC_CACHE_CHECK(whether getpgrp takes no argument, ac_cv_func_getpgrp_void,
+[AC_CACHE_CHECK(whether getpgrp requires zero arguments,
+ ac_cv_func_getpgrp_void,
 [# Use it with a single arg.
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [getpgrp (0);])],
-                  [ac_func_getpgrp_1=yes],
-                  [ac_func_getpgrp_1=no])
-# Use it with no arg.
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [getpgrp ();])],
-                  [ac_func_getpgrp_0=yes],
-                  [ac_func_getpgrp_0=no])
-# If both static checks agree, we are done.
-case $ac_func_getpgrp_0:$ac_func_getpgrp_1 in
-  yes:no) ac_cv_func_getpgrp_void=yes;;
-  no:yes) ac_cv_func_getpgrp_void=false;;
-  *) AC_RUN_IFELSE([_AC_FUNC_GETPGRP_TEST],
-                   [ac_cv_func_getpgrp_void=yes],
-                   [ac_cv_func_getpgrp_void=no],
-                   [AC_MSG_ERROR([cannot check getpgrp if cross compiling])]);;
-esac # $ac_func_getpgrp_0:$ac_func_getpgrp_1
+                  [ac_cv_func_getpgrp_void=no],
+                  [ac_cv_func_getpgrp_void=yes])
 ])
 if test $ac_cv_func_getpgrp_void = yes; then
   AC_DEFINE(GETPGRP_VOID, 1,
-            [Define if the `getpgrp' function takes no argument.])
+            [Define if the `getpgrp' function requires zero arguments.])
 fi
 ])# AC_FUNC_GETPGRP
 



More information about the openssh-unix-dev mailing list