From 52610a657cd8ea30f09fe15ec4da59a51a91351a Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Wed, 8 Jan 2025 10:51:49 -0700 Subject: [PATCH] comments --- cloudinit/signal_handler.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cloudinit/signal_handler.py b/cloudinit/signal_handler.py index e65ad1ae845..09209711707 100644 --- a/cloudinit/signal_handler.py +++ b/cloudinit/signal_handler.py @@ -10,6 +10,7 @@ import logging import signal import sys +import types from io import StringIO from typing import Callable, Dict, Final, NamedTuple, Union @@ -37,22 +38,24 @@ class ExitBehavior(NamedTuple): SIGNAL_EXIT_BEHAVIOR = SIGNAL_EXIT_BEHAVIOR_CRASH -def default_handler(_num, _stack) -> None: - """an empty handler""" - return None - - def inspect_handler(sig: Union[int, Callable, None]) -> None: """inspect_handler() logs signal handler state""" - # only produce a log if the signal handler isn't in the expected default - # state: SIG_DFL - if sig == signal.SIG_IGN: + if callable(sig): + # only produce a log when the signal handler isn't in the expected + # default state + if isinstance(sig, types.BuiltinFunctionType): + LOG.info("Signal state [%s] - previously custom handler.", sig) + elif sig == signal.SIG_IGN: LOG.info("Signal state [SIG_IGN] - previously ignored.") elif sig is None: LOG.info("Signal state [None] - previously not installed from Python.") - elif callable(sig): - LOG.info("Signal state [%s] - custom handler.", sig) elif sig != signal.SIG_DFL: + LOG.info( + "Signal state [%s] - default way of handling signal was " + "previously in use.", + sig + ) + else: # this should never happen, unless something in Python changes # https://docs.python.org/3/library/signal.html#signal.getsignal LOG.warning("Signal state [%s(%s)] - unknown", type(sig), sig)