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>
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. */
if (!ctl->imode) {
if (virOnce(&vshCmdCompleteCloseStdinStderrOnce, vshCmdCompleteCloseStdinStderr) < 0)
return false;
+
+ ctl->stderr_closed = true;
}
if (!(hooks && hooks->connHandler && hooks->connHandler(ctl)))
const vshClientHooks *hooks;/* mandatory client specific hooks */
void *privData; /* client specific data */
+
+ bool stderr_closed; /* stderr was closed for the 'complete' command */
};
typedef void *