fix daemon and add fastopen tests

This commit is contained in:
clowwindy 2014-12-22 17:58:12 +08:00
parent 072afd68f2
commit 5ea8403e56
4 changed files with 14 additions and 9 deletions

View file

@ -100,19 +100,21 @@ def freopen(f, mode, stream):
def daemon_start(pid_file, log_file):
# fork only once because we are sure parent will exit
pid = os.fork()
assert pid != -1
def handle_exit(signum, _):
if signum == signal.SIGTERM:
sys.exit(0)
sys.exit(1)
signal.signal(signal.SIGINT, handle_exit)
signal.signal(signal.SIGTERM, handle_exit)
# fork only once because we are sure parent will exit
pid = os.fork()
assert pid != -1
if pid > 0:
# parent waits for its child
signal.signal(signal.SIGINT, handle_exit)
signal.signal(signal.SIGTERM, handle_exit)
time.sleep(5)
sys.exit(0)
@ -135,7 +137,6 @@ def daemon_start(pid_file, log_file):
freopen(log_file, 'a', sys.stderr)
except IOError as e:
logging.error(e)
os.kill(ppid, signal.SIGINT)
sys.exit(1)