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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6637E95778 for ; Wed, 18 Jan 2023 14:53:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4F7C520BE8 for ; Wed, 18 Jan 2023 14:53:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 for ; Wed, 18 Jan 2023 14:53:58 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 294CC44691 for ; Wed, 18 Jan 2023 14:53:48 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Wed, 18 Jan 2023 14:53:42 +0100 Message-Id: <20230118135342.1226289-1-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.134 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup] fix #4483: fix `task log` command interrupt handling 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: Wed, 18 Jan 2023 13:53:59 -0000 `proxmox-backup-client task log ..` and `proxmox-backup-manager task log ..` are used to view the logs of tasks that have been started by another client, so interrupting the task progress view should not forward the interrupt to the running task. other call sites of the same helper(s) that spawn a task and then print its progress should keep the old behaviour of interrupting the spawned task on C^c. Signed-off-by: Fabian Grünbichler --- pbs-client/src/task_log.rs | 26 +++++++++++++++++--------- proxmox-backup-client/src/task.rs | 2 +- src/bin/proxmox-backup-manager.rs | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pbs-client/src/task_log.rs b/pbs-client/src/task_log.rs index 960653de..372d63df 100644 --- a/pbs-client/src/task_log.rs +++ b/pbs-client/src/task_log.rs @@ -17,13 +17,14 @@ use super::HttpClient; /// Display task log on console /// /// This polls the task API and prints the log to the console. It also -/// catches interrupt signals, and sends a abort request to the task if -/// the user presses CTRL-C. Two interrupts cause an immediate end of -/// the loop. The task may still run in that case. +/// catches interrupt signals, and sends an abort request to the task if the +/// user presses CTRL-C and `forward_interrupt` is true. Two interrupts cause an +/// immediate end of the loop. The task may still run in that case. pub async fn display_task_log( client: &HttpClient, upid_str: &str, strip_date: bool, + forward_interrupt: bool, ) -> Result<(), Error> { let mut signal_stream = signal(SignalKind::interrupt())?; let abort_count = Arc::new(AtomicUsize::new(0)); @@ -48,11 +49,15 @@ pub async fn display_task_log( loop { let abort = abort_count.load(Ordering::Relaxed); if abort > 0 { - let path = format!( - "api2/json/nodes/localhost/tasks/{}", - percent_encode_component(upid_str) - ); - let _ = client.delete(&path, None).await?; + if forward_interrupt { + let path = format!( + "api2/json/nodes/localhost/tasks/{}", + percent_encode_component(upid_str) + ); + let _ = client.delete(&path, None).await?; + } else { + return Ok(()); + } } let param = json!({ "start": start, "limit": limit, "test-status": true }); @@ -111,6 +116,9 @@ pub async fn display_task_log( } /// Display task result (upid), or view task log - depending on output format +/// +/// In case of a task log of a running task, this will forward interrupt signals +/// to the task and potentially abort it! pub async fn view_task_result( client: &HttpClient, result: Value, @@ -119,7 +127,7 @@ pub async fn view_task_result( let data = &result["data"]; if output_format == "text" { if let Some(upid) = data.as_str() { - display_task_log(client, upid, true).await?; + display_task_log(client, upid, true, true).await?; } } else { format_and_print_result(data, output_format); diff --git a/proxmox-backup-client/src/task.rs b/proxmox-backup-client/src/task.rs index 94c879a8..472db086 100644 --- a/proxmox-backup-client/src/task.rs +++ b/proxmox-backup-client/src/task.rs @@ -104,7 +104,7 @@ async fn task_log(param: Value) -> Result { let client = connect(&repo)?; - display_task_log(&client, upid, true).await?; + display_task_log(&client, upid, true, false).await?; Ok(Value::Null) } diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 06330c78..f084af31 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -189,7 +189,7 @@ async fn task_log(param: Value) -> Result { let client = connect_to_localhost()?; - display_task_log(&client, upid, true).await?; + display_task_log(&client, upid, true, false).await?; Ok(Value::Null) } -- 2.30.2