From 8b49d8b198564d0dae3e40b99b6f9d76188dcda7 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Wed, 26 Jun 2013 09:15:40 -0500 Subject: Revert "Core: properly handle Ctrl-C" This reverts commit 4568c44372c99ba809826e016680da9b881bd8e8. Trying to handle ^c in the core is difficult and can break STDOUT for interactive programs that invoke the core. Signed-off-by: Sol Jerome Conflicts: src/lib/Bcfg2/Server/Core.py src/sbin/bcfg2-test tools/bcfg2-profile-templates.py --- src/lib/Bcfg2/Server/Core.py | 17 ++++------------- src/sbin/bcfg2-test | 17 +++++++++++++++++ tools/bcfg2-profile-templates.py | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index f44634d35..ecd68e1e4 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -2,15 +2,14 @@ implementations inherit from. """ import os -import sys import pwd -import time import atexit -import select -import signal import logging -import inspect +import select +import sys import threading +import time +import inspect import lxml.etree import Bcfg2.settings import Bcfg2.Server @@ -244,14 +243,6 @@ class BaseCore(object): #: The CA that signed the server cert self.ca = setup['ca'] - def hdlr(sig, frame): # pylint: disable=W0613 - """ Handle SIGINT/Ctrl-C by shutting down the core and exiting - properly. """ - self.shutdown() - os._exit(1) # pylint: disable=W0212 - - signal.signal(signal.SIGINT, hdlr) - #: The FAM :class:`threading.Thread`, #: :func:`_file_monitor_thread` self.fam_thread = \ diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test index c33143a04..54ddad6df 100755 --- a/src/sbin/bcfg2-test +++ b/src/sbin/bcfg2-test @@ -5,6 +5,7 @@ without failures""" import os import sys +import signal import fnmatch import logging import Bcfg2.Logger @@ -193,6 +194,21 @@ def run_child(setup, clients, queue): def parse_args(): """ Parse command line arguments. """ optinfo = dict(Bcfg2.Options.TEST_COMMON_OPTIONS) + + +def get_sigint_handler(core): + """ Get a function that handles SIGINT/Ctrl-C by shutting down the + core and exiting properly.""" + + def hdlr(sig, frame): # pylint: disable=W0613 + """ Handle SIGINT/Ctrl-C by shutting down the core and exiting + properly. """ + core.shutdown() + os._exit(1) # pylint: disable=W0212 + + return hdlr + + optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS) optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS) setup = Bcfg2.Options.OptionParser(optinfo) @@ -220,6 +236,7 @@ def parse_args(): logger.warning("Python multiprocessing library not found, running " "with no children") setup['children'] = 0 + signal.signal(signal.SIGINT, get_sigint_handler(core)) if (setup['children'] and ('--with-xunit' in setup['noseopts'] or '--xunit-file' in setup['noseopts'])): diff --git a/tools/bcfg2-profile-templates.py b/tools/bcfg2-profile-templates.py index 93314f1e3..f4069e454 100755 --- a/tools/bcfg2-profile-templates.py +++ b/tools/bcfg2-profile-templates.py @@ -5,6 +5,7 @@ import sys import time import math +import signal import logging import operator import Bcfg2.Logger @@ -17,6 +18,19 @@ def stdev(nums): return math.sqrt(sum((n - mean)**2 for n in nums) / float(len(nums))) +def get_sigint_handler(core): + """ Get a function that handles SIGINT/Ctrl-C by shutting down the + core and exiting properly.""" + + def hdlr(sig, frame): # pylint: disable=W0613 + """ Handle SIGINT/Ctrl-C by shutting down the core and exiting + properly. """ + core.shutdown() + os._exit(1) # pylint: disable=W0212 + + return hdlr + + def main(): optinfo = dict( client=Bcfg2.Options.Option("Benchmark templates for one client", @@ -49,6 +63,7 @@ def main(): logger = logging.getLogger(sys.argv[0]) core = Bcfg2.Server.Core.BaseCore(setup) + signal.signal(signal.SIGINT, get_sigint_handler(core)) logger.info("Bcfg2 server core loaded") core.load_plugins() logger.debug("Plugins loaded") -- cgit v1.2.3-1-g7c22