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
use ;
use RawFd;
use id;
const LISTEN_PID: &str = "LISTEN_PID";
const LISTEN_FDS: &str = "LISTEN_FDS";
const LISTEN_FDNAMES: &str = "LISTEN_FDNAMES";
/// Minimum file descriptor used by systemd.
/// See <https://github.com/systemd/systemd/blob/v254/src/systemd/sd-daemon.h#L56>.
const SD_LISTEN_FDS_START: RawFd = 3;
/// Checks whether *at most one* file descriptor with given name was passed, returning it.
/// systemd sending none, more than one, or a file descriptor with a different name, all
/// results in [`Option::None`], but errors decoding environment variables or missing
/// environment variables will error.
/// This is a specialization of [`sd_listen_fds_with_names(3)`](man:sd_listen_fds_with_names(3)).
/// See:
/// - <https://www.freedesktop.org/software/systemd/man/254/sd_listen_fds_with_names.html>
/// - <https://github.com/systemd/systemd/blob/v254/src/libsystemd/sd-daemon/sd-daemon.c>
/// - <https://0pointer.de/blog/projects/socket-activation.html>
/// - <https://0pointer.de/blog/projects/socket-activation2.html>
///
/// # Safety
///
/// This function calls [`remove_var`] to remove the environment variables
/// it interpreted in case it returns `Ok(Some(_))`. In this case, this
/// function inherits the unsafe behavior of [`remove_var`].
pub unsafe