From 04af4df73a24b8461fcc56d2d7027f20150d9936 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sun, 12 Dec 2021 22:36:22 +0800 Subject: [PATCH] shim: pass environment variables to spawned process Enhanace spawn() to pass envrionment variables to child process. Signed-off-by: Liu Jiang --- crates/shim/examples/empty_shim.rs | 2 +- crates/shim/src/lib.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/shim/examples/empty_shim.rs b/crates/shim/examples/empty_shim.rs index bc34ef2..2a2be7e 100644 --- a/crates/shim/examples/empty_shim.rs +++ b/crates/shim/examples/empty_shim.rs @@ -37,7 +37,7 @@ impl shim::Shim for Service { } fn start_shim(&mut self, opts: shim::StartOpts) -> Result { - let address = shim::spawn(opts)?; + let address = shim::spawn(opts, Vec::new())?; Ok(address) } } diff --git a/crates/shim/src/lib.rs b/crates/shim/src/lib.rs index da2a1ee..a5d469c 100644 --- a/crates/shim/src/lib.rs +++ b/crates/shim/src/lib.rs @@ -316,7 +316,7 @@ fn start_listener(address: &str) -> Result { /// Spawn is a helper func to launch shim process. /// Typically this expected to be called from `StartShim`. -pub fn spawn(opts: StartOpts) -> Result { +pub fn spawn(opts: StartOpts, vars: Vec<(&str, &str)>) -> Result { let cmd = env::current_exe()?; let cwd = env::current_dir()?; let address = socket_address(&opts.address, &opts.namespace, &opts.id); @@ -342,7 +342,8 @@ pub fn spawn(opts: StartOpts) -> Result { &opts.id, "-address", &opts.address, - ]); + ]) + .envs(vars); command.spawn().map_err(Into::into).map(|_| { // Ownership of `listener` has been passed to child.