From nobody Mon Feb 9 06:01:39 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 155290015036934.401849733918084; Mon, 18 Mar 2019 02:09:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A63E3082163; Mon, 18 Mar 2019 09:09:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 032231001DF7; 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 3A5223FB11; 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 x2I994tv012769 for ; Mon, 18 Mar 2019 05:09:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id A820519C6A; Mon, 18 Mar 2019 09:09:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B07F19C7A 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 6314531688ED for ; Mon, 18 Mar 2019 09:08:59 +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 1h5oGP-00050x-Ql for libvir-list@redhat.com; Mon, 18 Mar 2019 12:08:57 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 18 Mar 2019 12:08:17 +0300 Message-Id: <1552900100-450648-3-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.41]); Mon, 18 Mar 2019 09:09:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); 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.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 2/5] tools: console: cleanup console on errors in main thread 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 18 Mar 2019 09:09:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We only check now for virObjectWait failures in virshRunConsole but we'd better check and for other failures too. And we need to shutdown console on error in the main thread. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Cole Robinson --- tools/virsh-console.c | 52 +++++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/tools/virsh-console.c b/tools/virsh-console.c index 763b395..9289221 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -112,8 +112,10 @@ virConsoleShutdown(virConsolePtr con) virEventRemoveHandle(con->stdoutWatch); con->stdinWatch =3D -1; con->stdoutWatch =3D -1; - con->quit =3D true; - virCondSignal(&con->cond); + if (!con->quit) { + con->quit =3D true; + virCondSignal(&con->cond); + } } =20 =20 @@ -388,22 +390,35 @@ virshRunConsole(vshControl *ctl, if (virDomainOpenConsole(dom, dev_name, con->st, flags) < 0) goto cleanup; =20 - con->stdinWatch =3D virEventAddHandle(STDIN_FILENO, - VIR_EVENT_HANDLE_READABLE, - virConsoleEventOnStdin, - con, - NULL); - con->stdoutWatch =3D virEventAddHandle(STDOUT_FILENO, - 0, - virConsoleEventOnStdout, - con, - NULL); - - virStreamEventAddCallback(con->st, - VIR_STREAM_EVENT_READABLE, - virConsoleEventOnStream, - con, - NULL); + virObjectRef(con); + if ((con->stdinWatch =3D virEventAddHandle(STDIN_FILENO, + VIR_EVENT_HANDLE_READABLE, + virConsoleEventOnStdin, + con, + virObjectFreeCallback)) < 0) { + virObjectUnref(con); + goto cleanup; + } + + virObjectRef(con); + if ((con->stdoutWatch =3D virEventAddHandle(STDOUT_FILENO, + 0, + virConsoleEventOnStdout, + con, + virObjectFreeCallback)) < 0)= { + virObjectUnref(con); + goto cleanup; + } + + virObjectRef(con); + if (virStreamEventAddCallback(con->st, + VIR_STREAM_EVENT_READABLE, + virConsoleEventOnStream, + con, + virObjectFreeCallback) < 0) { + virObjectUnref(con); + goto cleanup; + } =20 while (!con->quit) { if (virCondWait(&con->cond, &con->parent.lock) < 0) { @@ -415,6 +430,7 @@ virshRunConsole(vshControl *ctl, ret =3D 0; =20 cleanup: + virConsoleShutdown(con); 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