diff --git a/Cargo.lock b/Cargo.lock index 24ccde7..72643a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -324,6 +324,15 @@ dependencies = [ "syn 2.0.63", ] +[[package]] +name = "atomic" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d818003e740b63afc82337e3160717f4f63078720a810b7b903e70a5d1d2994" +dependencies = [ + "bytemuck", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -2179,6 +2188,7 @@ dependencies = [ "arrayvec", "async-channel", "async-io 1.13.0", + "atomic", "bitflags 2.5.0", "bytemuck", "calloop 0.13.0", diff --git a/Cargo.toml b/Cargo.toml index f1652eb..88bfca1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ anyhow.workspace = true arrayvec = "0.7.4" async-channel = "2.3.1" async-io = { version = "1.13.0", optional = true } +atomic = "0.6.0" bitflags.workspace = true bytemuck = { version = "1.16.0", features = ["derive"] } calloop = { version = "0.13.0", features = ["executor", "futures-io"] } diff --git a/src/utils/spawning.rs b/src/utils/spawning.rs index 9a274ff..871f05d 100644 --- a/src/utils/spawning.rs +++ b/src/utils/spawning.rs @@ -2,11 +2,12 @@ use std::ffi::OsStr; use std::os::unix::process::CommandExt; use std::path::Path; use std::process::{Child, Command, Stdio}; -use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::RwLock; use std::{io, thread}; -use libc::{getrlimit, rlimit, setrlimit, RLIMIT_NOFILE}; +use atomic::Atomic; +use libc::{getrlimit, rlim_t, rlimit, setrlimit, RLIMIT_NOFILE}; use niri_config::Environment; use crate::utils::expand_home; @@ -15,8 +16,8 @@ pub static REMOVE_ENV_RUST_BACKTRACE: AtomicBool = AtomicBool::new(false); pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false); pub static CHILD_ENV: RwLock = RwLock::new(Environment(Vec::new())); -static ORIGINAL_NOFILE_RLIMIT_CUR: AtomicU64 = AtomicU64::new(0); -static ORIGINAL_NOFILE_RLIMIT_MAX: AtomicU64 = AtomicU64::new(0); +static ORIGINAL_NOFILE_RLIMIT_CUR: Atomic = Atomic::new(0); +static ORIGINAL_NOFILE_RLIMIT_MAX: Atomic = Atomic::new(0); /// Increases the nofile rlimit to the maximum and stores the original value. pub fn store_and_increase_nofile_rlimit() {