public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH guest-common v2 09/14] tunnel: redirect stderr to log function
Date: Wed, 25 Feb 2026 16:18:32 +0100	[thread overview]
Message-ID: <20260225151931.176335-10-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260225151931.176335-1-f.ebner@proxmox.com>

With open2(), the stderr from the child process would just be printed
directly making it impossible for the call site of the tunnel to
filter the output.

This is in preparation to add a 'pct mtunnel' command. When forking a
tunnel to a node which does not support that command yet, the whole
'pct' usage documentation would be printed to the migration log and
the call site would only see 'can't open tunnel - no reply' as an
error. By capturing the stderr output too, the call site can detect
that the failure happens because the target node is too old and avoid
dumping the whole usage information.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

New in v2.

 src/PVE/Tunnel.pm | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/PVE/Tunnel.pm b/src/PVE/Tunnel.pm
index 25e03b6..148a8e2 100644
--- a/src/PVE/Tunnel.pm
+++ b/src/PVE/Tunnel.pm
@@ -5,7 +5,7 @@ use warnings;
 
 use IO::File;
 use IO::Pipe;
-use IPC::Open2;
+use IPC::Open3 qw(open3);
 use JSON qw(encode_json decode_json);
 use POSIX qw( WNOHANG );
 use Storable qw(dclone);
@@ -66,12 +66,19 @@ sub read_tunnel {
     $timeout = 60 if !defined($timeout);
 
     my $reader = $tunnel->{reader};
+    my $reader_stderr = $tunnel->{reader_stderr};
 
     my $output;
     eval {
         PVE::Tools::run_with_timeout($timeout, sub { $output = <$reader>; });
     };
-    die "reading from tunnel failed: $@\n" if $@;
+    my $err = $@;
+
+    while (my $line = <$reader_stderr>) { # $reader_stderr is set up as non-blocking
+        $tunnel->{log}->('warn', $line);
+    }
+
+    die "reading from tunnel failed: $err\n" if $err;
 
     chomp $output if defined($output);
 
@@ -145,13 +152,16 @@ sub fork_ssh_tunnel {
     my $full_cmd = [@$rem_ssh, '-o ExitOnForwardFailure=yes', @localtunnelinfo, @$cmd];
 
     my $reader = IO::File->new();
+    my $reader_stderr = IO::File->new();
     my $writer = IO::File->new();
 
     my $orig_pid = $$;
 
     my $cpid;
 
-    eval { $cpid = open2($reader, $writer, @$full_cmd); };
+    eval { $cpid = open3($writer, $reader, $reader_stderr, @$full_cmd); };
+    # Only read_tunnel() uses $reader_stderr and it never wants to wait.
+    $reader_stderr->blocking(0);
 
     my $err = $@;
 
@@ -167,6 +177,7 @@ sub fork_ssh_tunnel {
     my $tunnel = {
         writer => $writer,
         reader => $reader,
+        reader_stderr => $reader_stderr,
         pid => $cpid,
         rem_ssh => $rem_ssh,
         log => $log,
-- 
2.47.3





  parent reply	other threads:[~2026-02-25 15:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 15:18 [PATCH-SERIES qemu-server/guest-common/container v2 00/14] migration: strict config check for intra-cluster migration Fiona Ebner
2026-02-25 15:18 ` [PATCH qemu-server v2 01/14] d/control: bump versioned build dependency for libpve-common-perl to 9.0.12 Fiona Ebner
2026-02-25 15:18 ` [PATCH qemu-server v2 02/14] tests: migration: get rid of mocking for removed PVE::QemuMigrate::read_tunnel() Fiona Ebner
2026-02-25 15:18 ` [PATCH qemu-server v2 03/14] qm: mtunnel: avoid using deprecated check_running() helper Fiona Ebner
2026-02-25 15:18 ` [PATCH qemu-server v2 04/14] mtunnel: add 'conf' command to do strict configuration parsing Fiona Ebner
2026-02-25 15:18 ` [PATCH qemu-server v2 05/14] qm: mtunnel: reply when a command is unknown Fiona Ebner
2026-02-25 15:18 ` [PATCH qemu-server v2 06/14] migration: intra-cluster: check config can be parsed on target node Fiona Ebner
2026-02-25 15:18 ` [PATCH guest-common v2 07/14] tunnel: add missing IO::File module import Fiona Ebner
2026-02-25 15:18 ` [PATCH guest-common v2 08/14] tunnel: end module with true value as recommended by perlcritic Fiona Ebner
2026-02-25 15:18 ` Fiona Ebner [this message]
2026-02-25 15:18 ` [PATCH container v2 10/14] pct: add missing module imports and group according to style guide Fiona Ebner
2026-02-25 15:18 ` [PATCH container v2 11/14] migrate: add missing module imports Fiona Ebner
2026-02-25 15:18 ` [PATCH container v2 12/14] pct: introduce mtunnel command Fiona Ebner
2026-02-25 15:18 ` [PATCH container v2 13/14] d/control: bump versioned build dependency for libpve-common-perl to 9.0.12 Fiona Ebner
2026-02-25 15:18 ` [PATCH container v2 14/14] migration: intra-cluster: check config can be parsed on target node Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260225151931.176335-10-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal