add some simple error checking at startup

This commit is contained in:
randomuser 2021-07-20 03:31:02 -05:00
parent aab8672229
commit 54a6c6eff9
1 changed files with 12 additions and 7 deletions

19
esgd.py
View File

@ -193,10 +193,15 @@ location = "/tmp/test"
if __name__ == "__main__": if __name__ == "__main__":
switchgrp = grp.getgrnam("nobody").gr_gid switchgrp = grp.getgrnam("nobody").gr_gid
switchusr = pwd.getpwnam("nobody").pw_uid switchusr = pwd.getpwnam("nobody").pw_uid
with socketserver.TCPServer((host, port), GopherHandler) as server: try:
os.setgid(switchgrp) with socketserver.TCPServer((host, port), GopherHandler) as server:
os.seteuid(switchusr) os.setgid(switchgrp)
log.log("switch user successful") os.seteuid(switchusr)
os.chdir(location) log.log("switch user successful")
log.log("change directory successful") os.chdir(location)
server.serve_forever() log.log("change directory successful")
server.serve_forever()
except PermissionError:
log.error("invalid permissions")
except OSError:
log.error("address already in use")