From nobody Wed May 14 08:07:11 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; 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 1524157852796287.540863205595; Thu, 19 Apr 2018 10:10:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DCC83150098; Thu, 19 Apr 2018 17:10:51 +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 1207B89E7F; Thu, 19 Apr 2018 17:10:51 +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 B9C0B1805972; Thu, 19 Apr 2018 17:10:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3JHAEW8015133 for ; Thu, 19 Apr 2018 13:10:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8677321A468D; Thu, 19 Apr 2018 17:10:14 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EB582026DFD; Thu, 19 Apr 2018 17:10:13 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 19 Apr 2018 18:09:55 +0100 Message-Id: <20180419171002.17117-8-berrange@redhat.com> In-Reply-To: <20180419171002.17117-1-berrange@redhat.com> References: <20180419171002.17117-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/14] driver: use normal error reporting APIs when loading modules 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: , Content-Type: text/plain; charset="utf-8" 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 19 Apr 2018 17:10:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The driver module loading code is one of the few places that still uses VIR_ERROR for reporting failures. Convert it to normal error reporting APIs. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/driver.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/driver.c b/src/driver.c index e02efe2615..9b137c39e4 100644 --- a/src/driver.c +++ b/src/driver.c @@ -33,6 +33,7 @@ =20 VIR_LOG_INIT("driver"); =20 +#define VIR_FROM_THIS VIR_FROM_NONE =20 /* XXX re-implement this for other OS, or use libtools helper lib ? */ #define DEFAULT_DRIVER_DIR LIBDIR "/libvirt/connection-driver" @@ -55,8 +56,11 @@ virDriverLoadModuleFile(const char *file) =20 virUpdateSelfLastChanged(file); =20 - if (!(handle =3D dlopen(file, flags))) - VIR_ERROR(_("failed to load module %s %s"), file, dlerror()); + if (!(handle =3D dlopen(file, flags))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to load module '%s': %s"), file, dlerror(= )); + return NULL; + } =20 return handle; } @@ -64,14 +68,19 @@ virDriverLoadModuleFile(const char *file) =20 static void * virDriverLoadModuleFunc(void *handle, + const char *file, const char *funcname) { void *regsym; =20 VIR_DEBUG("Lookup function '%s'", funcname); =20 - if (!(regsym =3D dlsym(handle, funcname))) - VIR_ERROR(_("Missing module registration symbol %s"), funcname); + if (!(regsym =3D dlsym(handle, funcname))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to find symbol '%s' in module '%s': %s"), + funcname, file, dlerror()); + return NULL; + } =20 return regsym; } @@ -108,11 +117,18 @@ virDriverLoadModuleFull(const char *path, if (!(rethandle =3D virDriverLoadModuleFile(path))) goto cleanup; =20 - if (!(regsym =3D virDriverLoadModuleFunc(rethandle, regfunc))) + if (!(regsym =3D virDriverLoadModuleFunc(rethandle, path, regfunc))) goto cleanup; =20 if ((*regsym)() < 0) { - VIR_ERROR(_("Failed module registration %s"), regfunc); + /* regsym() should report an error itself, but lets + * just make sure */ + virErrorPtr err =3D virGetLastError(); + if (err =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to execute symbol '%s' in module '%s'= "), + regfunc, path); + } goto cleanup; } =20 @@ -131,7 +147,11 @@ virDriverLoadModuleFull(const char *path ATTRIBUTE_UNU= SED, const char *regfunc ATTRIBUTE_UNUSED) { VIR_DEBUG("dlopen not available on this platform"); - return -1; + /* Since we have no dlopen(), but definition we have no + * loadable modules on disk, so we can resaonably + * return '1' instead of an error. + */ + return 1; } #endif /* ! HAVE_DLFCN_H */ =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list