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 C1F749544B for ; Mon, 26 Feb 2024 15:10:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AB3A61045C for ; Mon, 26 Feb 2024 15:10:30 +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 ; Mon, 26 Feb 2024 15:10:26 +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 7F08B472AF for ; Mon, 26 Feb 2024 15:10:26 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Date: Mon, 26 Feb 2024 15:10:19 +0100 Message-Id: <20240226141020.296052-1-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.056 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] applied: [PATCH 1/2] run command: avoid using 1 as special value X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Feb 2024 14:10:30 -0000 In Perl, the last expression of a block (e.g. of a method, eval) gets returned if there's no explicit return statement. Quite often that is truthy, i.e., 1. As that was chosen as the special value for the CMD_FINISHED flag it had quite a few false positives, causing weird effects and installation failure. Reserve that overly problematic value and chose 2 as new CMD_FINISHED value, albeit it could be better to signal this even more explicitly, like with a structured hash reference, but for now this is a good stop gap. Fixes: 23c5fbe ("sys: command: allow terminating the process early from log subroutine") Signed-off-by: Thomas Lamprecht --- Proxmox/Sys/Command.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Proxmox/Sys/Command.pm b/Proxmox/Sys/Command.pm index cb5fe76..ac505c4 100644 --- a/Proxmox/Sys/Command.pm +++ b/Proxmox/Sys/Command.pm @@ -17,7 +17,10 @@ use Proxmox::UI; use base qw(Exporter); our @EXPORT_OK = qw(run_command syscmd CMD_FINISHED); -use constant CMD_FINISHED => 1; +use constant { + CMD_RESERVED => 1<<0, # reserve 1 as it's often the default return value of closures + CMD_FINISHED => 1<<1, +}; my sub shellquote { my $str = shift; @@ -78,8 +81,9 @@ sub syscmd { # # Arguments: # * $cmd - The command to run, either a single string or array with individual arguments -# * $func - Logging subroutine to call, receives both stdout and stderr. Might return CMD_FINISHED -# to exit early and ignore the rest of the process output. +# * $func - Logging subroutine to call, receives both stdout and stderr. +# Can return CMD_FINISHED to exit early and ignore the rest of the process output. +# Should use an explicit `return;` to avoid misinterpretation of return value. # * $input - Stdin contents for the spawned subprocess # * $noout - Whether to append any process output to the return value # * $noprint - Whether to print any process output to the parents stdout -- 2.39.2