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 = [
324324 "syn 2.0.63",
325325 ]
326326
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+
327336 [[package]]
328337 name = "atomic-waker"
329338 version = "1.1.2"
@@ -2179,6 +2188,7 @@ dependencies = [
21792188 "arrayvec",
21802189 "async-channel",
21812190 "async-io 1.13.0",
2191+ "atomic",
21822192 "bitflags 2.5.0",
21832193 "bytemuck",
21842194 "calloop 0.13.0",
Cargo.tomlmodified+1 -0
@@ -45,6 +45,7 @@ anyhow.workspace = true
4545 arrayvec = "0.7.4"
4646 async-channel = "2.3.1"
4747 async-io = { version = "1.13.0", optional = true }
48+atomic = "0.6.0"
4849 bitflags.workspace = true
4950 bytemuck = { version = "1.16.0", features = ["derive"] }
5051 calloop = { version = "0.13.0", features = ["executor", "futures-io"] }
src/utils/spawning.rsmodified+5 -4
@@ -2,11 +2,12 @@ use std::ffi::OsStr;
22 use std::os::unix::process::CommandExt;
33 use std::path::Path;
44 use std::process::{Child, Command, Stdio};
5-use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
5+use std::sync::atomic::{AtomicBool, Ordering};
66 use std::sync::RwLock;
77 use std::{io, thread};
88
9-use libc::{getrlimit, rlimit, setrlimit, RLIMIT_NOFILE};
9+use atomic::Atomic;
10+use libc::{getrlimit, rlim_t, rlimit, setrlimit, RLIMIT_NOFILE};
1011 use niri_config::Environment;
1112
1213 use crate::utils::expand_home;
@@ -15,8 +16,8 @@ pub static REMOVE_ENV_RUST_BACKTRACE: AtomicBool = AtomicBool::new(false);
1516 pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false);
1617 pub static CHILD_ENV: RwLock<Environment> = RwLock::new(Environment(Vec::new()));
1718
18-static ORIGINAL_NOFILE_RLIMIT_CUR: AtomicU64 = AtomicU64::new(0);
19-static ORIGINAL_NOFILE_RLIMIT_MAX: AtomicU64 = AtomicU64::new(0);
19+static ORIGINAL_NOFILE_RLIMIT_CUR: Atomic<rlim_t> = Atomic::new(0);
20+static ORIGINAL_NOFILE_RLIMIT_MAX: Atomic<rlim_t> = Atomic::new(0);
2021
2122 /// Increases the nofile rlimit to the maximum and stores the original value.
2223 pub fn store_and_increase_nofile_rlimit() {