From nobody Sun Feb 8 17:47:06 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1491926056748516.5616679075597; Tue, 11 Apr 2017 08:54:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73EA83DBC4; Tue, 11 Apr 2017 15:54:15 +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 4783D7B52A; Tue, 11 Apr 2017 15:54:15 +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 E522418523CE; Tue, 11 Apr 2017 15:54:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3BFs5bp001630 for ; Tue, 11 Apr 2017 11:54:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 77C917ED84; Tue, 11 Apr 2017 15:54:05 +0000 (UTC) Received: from angien.brq.redhat.com (dhcp129-47.brq.redhat.com [10.34.129.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD1FA7ED83; Tue, 11 Apr 2017 15:54:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 73EA83DBC4 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 73EA83DBC4 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:51 +0200 Message-Id: <396ca0a42d524a2e1cae55415c8f96f7a6035cf6.1491925946.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/9] vsh: Add helper for safe remembering of libvirt errors 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 11 Apr 2017 15:54:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Avoid the annoying issue where the public object freeing APIs overwrite the error set by helper functions, since they don't invoke the callback. The new helper remembers the error only if no previous error was set. --- tools/virsh-util.c | 2 ++ tools/vsh.c | 15 +++++++++++++++ tools/vsh.h | 1 + 3 files changed, 18 insertions(+) diff --git a/tools/virsh-util.c b/tools/virsh-util.c index e225d3332..79a38bb23 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -158,6 +158,7 @@ virshDomainFree(virDomainPtr dom) if (!dom) return; + vshSaveLibvirtHelperError(); virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ } @@ -168,5 +169,6 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap) if (!snap) return; + vshSaveLibvirtHelperError(); virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */ } diff --git a/tools/vsh.c b/tools/vsh.c index d2024be91..10a65c39f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -258,6 +258,21 @@ vshSaveLibvirtError(void) last_error =3D virSaveLastError(); } + +/* Store libvirt error from helper API but don't overwrite existing errors= */ +void +vshSaveLibvirtHelperError(void) +{ + if (last_error) + return; + + if (!virGetLastError()) + return; + + vshSaveLibvirtError(); +} + + /* * Reset libvirt error on graceful fallback paths */ diff --git a/tools/vsh.h b/tools/vsh.h index 8f5d1a69f..2f686eba6 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -341,6 +341,7 @@ void vshErrorHandler(void *opaque, virErrorPtr error); void vshReportError(vshControl *ctl); void vshResetLibvirtError(void); void vshSaveLibvirtError(void); +void vshSaveLibvirtHelperError(void); /* file handling */ char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list