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
//! Atomic pidfile writer with RAII cleanup.
//!
//! Per AD-012 + HINT-010 + FR-030 this module exposes
//! [`PidfileGuard`] — a Drop guard that removes the pidfile on supervisor
//! termination (clean exit, SIGTERM, panic via stack unwinding) so a
//! restarted supervisor never sees a stale pidfile from this run.
//!
//! The pidfile contents are written atomically (tempfile + rename) via
//! the `atomicwrites` crate so a process crash mid-write does not leave a
//! truncated/empty pidfile behind.
//!
//! Documented limitation: SIGKILL to the supervisor leaves a stale
//! pidfile (Drop cannot run). Matches upstream `autossh` behavior;
//! enumerated in `COMPATIBILITY.md`.
use Write;
use ;
use ;
use crateAutosshError;
/// RAII guard for the pidfile.
///
/// Removes the pidfile on `Drop`. Cleanup runs on clean exit, SIGTERM
/// (the runtime's shutdown path drops the guard), and panic via stack
/// unwinding. Does NOT run on SIGKILL.
/// Write the supervisor PID atomically to `path`.
///
/// Uses `atomicwrites::AtomicFile` with `AllowOverwrite::Yes` so a stale
/// pidfile from a prior crashed run is replaced cleanly at startup
/// (matches upstream `autossh` — pidfile contention is resolved by
/// overwrite, not by refusal to start).
///
/// Returns a [`PidfileGuard`] whose `Drop` impl removes the file on
/// supervisor termination.