]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Suppress attempts to write to stderr when it was closed in 'cmdComplete'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 29 Apr 2026 10:15:34 +0000 (12:15 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 5 May 2026 05:32:11 +0000 (07:32 +0200)
The completer closes stderr to suppress anything polluting the shell
when completion would cause any errors.

Since 'virshReconnect' would call 'vshError' on connection failure this
causes vshError to be killed by SIGPIPE and not provide any completions
if the connection is not possible.

To avoid this add a flag called 'stderr_closed' to vshControl and use it
to suppress output in 'vshPrintStderr'. Keep only the log.

Prior to this patch, attempt to run completion on a host with all
daemons shut down would result in:

 # virsh complete -- "start" "--doma" ; echo $?
 141
 #

With this patch the completion will still fail but the return code will
be 1. Further patch will allow completion.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/vsh.c
tools/vsh.h

index 74016c0043fe90f172957e077302cb139c399303..c84d17a3327f6d49497e4634cee103c59cc91f58 100644 (file)
@@ -2145,6 +2145,9 @@ vshPrintStderr(vshControl *ctl,
     if (ctl)
         vshOutputLogFile(ctl, level, str);
 
+    if (ctl->stderr_closed)
+        return;
+
     /* Most output is to stdout, but if someone ran virsh 2>&1, then
      * printing to stderr will not interleave correctly with stdout
      * unless we flush between every transition between streams.  */
@@ -3577,6 +3580,8 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
     if (!ctl->imode) {
         if (virOnce(&vshCmdCompleteCloseStdinStderrOnce, vshCmdCompleteCloseStdinStderr) < 0)
             return false;
+
+        ctl->stderr_closed = true;
     }
 
     if (!(hooks && hooks->connHandler && hooks->connHandler(ctl)))
index bd2494e899a663758589785239c23aee3a8b9dbf..1c5a69b04ed63569ba37989098661acc094b2f8b 100644 (file)
@@ -225,6 +225,8 @@ struct _vshControl {
 
     const vshClientHooks *hooks;/* mandatory client specific hooks */
     void *privData;             /* client specific data */
+
+    bool stderr_closed;         /* stderr was closed for the 'complete' command */
 };
 
 typedef void *