Mercurial > crates > systemd-socket
annotate tests/systemd.rs @ 25:8e20daee41ed
Set CLOEXEC flag on the descriptors
The received systemd descriptors don't have `O_CLOEXEC` set because they
are received over `exec`. Thus if the process executes a child the child
gets polluted with the descriptors.
To prevent this, we set `O_CLOEXEC` during initialization. However this
also required restructuring of the code because `libsystemd` doesn't
provide temporary access to the descriptors - only permanent one. Thus
we have to "validate" the descriptors eagerly. We still store the
invalid ones as errors to make sure the errors get reported accurately.
author | Martin Habovstiak <martin.habovstiak@gmail.com> |
---|---|
date | Fri, 28 Feb 2025 21:11:19 +0100 |
parents | bc76507dd878 |
children | cfef4593e207 |
rev | line source |
---|---|
1
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
1 // This integration test requires presence of systemd-socket-activate |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
2 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
3 use std::io; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
4 use std::ffi::OsStr; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
5 use std::process::{Command, Child}; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
6 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
7 mod comm; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
8 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
9 enum Test {} |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
10 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
11 impl comm::Test for Test { |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
12 const SOCKET_ADDR: &'static str = "systemd://secret_socket_of_satoshi_nakamoto"; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
13 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
14 fn spawn_slave(program_name: &OsStr) -> io::Result<Child> { |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
15 Command::new("systemd-socket-activate") |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
16 .arg("-l") |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
17 .arg("127.0.0.1:4242") |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
18 .arg("--fdname=secret_socket_of_satoshi_nakamoto") |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
19 .arg("--setenv=SYSTEMD_SOCKET_INTEGRATION_TEST=slave") |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
20 .arg(program_name) |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
21 .spawn() |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
22 } |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
23 } |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
24 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
25 #[test] |
16
bc76507dd878
Fixed conditional compilation based on OS
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
13
diff
changeset
|
26 #[cfg_attr(not(all(target_os = "linux", feature = "enable_systemd")), should_panic)] |
1
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
27 fn main() { |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
28 comm::main::<Test>(); |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
29 } |