Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Jan 8, 2025
1 parent 0d289e0 commit 52610a6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions cloudinit/signal_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import signal
import sys
import types
from io import StringIO
from typing import Callable, Dict, Final, NamedTuple, Union

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 52610a6

Please sign in to comment.