/
snap
/
core20
/
2769
/
usr
/
lib
/
python3
/
dist-packages
/
cloudinit
/
/snap/core20/2769/usr/lib/python3/dist-packages/cloudinit
mkdir
upload
Name
Size
Mode
Actions
analyze/
-
0755
rm
cmd/
-
0755
rm
config/
-
0755
rm
distros/
-
0755
rm
filters/
-
0755
rm
handlers/
-
0755
rm
log/
-
0755
rm
mergers/
-
0755
rm
net/
-
0755
rm
reporting/
-
0755
rm
sources/
-
0755
rm
__pycache__/
-
0755
rm
apport.py
8466
0644
edit
dl
rm
atomic_helper.py
2860
0644
edit
dl
rm
cloud.py
3296
0644
edit
dl
rm
dmi.py
8050
0644
edit
dl
rm
event.py
2051
0644
edit
dl
rm
features.py
5403
0644
edit
dl
rm
gpg.py
8186
0644
edit
dl
rm
helpers.py
16547
0644
edit
dl
rm
importer.py
2485
0644
edit
dl
rm
lifecycle.py
7979
0644
edit
dl
rm
netinfo.py
24598
0644
edit
dl
rm
performance.py
3175
0644
edit
dl
rm
persistence.py
2583
0644
edit
dl
rm
registry.py
1022
0644
edit
dl
rm
safeyaml.py
10349
0644
edit
dl
rm
settings.py
2172
0644
edit
dl
rm
signal_handler.py
4014
0644
edit
dl
rm
simpletable.py
1976
0644
edit
dl
rm
socket.py
6068
0644
edit
dl
rm
ssh_util.py
22750
0644
edit
dl
rm
stages.py
42526
0644
edit
dl
rm
subp.py
12729
0644
edit
dl
rm
templater.py
7990
0644
edit
dl
rm
temp_utils.py
3013
0644
edit
dl
rm
type_utils.py
703
0644
edit
dl
rm
url_helper.py
39076
0644
edit
dl
rm
user_data.py
14784
0644
edit
dl
rm
util.py
92598
0644
edit
dl
rm
version.py
573
0644
edit
dl
rm
warnings.py
3853
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
Edit:
/snap/core20/2769/usr/lib/python3/dist-packages/cloudinit/signal_handler.py
(4014B)
# Copyright (C) 2012 Canonical Ltd. # Copyright (C) 2012 Yahoo! Inc. # # Author: Scott Moser <scott.moser@canonical.com> # Author: Joshua Harlow <harlowja@yahoo-inc.com> # # This file is part of cloud-init. See LICENSE file for license information. import contextlib import inspect import logging import signal import sys import threading import types from io import StringIO from typing import Callable, Dict, Final, NamedTuple, 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", } class ExitBehavior(NamedTuple): exit_code: int log_level: int SIGNAL_EXIT_BEHAVIOR_CRASH: Final = ExitBehavior(1, logging.ERROR) SIGNAL_EXIT_BEHAVIOR_QUIET: Final = ExitBehavior(0, logging.INFO) _SIGNAL_EXIT_BEHAVIOR = SIGNAL_EXIT_BEHAVIOR_CRASH _SUSPEND_WRITE_LOCK = threading.RLock() 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( contents.getvalue(), log=LOG, log_level=_SIGNAL_EXIT_BEHAVIOR.log_level ) sys.exit(_SIGNAL_EXIT_BEHAVIOR.exit_code) 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 @contextlib.contextmanager def suspend_crash(): """suspend_crash() allows signals to be received without exiting 1 This allow signal handling without a crash where it is expected. The call stack is still printed if signal is received during this context, but the return code is 0 and no traceback is printed. Threadsafe. """ global _SIGNAL_EXIT_BEHAVIOR # If multiple threads simultaneously were to modify this # global state, this function would not behave as expected. with _SUSPEND_WRITE_LOCK: _SIGNAL_EXIT_BEHAVIOR = SIGNAL_EXIT_BEHAVIOR_QUIET yield _SIGNAL_EXIT_BEHAVIOR = SIGNAL_EXIT_BEHAVIOR_CRASH
Save
cmd:
run