Skip to content

Commit

Permalink
Use generic Atomic for rlim_t
Browse files Browse the repository at this point in the history
rlim_t is different between platforms.
  • Loading branch information
YaLTeR committed Jun 9, 2024
1 parent dbf0ddd commit f203c87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
9 changes: 5 additions & 4 deletions src/utils/spawning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Environment> = 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<rlim_t> = Atomic::new(0);
static ORIGINAL_NOFILE_RLIMIT_MAX: Atomic<rlim_t> = Atomic::new(0);

/// Increases the nofile rlimit to the maximum and stores the original value.
pub fn store_and_increase_nofile_rlimit() {
Expand Down

0 comments on commit f203c87

Please sign in to comment.