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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: NGROUPS_MAX in linux 2.6.3+


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


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