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
75
76
77
78
79
80
81
82
83
84
85
//! Shutdown-signal handling, which is the one place this CLI is platform
//! code.
//!
//! Its own module because it is the only thing here that differs between
//! Unix and Windows, and because `main.rs` should read as argument parsing
//! and printing — which is what it claims to be.
/// A shutdown-signal listener that outlives `park`.
///
/// tokio installs its handler on first use and documents that it stays
/// installed for the life of the process — "even if this `Signal` instance
/// is dropped, subsequent SIGINT deliveries will end up captured by Tokio,
/// and the default platform behavior will NOT be reset". So a `park` that
/// created its own listener and returned left every later signal going
/// nowhere: the first one entered `shutdown`, and if that took a while the
/// operator's only remaining option was `kill -9` from another terminal.
/// Keeping one listener alive across both phases is what makes the second
/// signal mean something.
///
/// **On Unix that means SIGINT and SIGTERM alike.** Ctrl-C is what a person
/// at a terminal sends; SIGTERM is what everything else sends — `kill` with
/// no argument, systemd stopping a unit, Docker stopping a container. Both
/// mean "stop", so both get the drain that lets an admitted request finish.
/// Handling only the first left the case that matters most under a service
/// manager taking the default disposition instead: immediate death, every
/// in-flight response cut mid-body. The two arrive as separate streams and
/// are merged here, so which one was sent never reaches the rest of the CLI
/// — the phase an interrupt lands in is what decides its meaning, not its
/// number.
///
/// The platform types are the same idea under different names — a stream
/// that yields once per signal — which is why the whole difference fits in
/// the fields and the constructor. What is *not* interchangeable is
/// `tokio::signal::ctrl_c()`: it is a one-shot future, and the second
/// signal is the one that matters here.
pub