From c84857ae9b759ba545e05b26e9d37fd13f98dc11 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 24 Jun 2022 14:46:14 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Move=20away=20from=20`s?= =?UTF-8?q?td::env::set=5Fvar`,=20which=20is=20unsound?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/comp.rs | 2 +- src/main.rs | 6 ++++-- src/panel.rs | 7 +++++-- src/process.rs | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/comp.rs b/src/comp.rs index 81416d1..54cf73c 100644 --- a/src/comp.rs +++ b/src/comp.rs @@ -6,7 +6,7 @@ use tokio_util::sync::CancellationToken; pub async fn run_compositor(token: CancellationToken, wayland_socket_tx: oneshot::Sender) { let mut wayland_socket_tx = Some(wayland_socket_tx); let (tx, mut rx) = unbounded_channel::(); - ProcessHandler::new(tx, &token).run("cosmic-comp", vec![]); + ProcessHandler::new(tx, &token).run("cosmic-comp", vec![], vec![]); let span = info_span!("cosmic-comp"); let _enter = span.enter(); while let Some(event) = rx.recv().await { diff --git a/src/main.rs b/src/main.rs index 21dc1dd..31b5f11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,9 +37,11 @@ async fn main() -> Result<()> { .await .expect("failed to get WAYLAND_SOCKET"); info!("got WAYLAND_SOCKET: {}", wayland_socket); - std::env::set_var("WAYLAND_SOCKET", wayland_socket); - tokio::spawn(panel::run_panel(token.child_token())); + tokio::spawn(panel::run_panel( + token.child_token(), + wayland_socket.clone(), + )); let mut signals = Signals::new(vec![libc::SIGTERM, libc::SIGINT]).unwrap(); while let Some(signal) = signals.next().await { diff --git a/src/panel.rs b/src/panel.rs index 52ae3bd..6a9cb2e 100644 --- a/src/panel.rs +++ b/src/panel.rs @@ -3,9 +3,12 @@ use crate::process::{ProcessEvent, ProcessHandler}; use tokio::sync::mpsc::unbounded_channel; use tokio_util::sync::CancellationToken; -pub async fn run_panel(token: CancellationToken) { +pub async fn run_panel(token: CancellationToken, wayland_socket: String) { let (tx, mut rx) = unbounded_channel::(); - ProcessHandler::new(tx, &token).run("cosmic-panel", vec![]); + ProcessHandler::new(tx, &token).run("cosmic-panel", vec![], vec![( + "WAYLAND_SOCKET".into(), + wayland_socket, + )]); let span = info_span!("cosmic-panel"); let _enter = span.enter(); while let Some(event) = rx.recv().await { diff --git a/src/process.rs b/src/process.rs index 1189259..892d740 100644 --- a/src/process.rs +++ b/src/process.rs @@ -27,7 +27,7 @@ impl ProcessHandler { } } - pub fn run(self, executable: impl ToString, args: Vec) { + pub fn run(self, executable: impl ToString, args: Vec, vars: Vec<(String, String)>) { let executable = executable.to_string(); tokio::spawn(async move { let mut child = match Command::new(&executable) @@ -35,6 +35,7 @@ impl ProcessHandler { .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) + .envs(vars) .kill_on_drop(true) .spawn() {