From d0597f273a9780ed4b985b9914198456901a84b2 Mon Sep 17 00:00:00 2001 From: Manthan Patil Date: Thu, 9 Jan 2025 20:48:15 +0000 Subject: [PATCH] refactor: swhkd should never read environment --- swhkd/src/daemon.rs | 7 +++---- swhkd/src/environ.rs | 10 ++-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index e23efe1..691156e 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -91,8 +91,8 @@ async fn main() -> Result<(), Box> { // Without this request, the environmental variables responsible for the reading for the config // file will not be available. // Thus, it is important to wait for the server to start before proceeding. - let mut env = environ::Env::construct(None); - let mut env_hash = 0; + let env; + let mut env_hash; loop { match refresh_env(invoking_uid, 0) { Ok((Some(new_env), hash)) => { @@ -100,8 +100,7 @@ async fn main() -> Result<(), Box> { env = new_env; break; } - Ok((None, hash)) => { - env_hash = hash; + Ok((None, _)) => { log::debug!("Waiting for env..."); continue; } diff --git a/swhkd/src/environ.rs b/swhkd/src/environ.rs index 4f92e05..572e1b3 100644 --- a/swhkd/src/environ.rs +++ b/swhkd/src/environ.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, error::Error, path::PathBuf, process::Command}; +use std::{collections::HashMap, path::PathBuf}; #[derive(Debug, Clone)] pub struct Env { @@ -6,12 +6,6 @@ pub struct Env { } impl Env { - fn get_env() -> Result> { - let cmd = Command::new("env").output()?; - let stdout = String::from_utf8(cmd.stdout)?; - Ok(stdout) - } - fn parse_env(env: &str) -> HashMap { let mut pairs = HashMap::new(); for line in env.lines() { @@ -27,7 +21,7 @@ impl Env { pub fn construct(env: Option<&str>) -> Self { let env = match env { Some(env) => env.to_string(), - None => Self::get_env().unwrap(), + None => "".to_string(), }; let pairs = Self::parse_env(&env); Self { pairs }