This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

initgroups change to use sysconf for NGROUPS_MAX


This change makes initgroups use sysconf(_SC_NGROUPS_MAX) even when the
NGROUPS_MAX constant is available at compile time.  (Other places in libc I
have found are already appropriately dynamic.)  This has been a problem for
people who configure their kernels with a limit larger than the default but
who don't want to have to rebuild libc themselves as well (of course, there
may well be program binaries that compiled in NGROUPS_MAX lying it wait for
these people, but at least libc doesn't have to be part of the problem).
(It's also notable that on the Hurd, though there is no actual limit, we
are required by POSIX.1 to define NGROUPS_MAX to some constant (we chose
256), and so initgroups has hitherto been imposing that compile-time limit,
though the code is already prepared to be fully dynamic when sysconf
returns -1.)

The second change here should have no effect, it just removes cruft.  But
the presence of the cruft deluded me into thinking I needed to fix this
code too, even though the current version is not using the relevant values
at all.  Cruft removal is good.


2001-04-16  Roland McGrath  <roland@frob.com>

	* grp/initgroups.c (initgroups) [NGROUPS_MAX != 0]: Always use sysconf
	instead of the constant NGROUPS_MAX.  That way, the limit can be
	raised in the kernel configuration without having to recompile libc.

	* sysdeps/posix/euidaccess.c: Don't #include <limits.h> or try to
	define NGROUPS_MAX; we don't use it here.


Index: grp/initgroups.c
===================================================================
RCS file: /cvs/glibc/libc/grp/initgroups.c,v
retrieving revision 1.23
diff -u -r1.23 initgroups.c
--- initgroups.c	2000/08/24 07:56:05	1.23
+++ initgroups.c	2001/04/17 00:29:16
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989, 91, 93, 1996-1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1989,91,93,1996-1999,2000,01 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -158,21 +158,21 @@
   /* Start is one, because we have the first group as parameter.  */
   long int start = 1;
   long int size;
-  long int limit;
   gid_t *groups;
   int result;
-#ifdef NGROUPS_MAX
-  size = NGROUPS_MAX;
-  limit = -1;
-#else
+
+  /* We always use sysconf even if NGROUPS_MAX is defined.  That way, the
+     limit can be raised in the kernel configuration without having to
+     recompile libc.  */
   long int limit = __sysconf (_SC_NGROUPS_MAX);
 
   if (limit > 0)
     size = limit;
   else
-    /* No fixed limit on groups.  Pick a starting buffer size.  */
-    size = 16;
-#endif
+    {
+      /* No fixed limit on groups.  Pick a starting buffer size.  */
+      size = 16;
+    }
 
   groups = (gid_t *) malloc (size * sizeof (gid_t));
   if (__builtin_expect (groups == NULL, 0))
Index: sysdeps/posix/euidaccess.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/posix/euidaccess.c,v
retrieving revision 1.9
diff -u -r1.9 euidaccess.c
--- euidaccess.c	2000/09/01 02:24:08	1.9
+++ euidaccess.c	2001/04/17 00:29:16
@@ -1,5 +1,5 @@
 /* Check if effective user id can access file
-   Copyright (C) 1990,91,95,96,97,98,99,2000 Free Software Foundation, Inc.
+   Copyright (C) 1990,91,95,96,97,98,99,2000,01 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -43,22 +43,11 @@
 #include <unistd.h>
 #endif
 
-#ifdef _POSIX_VERSION
-#include <limits.h>
-#if !defined(NGROUPS_MAX) || NGROUPS_MAX < 1
-#undef NGROUPS_MAX
-#define NGROUPS_MAX sysconf (_SC_NGROUPS_MAX)
-#endif /* NGROUPS_MAX */
-
-#else /* not _POSIX_VERSION */
+#ifndef _POSIX_VERSION
 uid_t getuid ();
 gid_t getgid ();
 uid_t geteuid ();
 gid_t getegid ();
-#include <sys/param.h>
-#if !defined(NGROUPS_MAX) && defined(NGROUPS)
-#define NGROUPS_MAX NGROUPS
-#endif /* not NGROUPS_MAX and NGROUPS */
 #endif /* not POSIX_VERSION */
 
 #include <errno.h>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]