From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8617 invoked by alias); 20 Nov 2006 16:45:09 -0000 Received: (qmail 8399 invoked by uid 48); 20 Nov 2006 16:45:00 -0000 Date: Mon, 20 Nov 2006 16:45:00 -0000 From: "bruno at clisp dot org" To: glibc-bugs@sources.redhat.com Message-ID: <20061120164459.3544.bruno@clisp.org> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/3544] New: getgroups() makes a useless system call X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2006-11/txt/msg00069.txt.bz2 List-Id: glibc-2.3.6 on Linux-2.4.x/i386 makes a useless system call when the getgroups() function is called. Test program: =================================================================== #include #include 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 * 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++) -- Summary: getgroups() makes a useless system call Product: glibc Version: 2.3.6 Status: NEW Severity: normal Priority: P2 Component: libc AssignedTo: drepper at redhat dot com ReportedBy: bruno at clisp dot org CC: glibc-bugs at sources dot redhat dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://sourceware.org/bugzilla/show_bug.cgi?id=3544 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.