Mercurial > crates > systemd-socket
annotate tests/ordinary.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 | 66c0e10c89fc |
children | cfef4593e207 |
rev | line source |
---|---|
1
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
1 use std::io; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
2 use std::ffi::OsStr; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
3 use std::process::{Command, Child}; |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
4 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
5 mod comm; |
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 enum Test {} |
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 impl comm::Test for Test { |
4
66c0e10c89fc
Support resolving hostnames
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
1
diff
changeset
|
10 const SOCKET_ADDR: &'static str = "localhost:4242"; |
1
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
11 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
12 fn spawn_slave(program_name: &OsStr) -> io::Result<Child> { |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
13 Command::new(program_name) |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
14 .env("SYSTEMD_SOCKET_INTEGRATION_TEST", "slave") |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
15 .spawn() |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
16 } |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
17 } |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
18 |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
19 #[test] |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
20 fn main() { |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
21 comm::main::<Test>(); |
ef8bf41097ac
Added integration tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
diff
changeset
|
22 } |