From: Peter Krempa <pkrempa@redhat.com> The completer closes stderr to suppress anything poluting 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> --- tools/vsh.c | 5 +++++ tools/vsh.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/tools/vsh.c b/tools/vsh.c index 74016c0043..c84d17a332 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -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))) diff --git a/tools/vsh.h b/tools/vsh.h index bd2494e899..1c5a69b04e 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -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 * -- 2.54.0