zedshaw/python-lust — pull request #9 by shabbyrobe (2013-03-19 05:22:51+00:00)
Title: Caches user id and group id on startup. pwd.getpwnam() and grp.getgrnam() were not working after chroot on ubuntu or centos

Using 1.0.3, the following daemon would fail:

```py
import sys
import time
from lust import log, server

class TestDaemon(server.Simple):
def start(self, args):
time.sleep(30)

def shutdown(self, signal):
log.info("Shutting down now signal: %d" % signal)

if __name__ == "__main__":
server = TestDaemon("testd", uid='nobody', gid='nogroup', log_dir='/tmp')
server.run(sys.argv)
```

Exception:
```
KeyError: 'getpwnam(): name not found: nobody'
```

The user ID lookup happening in `drop_privileges` was failing after the `chroot`, so I moved it to the server startup. Not sure if this fits in with the project's style or goals, or if it's even a good solution, but lust now works great for me with this change so hopefully it's useful.