mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
vsh: Suppress attempts to write to stderr when it was closed in 'cmdComplete'
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>
This commit is contained in:
1 parent
a8a06cf1c6
commit
9899c91515
2 files changed
+7
No files matched your search
@@ -2145,6 +2145,9 @@ vshPrintStderr(vshControl *ctl,
|
|||||||
if (ctl)
|
if (ctl)
|
||||||
vshOutputLogFile(ctl, level, str);
|
vshOutputLogFile(ctl, level, str);
|
||||||
|
|
||||||
|
if (ctl->stderr_closed)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Most output is to stdout, but if someone ran virsh 2>&1, then
|
/* Most output is to stdout, but if someone ran virsh 2>&1, then
|
||||||
* printing to stderr will not interleave correctly with stdout
|
* printing to stderr will not interleave correctly with stdout
|
||||||
* unless we flush between every transition between streams. */
|
* unless we flush between every transition between streams. */
|
||||||
@@ -3577,6 +3580,8 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!ctl->imode) {
|
if (!ctl->imode) {
|
||||||
if (virOnce(&vshCmdCompleteCloseStdinStderrOnce, vshCmdCompleteCloseStdinStderr) < 0)
|
if (virOnce(&vshCmdCompleteCloseStdinStderrOnce, vshCmdCompleteCloseStdinStderr) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
ctl->stderr_closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(hooks && hooks->connHandler && hooks->connHandler(ctl)))
|
if (!(hooks && hooks->connHandler && hooks->connHandler(ctl)))
|
||||||
|
|||||||
@@ -225,6 +225,8 @@ struct _vshControl {
|
|||||||
|
|
||||||
const vshClientHooks *hooks;/* mandatory client specific hooks */
|
const vshClientHooks *hooks;/* mandatory client specific hooks */
|
||||||
void *privData; /* client specific data */
|
void *privData; /* client specific data */
|
||||||
|
|
||||||
|
bool stderr_closed; /* stderr was closed for the 'complete' command */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void *
|
typedef void *
|
||||||
|
|||||||
Reference in new issue
Block a user