Skip to content

Commit

Permalink
fix: cannot actually unset an environment variable because toml lacks…
Browse files Browse the repository at this point in the history
… null support
  • Loading branch information
sisungo committed Jun 2, 2024
1 parent 8d3eef0 commit 803c9bf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion airup-sdk/src/files/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct Env {
///
/// By default, the service runs with the same environment variables as `airupd`.
#[serde(default)]
pub vars: HashMap<String, Option<String>>,
pub vars: HashMap<String, toml::Value>,
}
impl Default for Env {
fn default() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion airup-sdk/src/files/system_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Option<String>>,
pub vars: HashMap<String, toml::Value>,
}

fn default_os_name() -> String {
Expand Down
6 changes: 5 additions & 1 deletion airupd/src/storage/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 18 additions & 1 deletion airupd/src/supervisor/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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::<String, _, String>(env.vars.clone().into_iter())
.vars::<String, _, String>(vars)
.working_dir::<PathBuf, _>(env.working_dir.clone())
.setsid(true);

Expand Down

0 comments on commit 803c9bf

Please sign in to comment.