diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-24 10:08:56 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-24 10:08:56 +0400 |
| commit | ec156a858795b7f31cac51845d9cf3197a063f92 (patch) | |
| tree | b0da6c94a24286d8ddb3da79c9cd14531f85830e /src/utils/spawning.rs | |
| parent | e278e871c357c4832f29629e4f65f57ff0d0ded0 (diff) | |
| download | niri-ec156a858795b7f31cac51845d9cf3197a063f92.tar.gz niri-ec156a858795b7f31cac51845d9cf3197a063f92.tar.bz2 niri-ec156a858795b7f31cac51845d9cf3197a063f92.zip | |
Add environment {} config section
Diffstat (limited to 'src/utils/spawning.rs')
| -rw-r--r-- | src/utils/spawning.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/spawning.rs b/src/utils/spawning.rs index d212ea18..494ec997 100644 --- a/src/utils/spawning.rs +++ b/src/utils/spawning.rs @@ -4,9 +4,11 @@ use std::os::unix::process::CommandExt; use std::path::Path; use std::process::{Command, Stdio}; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::RwLock; use std::{io, thread}; use libc::close_range; +use niri_config::Environment; use smithay::reexports::rustix; use smithay::reexports::rustix::io::{close, read, retry_on_intr, write}; use smithay::reexports::rustix::pipe::{pipe_with, PipeFlags}; @@ -15,6 +17,7 @@ use crate::utils::expand_home; 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())); /// Spawns the command to run independently of the compositor. pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>) { @@ -67,6 +70,17 @@ fn spawn_sync(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl As process.env_remove("RUST_LIB_BACKTRACE"); } + // Set configured environment. + let env = CHILD_ENV.read().unwrap(); + for var in &env.0 { + if let Some(value) = &var.value { + process.env(&var.name, value); + } else { + process.env_remove(&var.name); + } + } + drop(env); + // When running as a systemd session, we want to put children into their own transient scopes // in order to separate them from the niri process. This is helpful for example to prevent the // OOM killer from taking down niri together with a misbehaving client. |
