From 72deb49e2c140f240943450be4dd93f68d34bd02 Mon Sep 17 00:00:00 2001 From: bwarsaw <> Date: Tue, 6 Jul 2004 01:04:29 +0000 Subject: getgrgid(), checkwalk(): cache the results of grp.getgrgid() so things go much faster. (At least some) libc getgrgid() opens /etc/group for every query. --- bin/check_perms | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/check_perms b/bin/check_perms index 4f976b06..5c8ce415 100755 --- a/bin/check_perms +++ b/bin/check_perms @@ -1,6 +1,6 @@ #! @PYTHON@ # -# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc. +# Copyright (C) 1998-2004 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -23,7 +23,6 @@ Usage: %(PROGRAM)s [-f] [-v] [-h] With no arguments, just check and report all the files that have bogus permissions or group ownership. With -f (and run as root), fix all the permission problems found. With -v be verbose. - """ import os @@ -86,6 +85,18 @@ def statgidmode(path): seen = {} +# libc's getgrgid re-opens /etc/group each time :( +_gidcache = {} + +def getgrgid(gid): + data = _gidcache.get(gid) + if data is None: + data = grp.getgrgid(gid) + _gidcache[gid] = data + return data + + + def checkwalk(arg, dirname, names): # Short-circuit duplicates if seen.has_key(dirname): @@ -102,7 +113,7 @@ def checkwalk(arg, dirname, names): continue if gid <> MAILMAN_GID: try: - groupname = grp.getgrgid(gid)[0] + groupname = getgrgid(gid)[0] except KeyError: groupname = '' % gid arg.ERRORS += 1 -- cgit v1.2.3