openbsd: implement close_range workaround
Browse files at this commit1fa0338a172a69b05a1a35d55b291693ff1bc29fParent: 8e3e93b1 changed file +16 -3
- src/utils/spawning.rs +16 -3
src/utils/spawning.rsmodified+16 -3
| @@ -213,6 +213,8 @@ mod systemd { | |||
| 213 | pub fn do_spawn(command: &OsStr, mut process: Command) -> Option<Child> { | 213 | pub fn do_spawn(command: &OsStr, mut process: Command) -> Option<Child> { |
| 214 | #[cfg(target_env = "gnu")] | 214 | #[cfg(target_env = "gnu")] |
| 215 | use libc::close_range; | 215 | use libc::close_range; |
| 216 | + #[cfg(target_os = "openbsd")] | ||
| 217 | + use libc::closefrom; | ||
| 216 | 218 | ||
| 217 | #[cfg(not(target_env = "gnu"))] // musl | 219 | #[cfg(not(target_env = "gnu"))] // musl |
| 218 | pub fn close_range(first: libc::c_uint, last: libc::c_uint, flags: libc::c_uint) -> i64 { | 220 | pub fn close_range(first: libc::c_uint, last: libc::c_uint, flags: libc::c_uint) -> i64 { |
| @@ -295,9 +297,20 @@ mod systemd { | |||
| 295 | if let Some(pipe) = pipe_wait_read { | 297 | if let Some(pipe) = pipe_wait_read { |
| 296 | // We're going to exit afterwards. Close all other FDs to allow | 298 | // We're going to exit afterwards. Close all other FDs to allow |
| 297 | // Command::spawn() to return in the parent process. | 299 | // Command::spawn() to return in the parent process. |
| 298 | - let raw = pipe.as_raw_fd() as u32; | 300 | + #[cfg(not(target_os = "openbsd"))] |
| 299 | - let _ = close_range(0, raw - 1, 0); | 301 | + { |
| 300 | - let _ = close_range(raw + 1, !0, 0); | 302 | + let raw = pipe.as_raw_fd() as u32; |
| 303 | + let _ = close_range(0, raw - 1, 0); | ||
| 304 | + let _ = close_range(raw + 1, !0, 0); | ||
| 305 | + } | ||
| 306 | + #[cfg(target_os = "openbsd")] | ||
| 307 | + { | ||
| 308 | + let raw = pipe.as_raw_fd(); | ||
| 309 | + for fd in 0..raw { | ||
| 310 | + close(fd); | ||
| 311 | + } | ||
| 312 | + closefrom(raw + 1); | ||
| 313 | + } | ||
| 301 | 314 | ||
| 302 | let _ = read_all(pipe, &mut [0]); | 315 | let _ = read_all(pipe, &mut [0]); |
| 303 | } | 316 | } |