mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Don't propagate overwritten RUST_{,LIB_}BACKTRACE
This commit is contained in:
+8
-1
@@ -39,6 +39,8 @@ use tracing_subscriber::EnvFilter;
|
||||
use utils::spawn;
|
||||
use watcher::Watcher;
|
||||
|
||||
use crate::utils::{REMOVE_ENV_RUST_BACKTRACE, REMOVE_ENV_RUST_LIB_BACKTRACE};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Cli {
|
||||
@@ -51,9 +53,14 @@ struct Cli {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env::set_var("RUST_BACKTRACE", "1");
|
||||
// Set backtrace defaults if not set.
|
||||
if env::var_os("RUST_BACKTRACE").is_none() {
|
||||
env::set_var("RUST_BACKTRACE", "1");
|
||||
REMOVE_ENV_RUST_BACKTRACE.store(true, Ordering::Relaxed);
|
||||
}
|
||||
if env::var_os("RUST_LIB_BACKTRACE").is_none() {
|
||||
env::set_var("RUST_LIB_BACKTRACE", "0");
|
||||
REMOVE_ENV_RUST_LIB_BACKTRACE.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
let is_systemd_service = env::var_os("NOTIFY_SOCKET").is_some();
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::os::unix::process::CommandExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::ptr::null_mut;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{ensure, Context};
|
||||
@@ -53,6 +54,9 @@ pub fn make_screenshot_path(config: &Config) -> anyhow::Result<Option<PathBuf>>
|
||||
Ok(Some(path))
|
||||
}
|
||||
|
||||
pub static REMOVE_ENV_RUST_BACKTRACE: AtomicBool = AtomicBool::new(false);
|
||||
pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
/// Spawns the command to run independently of the compositor.
|
||||
pub fn spawn(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>) {
|
||||
let _span = tracy_client::span!();
|
||||
@@ -66,6 +70,14 @@ pub fn spawn(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsR
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null());
|
||||
|
||||
// Remove RUST_BACKTRACE and RUST_LIB_BACKTRACE from the environment if needed.
|
||||
if REMOVE_ENV_RUST_BACKTRACE.load(Ordering::Relaxed) {
|
||||
process.env_remove("RUST_BACKTRACE");
|
||||
}
|
||||
if REMOVE_ENV_RUST_LIB_BACKTRACE.load(Ordering::Relaxed) {
|
||||
process.env_remove("RUST_LIB_BACKTRACE");
|
||||
}
|
||||
|
||||
// Double-fork to avoid having to waitpid the child.
|
||||
unsafe {
|
||||
process.pre_exec(|| {
|
||||
|
||||
Reference in New Issue
Block a user