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
//! `moat`: the name OpenMoat's command had up to 0.7.0, kept for a few
//! releases so hooks, scripts and habits that call it keep working.
//!
//! It runs the `openmoat` in its own directory with the same arguments, the
//! same standard streams and the same exit code; on Unix it replaces itself
//! with it. Hooks written by an older `moat init` name this file until
//! `openmoat init` rewrites them, so every failure follows the hook contract:
//! `moat guard` that cannot start `openmoat` exits 2 (deny, ADR-015), any
//! other command 64.
use OsString;
use PathBuf;
use ;
/// Exit codes of `openmoat`'s contract (`exit.rs`).
const DENY: u8 = 2;
const USAGE: u8 = 64;
/// `openmoat` in this executable's directory, when it is a file. The
/// directory is the one the executable really lives in: on macOS
/// `current_exe` is the path it was started by, so a `moat` linked from
/// another directory (`~/bin/moat → …/bin/moat`) would otherwise look beside
/// the link. The link's own directory is the fallback. Windows keeps the path
/// as started: its resolved form (`\\?\C:\…`) is not the one hooks record.
/// Replace this process with `command`; returns only when that failed.
/// Run `command` and exit with its code; returns only when it could not start.