From 1c7063b80ff18475c6bc6f0ac800e7565b531124 Mon Sep 17 00:00:00 2001 From: Cameron Patrick Date: Sun, 1 Aug 2004 07:31:10 +0000 Subject: [PATCH] more restructuring --- sql-edition/servers/VendServer.py | 38 +++++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index 3c3aee6..9ee8ef1 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -5,6 +5,7 @@ USE_DB = 0 import ConfigParser import sys, os, string, re, pwd, signal +import logging from traceback import print_tb if USE_DB: import pg from time import time, sleep @@ -430,19 +431,30 @@ class VendConfigFile: print "Error reading config file "+config_file+": " + str(e) sys.exit(1) -def do_vend_server(): +def set_stuff_up() + def do_nothing(signum, stack): pass + def stop_server(signum, stack): raise KeyboardInterrupt + signal.signal(signal.SIGHUP, do_nothing) + signal.signal(signal.SIGTERM, stop_server) + signal.signal(signal.SIGINT, stop_server) + options = parse_args() config_opts = VendConfigFile(options.config_file, config_options) + set_up_logging(options) + if options.daemon: become_daemon() - if options.daemon: - dev_null = file('/dev/null') - fd = dev_null.fileno() - os.dup2(fd, 0) - os.dup2(fd, 1) - os.dup2(fd, 2) - if os.fork() != 0: - sys.exit(0) + return options, config_opts +def become_daemon(options): + dev_null = file('/dev/null') + fd = dev_null.fileno() + os.dup2(fd, 0) + os.dup2(fd, 1) + os.dup2(fd, 2) + if os.fork() != 0: + sys.exit(0) + +def do_vend_server(options, config_opts): while True: try: rfh, wfh = connect_to_vend(options, config_opts) @@ -461,14 +473,10 @@ def do_vend_server(): print "Connection died, trying again..." if __name__ == '__main__': - def do_nothing(signum, stack): pass - def stop_server(signum, stack): raise KeyboardInterrupt - signal.signal(signal.SIGHUP, do_nothing) - signal.signal(signal.SIGTERM, stop_server) - signal.signal(signal.SIGINT, stop_server) + options, config_opts = set_stuff_up() while True: try: - do_vend_server() + do_vend_server(options, config_opts) except KeyboardInterrupt: print "Killed by signal." break -- 2.20.1