aboutsummaryrefslogtreecommitdiffstats
path: root/bin/check_perms
diff options
context:
space:
mode:
authorbwarsaw <>2004-07-06 01:04:29 +0000
committerbwarsaw <>2004-07-06 01:04:29 +0000
commit72deb49e2c140f240943450be4dd93f68d34bd02 (patch)
treeb45139c6327e3632422e8de916852e9d59eed8e4 /bin/check_perms
parent69ec6967f77d227551f2cc1cd85458f1da4088bc (diff)
downloadmailman2-72deb49e2c140f240943450be4dd93f68d34bd02.tar.gz
mailman2-72deb49e2c140f240943450be4dd93f68d34bd02.tar.xz
mailman2-72deb49e2c140f240943450be4dd93f68d34bd02.zip
getgrgid(), checkwalk(): cache the results of grp.getgrgid() so things go much
faster. (At least some) libc getgrgid() opens /etc/group for every query.
Diffstat (limited to '')
-rwxr-xr-xbin/check_perms17
1 files changed, 14 insertions, 3 deletions
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 = '<anon gid %d>' % gid
arg.ERRORS += 1