Catch KeyError on uid and gid conversion

This commit is contained in:
Paul Townsend 2011-08-17 17:16:21 -04:00
commit bc48175929

10
smem
View file

@ -62,13 +62,19 @@ class procdata(object):
if uid == -1: if uid == -1:
return '?' return '?'
if uid not in self._ucache: if uid not in self._ucache:
self._ucache[uid] = pwd.getpwuid(uid)[0] try:
self._ucache[uid] = pwd.getpwuid(uid)[0]
except KeyError:
self._ucache[uid] = uid
return self._ucache[uid] return self._ucache[uid]
def groupname(self, gid): def groupname(self, gid):
if gid == -1: if gid == -1:
return '?' return '?'
if gid not in self._gcache: if gid not in self._gcache:
self._gcache[gid] = pwd.getgrgid(gid)[0] try:
self._gcache[gid] = pwd.getgrgid(gid)[0]
except KeyError:
self._gcache[gid] = gid
return self._gcache[gid] return self._gcache[gid]
class tardata(procdata): class tardata(procdata):