This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: NGROUPS_MAX in linux 2.6.3+
- From: Tim Hockin <thockin at sun dot com>
- To: Ulrich Drepper <drepper at redhat dot com>
- Cc: Andreas Jaeger <aj at suse dot de>, "GNU C. Library" <libc-alpha at sources dot redhat dot com>
- Date: Wed, 25 Feb 2004 17:33:45 -0800
- Subject: Re: NGROUPS_MAX in linux 2.6.3+
- References: <20040219212025.GE9155@sun.com> <20040224223909.GJ18498@sun.com> <howu6bvcd2.fsf@reger.suse.de> <403C597F.3000906@redhat.com>
- Reply-to: thockin at sun dot com
On Wed, Feb 25, 2004 at 12:14:55AM -0800, Ulrich Drepper wrote:
> So, rewrite the code to use open+read+strtol (don't even thing about
> fopen+fscanf). Replace the default case with a simple break, move the
> posix_sysconf call to the end of the function, and return from the
> special NGROUPS handling only if reading the file was successful.
> Otherwise fall through to the posix_sysconf call. Oh, and since you'll
> use /proc there is no need for any #ifdef.
more like this?
Index: sysdeps/unix/sysv/linux/sysconf.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/sysconf.c,v
retrieving revision 1.9
diff -u -u -r1.9 sysconf.c
--- sysdeps/unix/sysv/linux/sysconf.c 27 Mar 2003 17:55:08 -0000 1.9
+++ sysdeps/unix/sysv/linux/sysconf.c 26 Feb 2004 01:10:06 -0000
@@ -27,6 +27,7 @@
#define __sysconf static posix_sysconf
#include <sysdeps/posix/sysconf.c>
+#define NGROUPS_MAX_SYSCTL_FILE "/proc/sys/kernel/ngroups_max"
/* Get the value of the system variable NAME. */
long int
@@ -46,7 +47,33 @@
}
#endif
+ case _SC_NGROUPS_MAX:
+ {
+ int fd;
+
+ fd = open (NGROUPS_MAX_SYSCTL_FILE, O_RDONLY);
+ if (fd >= 0)
+ {
+ char buf[32];
+ int r;
+
+ r = read (fd, buf, sizeof (buf) - 1);
+ close (fd);
+ if (r > 0)
+ {
+ long ngroups_max;
+ char *endp;
+
+ buf[r] = '\0';
+ ngroups_max = strtol (buf, &endp, 10);
+ if (*endp = '\0' && ngroups_max >= 0)
+ return (int) ngroups_max;
+ }
+ }
+ }
+
default:
- return posix_sysconf (name);
}
+
+ return posix_sysconf (name);
}
--
Tim Hockin
Sun Microsystems, Linux Software Engineering
thockin@sun.com
All opinions are my own, not Sun's