From nobody Thu Apr 25 15:31:08 2024 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=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1539288562697135.8115052457556; Thu, 11 Oct 2018 13:09:22 -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 D6C465F744; Thu, 11 Oct 2018 20:09:19 +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 367D91042557; Thu, 11 Oct 2018 20:09:19 +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 2BE014CA94; Thu, 11 Oct 2018 20:09:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9BK9H1N029195 for ; Thu, 11 Oct 2018 16:09:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 10823C0D9C; Thu, 11 Oct 2018 20:09:17 +0000 (UTC) Received: from red.redhat.com (ovpn-121-240.rdu2.redhat.com [10.10.121.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0C76C0D87 for ; Thu, 11 Oct 2018 20:09:13 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Thu, 11 Oct 2018 15:09:13 -0500 Message-Id: <20181011200913.782162-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: Fix regression with duplicated error messages 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.39]); Thu, 11 Oct 2018 20:09:20 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit 4f4c3b13 (v3.3) fixed an issue where cleaning libvirt objects lost error messages, by adding code to copy the libvirt error into last_error prior to cleanup paths. However, it caused a regression: some errors are now printed twice, because libvirt still remembers in its thread-local storage that an error was set. For example: $ virsh -c test:///default snapshot-delete test blah error: Domain snapshot not found: no domain snapshot with matching name 'bl= ah' error: Domain snapshot not found: no domain snapshot with matching name 'bl= ah' Fix things by telling libvirt to discard any thread-local errors at the same time virsh prints an error message (whether or not the libvirt error is the same as what is stored in last_error). Update the virsh-undefine testsuite (partially reverting portions of commit b620bdee, by removing -q, to more easily pinpoint which commands are causing which messages), now that there is only one error message instead of two. Signed-off-by: Eric Blake --- tests/virsh-undefine | 20 ++++++++++++++++---- tools/vsh.c | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/virsh-undefine b/tests/virsh-undefine index 974b0c71f7..4a9f68dd39 100755 --- a/tests/virsh-undefine +++ b/tests/virsh-undefine @@ -30,34 +30,46 @@ fail=3D0 # connection is opened to the test driver, it starts life with a new # persistent running domain named 'test' with a different uuid, so # testing this command requires batch mode use of virsh. -$abs_top_builddir/tools/virsh -q -c test:///default \ +$abs_top_builddir/tools/virsh -c test:///default \ 'dominfo test; undefine test; dominfo test' > out1 2>&1 test $? =3D 0 || fail=3D1 sed '/^Persistent/n; /:/d' < out1 > out cat <<\EOF > exp || fail=3D1 Persistent: yes + +Domain test has been undefined + Persistent: no + EOF compare exp out || fail=3D1 # A similar diagnostic when specifying a domain ID -$abs_top_builddir/tools/virsh -q -c test:///default \ +$abs_top_builddir/tools/virsh -c test:///default \ 'dominfo 1; undefine 1; dominfo 1' > out1 2>&1 test $? =3D 0 || fail=3D1 sed '/^Persistent/n; /:/d' < out1 > out cat <<\EOF > exp || fail=3D1 Persistent: yes + +Domain 1 has been undefined + Persistent: no + EOF compare exp out || fail=3D1 # Succeed, now: first shut down, then undefine, both via name. -$abs_top_builddir/tools/virsh -q -c test:///default \ +$abs_top_builddir/tools/virsh -c test:///default \ 'shutdown test; undefine test; dominfo test' > out 2>&1 test $? =3D 1 || fail=3D1 cat <<\EOF > expout || fail=3D1 +Domain test is being shutdown + +Domain test has been undefined + error: failed to get domain 'test' -error: Domain not found + EOF compare expout out || fail=3D1 diff --git a/tools/vsh.c b/tools/vsh.c index 9ea3c4b96a..de887a9e76 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -276,6 +276,7 @@ vshResetLibvirtError(void) { virFreeError(last_error); last_error =3D NULL; + virResetLastError(); } /* --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list