From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D3971657E7 for ; Thu, 23 Jul 2020 15:20:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C37EB29724 for ; Thu, 23 Jul 2020 15:20:16 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 4BDA629716 for ; Thu, 23 Jul 2020 15:20:15 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 11F9243339 for ; Thu, 23 Jul 2020 15:20:15 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 23 Jul 2020 15:20:12 +0200 Message-Id: <20200723132013.22398-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.001 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pbs-devel] [PATCH proxmox-backup 1/2] termproxy: let users stop the termproxy task X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2020 13:20:16 -0000 for that we have to do a select on the workers abort_future Signed-off-by: Dominik Csapak --- src/api2/node.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/api2/node.rs b/src/api2/node.rs index 431627c..b572a9c 100644 --- a/src/api2/node.rs +++ b/src/api2/node.rs @@ -4,7 +4,7 @@ use std::os::unix::io::AsRawFd; use anyhow::{bail, format_err, Error}; use futures::{ future::{FutureExt, TryFutureExt}, - try_join, + select, }; use hyper::body::Body; use hyper::http::request::Parts; @@ -169,9 +169,10 @@ async fn termproxy( let mut cmd = tokio::process::Command::new("/usr/bin/termproxy"); - cmd.args(&arguments); - cmd.stdout(std::process::Stdio::piped()); - cmd.stderr(std::process::Stdio::piped()); + cmd.args(&arguments) + .kill_on_drop(true) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()); let mut child = cmd.spawn().expect("error executing termproxy"); @@ -184,7 +185,7 @@ async fn termproxy( while let Some(line) = reader.next_line().await? { worker_stdout.log(line); } - Ok(()) + Ok::<(), Error>(()) }; let worker_stderr = worker.clone(); @@ -193,18 +194,24 @@ async fn termproxy( while let Some(line) = reader.next_line().await? { worker_stderr.warn(line); } - Ok(()) + Ok::<(), Error>(()) }; - let (exit_code, _, _) = try_join!(child, stdout_fut, stderr_fut)?; - if !exit_code.success() { - match exit_code.code() { - Some(code) => bail!("termproxy exited with {}", code), - None => bail!("termproxy exited by signal"), - } + select!{ + res = child.fuse() => { + let exit_code = res?; + if !exit_code.success() { + match exit_code.code() { + Some(code) => bail!("termproxy exited with {}", code), + None => bail!("termproxy exited by signal"), + } + } + Ok(()) + }, + res = stdout_fut.fuse() => res, + res = stderr_fut.fuse() => res, + res = worker.abort_future().fuse() => res.map_err(Error::from), } - - Ok(()) }, )?; -- 2.20.1