Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/pynslcd
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2013-07-26 14:26:55 +0200
committerArthur de Jong <arthur@arthurdejong.org>2013-07-26 14:26:55 +0200
commit6054499f9a9952593ccadc83182e01d39ff62f12 (patch)
tree74b61921f9bcbf780863060971a2bf280a9fd5c3 /pynslcd
parentd2e2e400e79c94c2e60f21ec61811dfe948924cc (diff)
Allow invalidating the nfsidmap cache
This introduces an nfsidmap value for nscd_invalidate which will cause the nfsidmap -c command to be run.
Diffstat (limited to 'pynslcd')
-rw-r--r--pynslcd/cfg.py2
-rw-r--r--pynslcd/nscd.py32
2 files changed, 18 insertions, 16 deletions
diff --git a/pynslcd/cfg.py b/pynslcd/cfg.py
index a9f1d89..516eeb7 100644
--- a/pynslcd/cfg.py
+++ b/pynslcd/cfg.py
@@ -317,7 +317,7 @@ def read(filename):
if m:
dbs = re.split('[ ,]+', m.group('value').lower())
for db in dbs:
- if db not in maps:
+ if db not in maps.keys() + ['nfsidmap']:
raise ParseError(filename, lineno, 'map %s unknown' % db)
nscd_invalidate.update(dbs)
continue
diff --git a/pynslcd/nscd.py b/pynslcd/nscd.py
index acee9a9..1cc05cf 100644
--- a/pynslcd/nscd.py
+++ b/pynslcd/nscd.py
@@ -34,31 +34,31 @@ signalfd = None
_db_to_char = dict(
aliases='A', ethers='E', group='G', hosts='H', netgroup='U',
networks='N', passwd='P', protocols='L', rpc='R', services='V',
- shadow='S',
+ shadow='S', nfsidmap='F',
)
_char_to_db = dict((reversed(item) for item in _db_to_char.items()))
-def exec_invalidate(db):
- logging.debug('nscd_invalidator: nscd -i %s', db)
+def exec_invalidate(*args):
+ cmd = ' '.join(args)
+ logging.debug('nscd_invalidator: %s', cmd)
try:
- p = subprocess.Popen(['nscd', '-i', db],
- bufsize=4096, close_fds=True,
+ p = subprocess.Popen(args, bufsize=4096, close_fds=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, ignored = p.communicate()
if output:
output = ': %s' % output[:1024].strip()
if p.returncode == 0:
- logging.debug('nscd_invalidator: nscd -i %s (pid %d) success%s',
- db, p.pid, output)
+ logging.debug('nscd_invalidator: %s (pid %d) success%s',
+ cmd, p.pid, output)
elif p.returncode > 0:
- logging.debug('nscd_invalidator: nscd -i %s (pid %d) failed (%d)%s',
- db, p.pid, p.returncode, output)
+ logging.debug('nscd_invalidator: %s (pid %d) failed (%d)%s',
+ cmd, p.pid, p.returncode, output)
else: # p.returncode < 0
- logging.error('nscd_invalidator: nscd -i %s (pid %d) killed by signal %d%s',
- db, p.pid, -p.returncode, output)
+ logging.error('nscd_invalidator: %s (pid %d) killed by signal %d%s',
+ cmd, p.pid, -p.returncode, output)
except:
- logging.warn('nscd_invalidator: nscd -i %s failed', db, exc_info=True)
+ logging.warn('nscd_invalidator: %s failed', cmd, exc_info=True)
def loop(fd):
@@ -76,8 +76,10 @@ def loop(fd):
if db == '':
break # close process down
db = _char_to_db.get(db, None)
- if db:
- exec_invalidate(db)
+ if db == 'nfsidmap':
+ exec_invalidate('nfsidmap', '-c')
+ else if db:
+ exec_invalidate('nscd', '-i', db)
def start_invalidator():
@@ -107,4 +109,4 @@ def invalidate(db=None):
try:
os.write(signalfd, db)
except:
- logging.warn('nscd_invalidator: nscd -i %s failed', db, exc_info=True)
+ logging.warn('requesting invalidation (%s) failed', db, exc_info=True)