From nobody Tue Feb 10 01:06:00 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1505211796573592.935346403814; Tue, 12 Sep 2017 03:23:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DC5C6DDCD; Tue, 12 Sep 2017 10:23: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 5B9AF5E1D6; Tue, 12 Sep 2017 10:23: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 25E3F1864DBB; Tue, 12 Sep 2017 10:23:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8CA8dCa012861 for ; Tue, 12 Sep 2017 06:08:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6FFBA60BEB; Tue, 12 Sep 2017 10:08:39 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 930386062A; Tue, 12 Sep 2017 10:08:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7DC5C6DDCD Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 12 Sep 2017 12:09:44 +0200 Message-Id: <969a14ba3a13df435cbde395957bba6e689bf0eb.1505210917.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/3] util: error: Add helpers for saving and restoring of last error 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 12 Sep 2017 10:23:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some cleanup paths overwrite a usefull error message with a less useful one and we then try to preserve the original message. The handlers added in this patch will simplify the operations since they are designed right for the purpose. --- src/libvirt_private.syms | 2 ++ src/util/virerror.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/util/virerror.h | 3 +++ 3 files changed, 50 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f30a04b14..62e05186d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1604,6 +1604,8 @@ ebtablesRemoveForwardAllowIn; virDispatchError; virErrorCopyNew; virErrorInitialize; +virErrorPreserveLast; +virErrorRestore; virErrorSetErrnoFromLastError; virLastErrorIsSystemErrno; virRaiseErrorFull; diff --git a/src/util/virerror.c b/src/util/virerror.c index a5a2d6ed1..1f15c5dbb 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -371,6 +371,51 @@ virSaveLastError(void) return to; } + +/** + * virErrorPreserveLast: + * @saveerr: pointer to virErrorPtr for storing last error object + * + * Preserves the currently set last error (for the thread) into @saveerr s= o that + * it can be restored via virErrorRestore(). @saveerr must be passed to + * virErrorRestore() + */ +void +virErrorPreserveLast(virErrorPtr *saveerr) +{ + int saved_errno =3D errno; + virErrorPtr lasterr =3D virGetLastError(); + + *saveerr =3D NULL; + + if (lasterr) + *saveerr =3D virErrorCopyNew(lasterr); + + errno =3D saved_errno; +} + + +/** + * virErrorRestore: + * @savederr: error object holding saved error + * + * Restores the error passed via @savederr and clears associated memory. + */ +void +virErrorRestore(virErrorPtr *savederr) +{ + int saved_errno =3D errno; + + if (!*savederr) + return; + + virSetError(*savederr); + virFreeError(*savederr); + *savederr =3D NULL; + errno =3D saved_errno; +} + + /** * virResetError: * @err: pointer to the virError to clean up diff --git a/src/util/virerror.h b/src/util/virerror.h index 234864812..54530d081 100644 --- a/src/util/virerror.h +++ b/src/util/virerror.h @@ -196,4 +196,7 @@ void virErrorSetErrnoFromLastError(void); bool virLastErrorIsSystemErrno(int errnum); +void virErrorPreserveLast(virErrorPtr *saveerr); +void virErrorRestore(virErrorPtr *savederr); + #endif --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list