aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs9
-rw-r--r--src/utils.rs12
2 files changed, 20 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 3792caaf..08cd0533 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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();
diff --git a/src/utils.rs b/src/utils.rs
index a04b8e9b..94b5c427 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -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(|| {