diff --git a/khepri.py b/khepri.py index 13c9870..81be6f5 100755 --- a/khepri.py +++ b/khepri.py @@ -3,6 +3,7 @@ import sys, logging import tftpy import re +import signal LEASES_FILE = "/var/lib/dhcp/dhcpd.leases" @@ -51,6 +52,14 @@ def hook(pattern, match_mac=None): import hooks def main(): + def sighup_handler(signum, frame): + signal.siginterrupt(signal.SIGHUP, False) + sys.stderr.write("Reloading config...\n") + sys.stderr.flush() + file_hooks = {} + reload(hooks) + + signal.signal(signal.SIGHUP, sighup_handler) server = tftpy.TftpServer("/var/khepri/tftp-root/", dyn_file_func=hook_dispatcher) try: server.listen("10.8.1.1", 5000) @@ -59,4 +68,3 @@ def main(): sys.exit(1) except KeyboardInterrupt: pass - diff --git a/tftpy/TftpServer.py b/tftpy/TftpServer.py index f91d897..8feb287 100644 --- a/tftpy/TftpServer.py +++ b/tftpy/TftpServer.py @@ -5,11 +5,22 @@ TftpShared.""" import socket, os, time import select +import signal +import errno from TftpShared import * from TftpPacketTypes import * from TftpPacketFactory import TftpPacketFactory from TftpContexts import TftpContextServer +def until_concludes(f, *a, **kw): + while True: + try: + return f(*a, **kw) + except (IOError, OSError, select.error), e: + if e.args[0] == errno.EINTR: + continue + raise + class TftpServer(TftpSession): """This class implements a tftp server object. Run the listen() method to listen for client requests. It takes two optional arguments. tftproot is @@ -81,7 +92,7 @@ class TftpServer(TftpSession): # Block until some socket has input on it. log.debug("Performing select on this inputlist: %s" % inputlist) - readyinput, readyoutput, readyspecial = select.select(inputlist, + readyinput, readyoutput, readyspecial = until_concludes(select.select, inputlist, [], [], SOCK_TIMEOUT)