/usr/lib/python3/dist-packages/cloudinit
NameSizeModeActions
analyze/-0755rm
cmd/-0755rm
config/-0755rm
distros/-0755rm
filters/-0755rm
handlers/-0755rm
log/-0755rm
mergers/-0755rm
net/-0755rm
reporting/-0755rm
sources/-0755rm
__pycache__/-0755rm
apport.py84960644editdlrm
atomic_helper.py28600644editdlrm
cloud.py32960644editdlrm
dmi.py80020644editdlrm
event.py20510644editdlrm
features.py57630644editdlrm
gpg.py81860644editdlrm
helpers.py165470644editdlrm
importer.py24850644editdlrm
lifecycle.py79790644editdlrm
netinfo.py246460644editdlrm
performance.py31750644editdlrm
persistence.py25830644editdlrm
registry.py10220644editdlrm
safeyaml.py103490644editdlrm
settings.py21720644editdlrm
signal_handler.py30270644editdlrm
simpletable.py19760644editdlrm
socket.py59910644editdlrm
ssh_util.py229830644editdlrm
stages.py425260644editdlrm
subp.py126580644editdlrm
templater.py79300644editdlrm
temp_utils.py30130644editdlrm
type_utils.py7030644editdlrm
url_helper.py391640644editdlrm
user_data.py147840644editdlrm
util.py929070644editdlrm
version.py5640644editdlrm
warnings.py38530644editdlrm
__init__.py00644editdlrm
Edit: /usr/lib/python3/dist-packages/cloudinit/signal_handler.py (3027B)
# Copyright (C) 2012 Canonical Ltd. # Copyright (C) 2012 Yahoo! Inc. # # Author: Scott Moser # Author: Joshua Harlow # # This file is part of cloud-init. See LICENSE file for license information. import inspect import logging import signal import sys import types from io import StringIO from typing import Callable, Dict, Final, Union from cloudinit import version as vr from cloudinit.log import log_util LOG = logging.getLogger(__name__) SIG_MESSAGE: Final = "Cloud-init {} received {}, exiting\n" BACK_FRAME_TRACE_DEPTH: Final = 3 SIGNALS: Final[Dict[int, str]] = { signal.SIGINT: "Cloud-init %(version)s received SIGINT, exiting", signal.SIGTERM: "Cloud-init %(version)s received SIGTERM, exiting", signal.SIGABRT: "Cloud-init %(version)s received SIGABRT, exiting", } def inspect_handler(sig: Union[int, Callable, None]) -> None: """inspect_handler() logs signal handler state""" if callable(sig): # only produce a log when the signal handler isn't in the expected # default state if not 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 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) def _pprint_frame(frame, depth, max_depth, contents): if depth > max_depth or not frame: return frame_info = inspect.getframeinfo(frame) prefix = " " * (depth * 2) contents.write("%sFilename: %s\n" % (prefix, frame_info.filename)) contents.write("%sFunction: %s\n" % (prefix, frame_info.function)) contents.write("%sLine number: %s\n" % (prefix, frame_info.lineno)) _pprint_frame(frame.f_back, depth + 1, max_depth, contents) def _handle_exit(signum, frame): # in practice we always receive a Signals object but int is possible name = signum.name if isinstance(signum, signal.Signals) else signum contents = StringIO(SIG_MESSAGE.format(vr.version_string(), name)) _pprint_frame(frame, 1, BACK_FRAME_TRACE_DEPTH, contents) log_util.multi_log( f"Received signal {name} resulting in exit. Cause:\n" + contents.getvalue(), log=LOG, log_level=logging.INFO, ) sys.exit(0) def attach_handlers(): """attach cloud-init's handlers""" sigs_attached = 0 for signum in SIGNALS.keys(): inspect_handler(signal.signal(signum, _handle_exit)) sigs_attached += len(SIGNALS) return sigs_attached