diff --git a/airup-sdk/src/files/service.rs b/airup-sdk/src/files/service.rs index 8786fe4..9b2bf6b 100644 --- a/airup-sdk/src/files/service.rs +++ b/airup-sdk/src/files/service.rs @@ -112,7 +112,7 @@ pub struct Env { /// /// By default, the service runs with the same environment variables as `airupd`. #[serde(default)] - pub vars: HashMap>, + pub vars: HashMap, } impl Default for Env { fn default() -> Self { diff --git a/airup-sdk/src/files/system_conf.rs b/airup-sdk/src/files/system_conf.rs index 31a813c..5467305 100644 --- a/airup-sdk/src/files/system_conf.rs +++ b/airup-sdk/src/files/system_conf.rs @@ -37,7 +37,7 @@ pub struct Env { /// /// If a value is set to `null`, the environment variable gets removed if it exists. #[serde(default)] - pub vars: HashMap>, + pub vars: HashMap, } fn default_os_name() -> String { diff --git a/airupd/src/storage/config.rs b/airupd/src/storage/config.rs index d328c92..816097a 100644 --- a/airupd/src/storage/config.rs +++ b/airupd/src/storage/config.rs @@ -36,7 +36,11 @@ impl Config { vars.insert(k.to_owned(), v.as_ref().map(Into::into)); } for (k, v) in &self.system_conf.env.vars { - vars.insert(k.into(), v.clone()); + if v.as_integer() == Some(0) { + vars.insert(k.clone(), None); + } else if let Some(s) = v.as_str() { + vars.insert(k.clone(), Some(s.into())); + } } airupfx::env::set_vars(vars); } diff --git a/airupd/src/supervisor/task/mod.rs b/airupd/src/supervisor/task/mod.rs index b200029..2f3bfbf 100644 --- a/airupd/src/supervisor/task/mod.rs +++ b/airupd/src/supervisor/task/mod.rs @@ -197,6 +197,23 @@ async fn ace_environment( airup_sdk::files::service::Stdio::Log => log(y), }; + let vars = env + .vars + .iter() + .filter(|(_, v)| v.as_integer() == Some(0) || v.is_str()) + .map(|(k, v)| { + ( + k.into(), + if v.is_integer() { + None + } else if let Some(s) = v.as_str() { + Some(s.into()) + } else { + unreachable!() + }, + ) + }); + result .login(env.login.as_deref())? .uid(env.uid) @@ -205,7 +222,7 @@ async fn ace_environment( .stdout(to_ace(env.stdout.clone(), 1)) .stderr(to_ace(env.stderr.clone(), 2)) .clear_vars(env.clear_vars) - .vars::(env.vars.clone().into_iter()) + .vars::(vars) .working_dir::(env.working_dir.clone()) .setsid(true);