Mercurial > crates > systemd-socket
comparison tests/comm.rs @ 24:1941e9d9819c
Fix unsound manipulation of env vars
Modifying env vars in multi-threaded process is unsound but this crate
was neither checking the number of threads nor mark its functions as
`unsafe`. This change fixes it by both adding a check and adding an
`unsafe` function that can bypass that check if needed.
| author | Martin Habovstiak <martin.habovstiak@gmail.com> |
|---|---|
| date | Fri, 28 Feb 2025 13:52:31 +0100 |
| parents | 08b37039504b |
| children | cfef4593e207 |
comparison
equal
deleted
inserted
replaced
| 23:729392c49b46 | 24:1941e9d9819c |
|---|---|
| 34 } | 34 } |
| 35 | 35 |
| 36 fn main_slave(addr: &str) { | 36 fn main_slave(addr: &str) { |
| 37 use systemd_socket::SocketAddr; | 37 use systemd_socket::SocketAddr; |
| 38 | 38 |
| 39 // SAFETY: this is the only thread that's going to mess with systemd sockets. | |
| 40 unsafe { | |
| 41 systemd_socket::init_unprotected().unwrap(); | |
| 42 } | |
| 43 | |
| 39 let socket = addr | 44 let socket = addr |
| 40 .parse::<SocketAddr>() | 45 .parse::<SocketAddr>() |
| 41 .expect("failed to parse socket") | 46 .expect("failed to parse socket") |
| 42 .bind() | 47 .bind() |
| 43 .expect("failed to bind"); | 48 .expect("failed to bind"); |
