glibc-2.3.6 on Linux-2.4.x/i386 makes a useless system call when the getgroups() function is called. Test program: =================================================================== #include <sys/types.h> #include <unistd.h> int main () { gid_t buf[10]; getgroups (10, buf); return 0; } =================================================================== strace shows: open("/proc/sys/kernel/ngroups_max", O_RDONLY) = -1 ENOENT (No such file or directory) getgroups32(0xa, 0xbfffe4c0) = 3 This open() call, coming from a __sysconf() call, is useless, because the getgroups32 system call exists; there is no need to allocate a kernel_groups[] array since there is no translation to do. Proposed fix (untested): 2006-11-18 Bruno Haible <bruno@clisp.org> * sysdeps/unix/sysv/linux/i386/getgroups.c (__getgroups): Invoke __sysconf only after having tried to call getgroups32. --- sysdeps/unix/sysv/linux/i386/getgroups.c.bak 2003-09-03 05:21:27.000000000 +0200 +++ sysdeps/unix/sysv/linux/i386/getgroups.c 2006-11-18 15:35:59.000000000 +0100 @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998, 2000, 2001, 2003 Free Software Foundation, Inc. +/* Copyright (C) 1997, 1998, 2000, 2001, 2003, 2006 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 @@ -52,8 +52,6 @@ } else { - int i, ngids; - __kernel_gid_t kernel_groups[n = MIN (n, __sysconf (_SC_NGROUPS_MAX))]; # ifdef __NR_getgroups32 if (__libc_missing_32bit_uids <= 0) { @@ -69,6 +67,9 @@ } # endif /* __NR_getgroups32 */ + int i, ngids; + __kernel_gid_t kernel_groups[n = MIN (n, __sysconf (_SC_NGROUPS_MAX))]; + ngids = INLINE_SYSCALL (getgroups, 2, n, CHECK_N (kernel_groups, n)); if (n != 0 && ngids > 0) for (i = 0; i < ngids; i++)
Created attachment 1428 [details] fix
Applied to trunk.