[libvirt] [PATCH v3 5/5] tools: console: pass stream/fd errors to user
Cole Robinson
crobinso at redhat.com
Wed Apr 3 20:59:15 UTC 2019
On 3/18/19 5:08 AM, Nikolay Shirokovskiy wrote:
> If the console was disconnected due to a connection problem or a problem on the
> server side it is convinient to provide the cause to the user. If the error
> come from the API then the error is saved in a virsh global variable. However,
> since success is returned from virshRunConsole after we reach the waiting stage,
> then the error is never reported. Let's track the error in the event loop.
>
> Next after failure we do a cleanup and this cleanup can overwrite
> root cause. Thus let's save root cause immediately and then set it to
> virsh error after all cleanup is done.
>
> Since we'll be sending the error to the consumer, each failure path from
> the event handlers needs to be augmented to provide what error generated
> the failure.
>
> Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
> ---
> tools/virsh-console.c | 55 +++++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 47 insertions(+), 8 deletions(-)
>
> diff --git a/tools/virsh-console.c b/tools/virsh-console.c
> index d109734..236933a 100644
> --- a/tools/virsh-console.c
> +++ b/tools/virsh-console.c
> @@ -73,6 +73,7 @@ struct virConsole {
> struct virConsoleBuffer terminalToStream;
>
> char escapeChar;
> + virError error;
> };
>
> static virClassPtr virConsoleClass;
> @@ -98,6 +99,11 @@ virConsoleHandleSignal(int sig ATTRIBUTE_UNUSED)
> static void
> virConsoleShutdown(virConsolePtr con)
> {
> + virErrorPtr err = virGetLastError();
> +
> + if (con->error.code == VIR_ERR_OK && err && err->code != VIR_ERR_OK)
> + virCopyLastError(&con->error);
> +
virGetLastError() returns NULL if err->code == VIR_ERR_OK, so that last
check can be removed. The rest looks good to me
Reviewed-by: Cole Robinson <crobinso at redhat.com>
- Cole
More information about the libvir-list
mailing list