From nobody Mon Feb 9 08:57:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155290014993830.752541896066077; Mon, 18 Mar 2019 02:09:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3038537E79; Mon, 18 Mar 2019 09:09:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0716317CE5; Mon, 18 Mar 2019 09:09:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 55B56181A13B; Mon, 18 Mar 2019 09:09:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2I9947h012763 for ; Mon, 18 Mar 2019 05:09:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 616BD18509; Mon, 18 Mar 2019 09:09:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5AD9B19C72 for ; Mon, 18 Mar 2019 09:09:02 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59F6A59447 for ; Mon, 18 Mar 2019 09:09:01 +0000 (UTC) Received: from [10.94.3.220] (helo=dim-vz7.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1h5oGQ-00050x-C1 for libvir-list@redhat.com; Mon, 18 Mar 2019 12:08:58 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 18 Mar 2019 12:08:20 +0300 Message-Id: <1552900100-450648-6-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1552900100-450648-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1552900100-450648-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Sender passed SPF test, ACL 242 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 18 Mar 2019 09:09:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 18 Mar 2019 09:09:01 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 5/5] tools: console: pass stream/fd errors to user X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 18 Mar 2019 09:09:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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. Howev= er, since success is returned from virshRunConsole after we reach the waiting s= tage, 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 Reviewed-by: Cole Robinson --- 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; =20 char escapeChar; + virError error; }; =20 static virClassPtr virConsoleClass; @@ -98,6 +99,11 @@ virConsoleHandleSignal(int sig ATTRIBUTE_UNUSED) static void virConsoleShutdown(virConsolePtr con) { + virErrorPtr err =3D virGetLastError(); + + if (con->error.code =3D=3D VIR_ERR_OK && err && err->code !=3D VIR_ERR= _OK) + virCopyLastError(&con->error); + if (con->st) { virStreamEventRemoveCallback(con->st); virStreamAbort(con->st); @@ -128,6 +134,7 @@ virConsoleDispose(void *obj) virStreamFree(con->st); =20 virCondDestroy(&con->cond); + virResetError(&con->error); } =20 =20 @@ -165,6 +172,10 @@ virConsoleEventOnStream(virStreamPtr st, if (got =3D=3D -2) goto cleanup; /* blocking */ if (got <=3D 0) { + if (got =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("console stream EOF")); + } virConsoleShutdown(con); goto cleanup; } @@ -247,11 +258,14 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, con->terminalToStream.offset, avail); if (got < 0) { - if (errno !=3D EAGAIN) + if (errno !=3D EAGAIN) { + virReportSystemError(errno, "%s", _("cannot read from stdi= n")); virConsoleShutdown(con); + } goto cleanup; } if (got =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdin")= ); virConsoleShutdown(con); goto cleanup; } @@ -267,9 +281,16 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, VIR_STREAM_EVENT_WRITABLE); } =20 - if (events & VIR_EVENT_HANDLE_ERROR || - events & VIR_EVENT_HANDLE_HANGUP) { + if (events & VIR_EVENT_HANDLE_ERROR) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("IO error on stdin"= )); virConsoleShutdown(con); + goto cleanup; + } + + if (events & VIR_EVENT_HANDLE_HANGUP) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdin")); + virConsoleShutdown(con); + goto cleanup; } =20 cleanup: @@ -299,8 +320,10 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED, con->streamToTerminal.data, con->streamToTerminal.offset); if (done < 0) { - if (errno !=3D EAGAIN) + if (errno !=3D EAGAIN) { + virReportSystemError(errno, "%s", _("cannot write to stdou= t")); virConsoleShutdown(con); + } goto cleanup; } memmove(con->streamToTerminal.data, @@ -319,9 +342,16 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED, if (!con->streamToTerminal.offset) virEventUpdateHandle(con->stdoutWatch, 0); =20 - if (events & VIR_EVENT_HANDLE_ERROR || - events & VIR_EVENT_HANDLE_HANGUP) { + if (events & VIR_EVENT_HANDLE_ERROR) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("IO error stdout")); virConsoleShutdown(con); + goto cleanup; + } + + if (events & VIR_EVENT_HANDLE_HANGUP) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdout")); + virConsoleShutdown(con); + goto cleanup; } =20 cleanup: @@ -449,15 +479,24 @@ virshRunConsole(vshControl *ctl, =20 while (!con->quit) { if (virCondWait(&con->cond, &con->parent.lock) < 0) { - VIR_ERROR(_("unable to wait on console condition")); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unable to wait on console condition")); goto cleanup; } } =20 - ret =3D 0; + if (con->error.code =3D=3D VIR_ERR_OK) + ret =3D 0; =20 cleanup: virConsoleShutdown(con); + + if (ret < 0) { + vshResetLibvirtError(); + virSetError(&con->error); + vshSaveLibvirtHelperError(); + } + virObjectUnlock(con); virObjectUnref(con); =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list