[pve-devel] [PATCH installer 2/4] sys: command: allow terminating the process early from log subroutine

Christoph Heiss c.heiss at proxmox.com
Fri Feb 9 11:55:59 CET 2024


This is done in a entirely backwards-compatible way, i.e. existing
usages don't need any modification.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 Proxmox/Sys/Command.pm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Proxmox/Sys/Command.pm b/Proxmox/Sys/Command.pm
index c3e24b3..bf67b27 100644
--- a/Proxmox/Sys/Command.pm
+++ b/Proxmox/Sys/Command.pm
@@ -114,7 +114,14 @@ sub run_command {
 		$logout .= $buf;
 		while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
 		    my $line = $1;
-		    $func->($line) if $func;
+		    if ($func) {
+			my $ret = $func->($line);
+			if (defined($ret) && $ret == 1) {
+			    kill('KILL', $pid);
+			    waitpid($pid, 0);
+			    return $ostream;
+			}
+		    };
 		}
 
 	    } elsif ($h eq $error) {
-- 
2.43.0





More information about the pve-devel mailing list