summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortgoodwin <tgoodwin>1998-07-27 13:26:37 +0000
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:23:11 +0100
commitd3102fa7de519677c917beb108a71b81ef9a8abc (patch)
tree2b30aa4eddaf1f9913fe7e2d1f480c67605465c8
parent8a11028b592d1c7a5b408475fdc3028b04ab6ffa (diff)
add RC_FUNC_GETGROUPS configure magic
-rw-r--r--acconfig.h3
-rw-r--r--acinclude.m420
-rw-r--r--configure.ac6
-rw-r--r--which.c12
4 files changed, 36 insertions, 5 deletions
diff --git a/acconfig.h b/acconfig.h
index 62e6542..c00f411 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -72,3 +72,6 @@
/* Define if you have SA_INTERRUPT (and sigaction()). */
#undef HAVE_SA_INTERRUPT
+
+/* Define if you have POSIX getgroups(). */
+#undef HAVE_POSIX_GETGROUPS
diff --git a/acinclude.m4 b/acinclude.m4
index c8913a0..60ec318 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1,3 +1,19 @@
+dnl This macro sets HAVE_POSIX_GETGROUPS if the
+dnl getgroups() function accepts a zero first argument.
+AC_DEFUN(RC_FUNC_GETGROUPS, [
+ AC_CACHE_CHECK(for POSIX getgroups, rc_cv_func_posix_getgroups, AC_TRY_RUN([
+#include <sys/types.h>
+#include <unistd.h>
+int main(void) {
+ return getgroups(0, (void *)0) == -1;
+}
+ ], rc_cv_func_posix_getgroups=yes, rc_cv_func_posix_getgroups=no, rc_cv_func_posix_getgroups=yes))
+ case "$rc_cv_func_posix_getgroups" in
+ yes) AC_DEFINE(HAVE_POSIX_GETGROUPS) ;;
+ esac
+])
+
+
dnl The AC_FUNC_SETPGRP macro doesn't
dnl #include <unistd.h>, so it fails on OSF-1, where setpgrp
dnl will happily accept arguments, but the protoype doesn't
@@ -7,7 +23,9 @@ AC_DEFUN(RC_FUNC_SETPGRP, [
AC_CACHE_CHECK(for setpgrp that takes no arguments, ac_cv_func_setpgrp_void, AC_TRY_RUN([
#include <unistd.h>
/* If setpgrp() takes no arguments, this may fail to compile, but
-if it compiles the call should succeed. */
+if it compiles the call should succeed. Note that the assignments
+to ac_cv_func_setpgrp_void are the other way round from what you
+would expect. */
int main(void) {
return setpgrp(1,1) != -1;
}
diff --git a/configure.ac b/configure.ac
index 2d48ed4..c0f2261 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,12 +1,12 @@
AC_INIT(rc.h)
dnl Automake stuff.
-AM_INIT_AUTOMAKE(rc, 1.5s19980724)
+AM_INIT_AUTOMAKE(rc, 1.5s19980727)
AM_CONFIG_HEADER(config.h)
AC_ARG_PROGRAM
-AC_DEFINE(RELDATE, "1998-07-24")
+AC_DEFINE(RELDATE, "1998-07-27")
dnl If we're using gcc, specify `-Wall'. I've also checked the code
dnl with `-pedantic -W -Wall -Wpointer-arith -Wstrict-prototypes
@@ -36,7 +36,7 @@ AC_TYPE_UID_T
AC_CHECK_TYPE(ssize_t, long)
AC_CHECK_FUNCS(getgroups setpgrp setrlimit)
-
+RC_FUNC_GETGROUPS
dnl sigsetjmp() isn't a real function in some places.
AC_CACHE_CHECK(for sigsetjmp, rc_cv_sigsetjmp,
diff --git a/which.c b/which.c
index c4bbc29..3d23e3d 100644
--- a/which.c
+++ b/which.c
@@ -8,10 +8,12 @@
and to strip out unneeded functionality.
*/
-#include "rc.h"
#include <errno.h>
#include <sys/stat.h>
+#include "rc.h"
+#include "getgroups.h"
+
#define X_USR 0100
#define X_GRP 0010
#define X_OTH 0001
@@ -83,7 +85,15 @@ extern char *which(char *name, bool verbose) {
uid = geteuid();
gid = getegid();
#if HAVE_GETGROUPS
+#if HAVE_POSIX_GETGROUPS
ngroups = getgroups(0, (GETGROUPS_T *)0);
+ if (ngroups < 0) {
+ uerror("getgroups");
+ rc_exit(1);
+ }
+#else
+ ngroups = NGROUPS;
+#endif
gidset = ealloc(ngroups * sizeof(GETGROUPS_T));
getgroups(ngroups, gidset);
#endif