forge
Explore
Log in

Don't you dare go Hollow

Use generic Atomic for rlim_t

Browse files at this commit

f203c8729a8535f6a317df5a35dc01306be2e45cIvan MolodetskikhParent: dbf0ddd
rlim_t is different between platforms.
Cargo.lockmodified+10 -0
@@ -324,6 +324,15 @@ dependencies = [
324 "syn 2.0.63",324 "syn 2.0.63",
325 ]325 ]
326 326
327+[[package]]
328+name = "atomic"
329+version = "0.6.0"
330+source = "registry+https://github.com/rust-lang/crates.io-index"
331+checksum = "8d818003e740b63afc82337e3160717f4f63078720a810b7b903e70a5d1d2994"
332+dependencies = [
333+ "bytemuck",
334+]
335+
327 [[package]]336 [[package]]
328 name = "atomic-waker"337 name = "atomic-waker"
329 version = "1.1.2"338 version = "1.1.2"
@@ -2179,6 +2188,7 @@ dependencies = [
2179 "arrayvec",2188 "arrayvec",
2180 "async-channel",2189 "async-channel",
2181 "async-io 1.13.0",2190 "async-io 1.13.0",
2191+ "atomic",
2182 "bitflags 2.5.0",2192 "bitflags 2.5.0",
2183 "bytemuck",2193 "bytemuck",
2184 "calloop 0.13.0",2194 "calloop 0.13.0",
Cargo.tomlmodified+1 -0
@@ -45,6 +45,7 @@ anyhow.workspace = true
45 arrayvec = "0.7.4"45 arrayvec = "0.7.4"
46 async-channel = "2.3.1"46 async-channel = "2.3.1"
47 async-io = { version = "1.13.0", optional = true }47 async-io = { version = "1.13.0", optional = true }
48+atomic = "0.6.0"
48 bitflags.workspace = true49 bitflags.workspace = true
49 bytemuck = { version = "1.16.0", features = ["derive"] }50 bytemuck = { version = "1.16.0", features = ["derive"] }
50 calloop = { version = "0.13.0", features = ["executor", "futures-io"] }51 calloop = { version = "0.13.0", features = ["executor", "futures-io"] }
src/utils/spawning.rsmodified+5 -4
@@ -2,11 +2,12 @@ use std::ffi::OsStr;
2 use std::os::unix::process::CommandExt;2 use std::os::unix::process::CommandExt;
3 use std::path::Path;3 use std::path::Path;
4 use std::process::{Child, Command, Stdio};4 use std::process::{Child, Command, Stdio};
5-use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};5+use std::sync::atomic::{AtomicBool, Ordering};
6 use std::sync::RwLock;6 use std::sync::RwLock;
7 use std::{io, thread};7 use std::{io, thread};
8 8
9-use libc::{getrlimit, rlimit, setrlimit, RLIMIT_NOFILE};9+use atomic::Atomic;
10+use libc::{getrlimit, rlim_t, rlimit, setrlimit, RLIMIT_NOFILE};
10 use niri_config::Environment;11 use niri_config::Environment;
11 12
12 use crate::utils::expand_home;13 use crate::utils::expand_home;
@@ -15,8 +16,8 @@ pub static REMOVE_ENV_RUST_BACKTRACE: AtomicBool = AtomicBool::new(false);
15 pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false);16 pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false);
16 pub static CHILD_ENV: RwLock<Environment> = RwLock::new(Environment(Vec::new()));17 pub static CHILD_ENV: RwLock<Environment> = RwLock::new(Environment(Vec::new()));
17 18
18-static ORIGINAL_NOFILE_RLIMIT_CUR: AtomicU64 = AtomicU64::new(0);19+static ORIGINAL_NOFILE_RLIMIT_CUR: Atomic<rlim_t> = Atomic::new(0);
19-static ORIGINAL_NOFILE_RLIMIT_MAX: AtomicU64 = AtomicU64::new(0);20+static ORIGINAL_NOFILE_RLIMIT_MAX: Atomic<rlim_t> = Atomic::new(0);
20 21
21 /// Increases the nofile rlimit to the maximum and stores the original value.22 /// Increases the nofile rlimit to the maximum and stores the original value.
22 pub fn store_and_increase_nofile_rlimit() {23 pub fn store_and_increase_nofile_rlimit() {