From nobody Wed May 14 09:41:19 2025 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; dkim=fail; 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=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525521905940836.1985948602862; Sat, 5 May 2018 05:05:05 -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 2C5294E90C; Sat, 5 May 2018 12:04:59 +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 751B65C3FD; Sat, 5 May 2018 12:04:57 +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 9D09A5BBE5; Sat, 5 May 2018 12:04:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w45C4qZW016065 for ; Sat, 5 May 2018 08:04:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id E0CCC30012A3; Sat, 5 May 2018 12:04:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9F42309128B for ; Sat, 5 May 2018 12:04:50 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E287F3680B for ; Sat, 5 May 2018 12:04:38 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id a67so7552318wmf.3 for ; Sat, 05 May 2018 05:04:38 -0700 (PDT) Received: from localhost.localdomain ([212.92.119.143]) by smtp.gmail.com with ESMTPSA id g21-v6sm7702047edm.27.2018.05.05.05.04.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 05 May 2018 05:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/uC3uzbdHTORGkcX/ZAo0o+oVI4BYn3I/tcGqXvLBKE=; b=ajgSUykVhp6VI3v9F/sb6DaZYJimT++JinkATY37ZjIaooOqdH6oOsdD5bZoDD3v/5 EBNge6A2ywwvWn+P/JVCS8oRP9o3U5AVTSSXH+htAAIvOpQEg2pW623NMYdqlgUp0Dxz get4L558ii3Rzpba/f2Ry/5VPnIQpkZSWgRTzntkupeSoxwl4sQEofCi+9bQgsd0QzBx ZIK5axOUFftEhwlJFSMmhEG45OjJahb9HHySyonXJTbmshsV06nAbdz0DdgeJdoZHHW2 PPwcl76YSKDzja+xs15EcAqwbyN/JaK+O+s/Nbh74fHkW3w3EOQk36hSaj1Am/XeUjLI 2gPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/uC3uzbdHTORGkcX/ZAo0o+oVI4BYn3I/tcGqXvLBKE=; b=CttbAs3avhr0O45t05yfCk73EvGQwEdzzFazCpsW5IV5zN9bECIJvMMaY3MGgS9tlu ish/P3mBC56qhhG6Bv0Sc850mS+2MqLRhiG6/Gu0iujiSv/fZmZT7hq+DT2pnjJgPRWF yaIUVlt3DfqKEVWSohKqrQcwPzzvj+39N3e6gaL4f/myCoOB3wOWqRxg8VWYDGYZrk22 zVig2gUiRT3y8gI/jCOALK+jjU1vy8noCTT2qB21EDfs1THHBjHSxz51WFA7ChSaugNV JffqQ0a6KravUGEGQuI3clOsi9pfrmdJkEKDPkPRkVGK0S2kW+Cd4SCsvhG28Rcy0dYc pTjQ== X-Gm-Message-State: ALQs6tBATmAfdwECypcckr8qqQopxw7B/53SQabAba/9d1lfF/Sg2Bd9 Osx3/YBc0kfwfrtrSsfn0JpR2g== X-Google-Smtp-Source: AB8JxZpE4dHB+eR4LuIDEnfnrDPe1r79gnovkMfSiWMBMVUZyh430Fnc+hp7htwqio3uiFJm1QSC5Q== X-Received: by 2002:a50:d59e:: with SMTP id v30-v6mr40731107edi.167.1525521877504; Sat, 05 May 2018 05:04:37 -0700 (PDT) From: ramyelkest To: libvir-list@redhat.com Date: Sat, 5 May 2018 13:04:20 +0100 Message-Id: <1525521861-32624-3-git-send-email-ramyelkest@gmail.com> In-Reply-To: <1525521861-32624-1-git-send-email-ramyelkest@gmail.com> References: <1525521861-32624-1-git-send-email-ramyelkest@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 05 May 2018 12:04:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 05 May 2018 12:04:39 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.google.com' FROM:'ramyelkest@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.82.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: ramyelkest Subject: [libvirt] [PATCH 2/3] util: added virGetLastErrorCode/Domain 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.38]); Sat, 05 May 2018 12:05:04 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Many places in the code call virGetLastError() just to check the raised error code, or domain. However virGetLastError() can return NULL, so the code has to check for that first. This patch therefore introduces virGetLasErrorCode/Domain function which always returns a valid error code/domain respectively, thus dropping the need to perform any checks on the error object. Signed-off-by: Ramy Elkest Reviewed-by: Erik Skultety --- include/libvirt/virterror.h | 2 ++ src/libvirt_public.syms | 6 ++++++ src/util/virerror.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 3e7c7a0..5e58b6a 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -344,6 +344,8 @@ void virResetLastError (void); void virResetError (virErrorPtr err); void virFreeError (virErrorPtr err); =20 +int virGetLastErrorCode (void); +int virGetLastErrorDomain (void); const char * virGetLastErrorMessage (void); =20 virErrorPtr virConnGetLastError (virConnectPtr conn); diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 95df3a0..85b6b6d 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -785,4 +785,10 @@ LIBVIRT_4.1.0 { virStoragePoolLookupByTargetPath; } LIBVIRT_3.9.0; =20 +LIBVIRT_4.4.0 { + global: + virGetLastErrorCode; + virGetLastErrorDomain; +} LIBVIRT_4.1.0; + # .... define new API here using predicted next version number .... diff --git a/src/util/virerror.c b/src/util/virerror.c index c000b00..842fc49 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -272,6 +272,48 @@ virGetLastError(void) =20 =20 /** + * virGetLastErrorCode: + * + * Get the most recent error code + * + * The error object is kept in thread local storage, so separate + * threads can safely access this concurrently. + * + * Returns the most recent error code in this thread, + * or VIR_ERR_OK if none is set + */ +int +virGetLastErrorCode(void) +{ + virErrorPtr err =3D virLastErrorObject(); + if (!err) + return VIR_ERR_OK; + return err->code; +} + + +/** + * virGetLastErrorDomain: + * + * Get the most recent error domain + * + * The error object is kept in thread local storage, so separate + * threads can safely access this concurrently. + * + * Returns the most recent error code in this thread, + * or VIR_FROM_NONE if none is set + */ +int +virGetLastErrorDomain(void) +{ + virErrorPtr err =3D virLastErrorObject(); + if (!err) + return VIR_FROM_NONE; + return err->domain; +} + + +/** * virGetLastErrorMessage: * * Get the most recent error message --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list