1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Termination signals, routed into the one orderly stop the supervisor has.
//!
//! There is no graph to tear down: this process started nothing. An orderly
//! stop is closing the control plane, the bus session, and the embedded router,
//! in that order, and exiting 0. Nothing here records a failure, because being
//! asked to stop is not one.
//!
//! Handling the signal at all still matters. Under the default disposition of
//! SIGTERM the process would die where it stands, taking the router down
//! without closing it: every participant would lose its links to a socket that
//! vanished mid-session rather than to a router that finished with them, and
//! the lock and socket the next run needs would be left behind.
//!
//! The handler comes from `ctrlc` with its `termination` feature, which covers
//! SIGINT, SIGTERM, and SIGHUP in one registration: SIGTERM is what a service
//! manager and a `kill` send, SIGINT is the interactive form of the same
//! request, and SIGHUP arrives when the terminal that launched a foreground
//! supervisor goes away - all three leave the graph with no owner, so all
//! three mean stop rather than continue headless.
use ;
use CancellationToken;
/// Register the termination handler now, and cancel `shutdown` on the first
/// signal that arrives.
///
/// Registration is deliberately fallible and eager: a supervisor that cannot
/// install the handler has no orderly stop at all, which is a startup
/// precondition rather than a warning, and installing it before anything is
/// launched means a startup-time signal is caught rather than lethal.
///
/// A second signal while the stop is already in flight does nothing extra: the
/// token is already cancelled, and what is left is bounded transport close, so
/// there is nothing an impatient repeat could usefully shorten. SIGKILL remains
/// the operator's escape hatch, as always.
pub
/// SIGHUP stands in for the whole set: `ctrlc`'s `termination` feature
/// registers the three signals in one call, and it is the one signal no test
/// harness raises on its own, so the test binary cannot mistake a stray SIGTERM
/// for this one. The handler is installed before the signal is raised, so this
/// process catches it instead of dying under the default disposition.