From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704871; cv=none; d=zoho.com; s=zohoarc; b=PZUx5BtAsEI5jCLKbKJGAXHMfVoZzNCTK+yju/DtD/DBPGgIjyXwT+2NJgk8Fz1gxl5tjIsBITAaj21tuyJnfXQa6zr/LZ+ij5MP/D0rGkMmW7Yvck4WWGo2NTvetqFwEqm+G5M/rCniuTv+30YyPu4peXj0WXUwcQ2kDhpMvug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704871; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m9d5PWvbz7Sc7W7XZzF31DqkCYttj/7zY4QcAk8et5U=; b=VQXCzWwROjiybU//BRDFoj2Ksbnr8rMx0WHBqGX5B+k3C2lnA2MwkzoUk56R+xAOoibHXWNRfAtsfwJNRD9F26Oi4gtUz1MV61fNSuqyhh2DpMmyGCzo2hVsozVQUvTC1rSXVpQOWIV6n5pN8uBO95vEHWM5k9XxZA60tODC5sU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15707048712701023.1569856220004; Thu, 10 Oct 2019 03:54:31 -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 69B60A44AFD; Thu, 10 Oct 2019 10:54:29 +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 40B746092F; Thu, 10 Oct 2019 10:54:29 +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 035CE180B76F; Thu, 10 Oct 2019 10:54:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsIjU010334 for ; Thu, 10 Oct 2019 06:54:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6CCF5C231; Thu, 10 Oct 2019 10:54:18 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1A1C5C1B5; Thu, 10 Oct 2019 10:54:17 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:53:55 +0100 Message-Id: <20191010105413.4091-2-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= , Pavel Hrdina Subject: [libvirt] [PATCH v3 01/19] build: probe for glib-2 library in configure 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.6.2 (mx1.redhat.com [10.5.110.68]); Thu, 10 Oct 2019 10:54:30 +0000 (UTC) Prepare for linking with glib by probing for it at configure time. Per supported platforms target, the min glib versions on relevant distros are: RHEL-8: 2.56.1 RHEL-7: 2.50.3 Debian (Buster): 2.58.3 Debian (Stretch): 2.50.3 OpenBSD (Ports): 2.58.3 FreeBSD (Ports): 2.56.3 OpenSUSE Leap 15: 2.54.3 SLE12-SP2: 2.48.2 Ubuntu (Xenial): 2.48.0 macOS (Homebrew): 2.56.0 This suggests that a minimum glib of 2.48 is a reasonable target. This aligns with the minimum version required by qemu too. We must disable the bad-function-cast warning as various GLib APIs and macros will trigger this. Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- .travis.yml | 1 + configure.ac | 2 ++ libvirt.spec.in | 1 + m4/virt-compile-warnings.m4 | 2 ++ m4/virt-glib.m4 | 36 ++++++++++++++++++++++++++++++++++++ mingw-libvirt.spec.in | 2 ++ 6 files changed, 44 insertions(+) create mode 100644 m4/virt-glib.m4 diff --git a/.travis.yml b/.travis.yml index e475af34cf..478909d3bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ addons: - rpcgen - xz - yajl + - glib =20 matrix: include: diff --git a/configure.ac b/configure.ac index f6bf4fb60a..9b4e6fdd6d 100644 --- a/configure.ac +++ b/configure.ac @@ -311,6 +311,7 @@ LIBVIRT_CHECK_DLOPEN LIBVIRT_CHECK_FIREWALLD LIBVIRT_CHECK_FIREWALLD_ZONE LIBVIRT_CHECK_FUSE +LIBVIRT_CHECK_GLIB LIBVIRT_CHECK_GLUSTER LIBVIRT_CHECK_GNUTLS LIBVIRT_CHECK_HAL @@ -1007,6 +1008,7 @@ LIBVIRT_RESULT_DLOPEN LIBVIRT_RESULT_FIREWALLD LIBVIRT_RESULT_FIREWALLD_ZONE LIBVIRT_RESULT_FUSE +LIBVIRT_RESULT_GLIB LIBVIRT_RESULT_GLUSTER LIBVIRT_RESULT_GNUTLS LIBVIRT_RESULT_HAL diff --git a/libvirt.spec.in b/libvirt.spec.in index 7f5183f341..dcad08cb5f 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -273,6 +273,7 @@ BuildRequires: systemd-units %if %{with_libxl} BuildRequires: xen-devel %endif +BuildRequires: glib2-devel >=3D 2.48 BuildRequires: libxml2-devel BuildRequires: libxslt BuildRequires: readline-devel diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index 4f9eee121c..1dbe1abe27 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -67,6 +67,8 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ # > to handle the code effectively. # Source: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html dontwarn=3D"$dontwarn -Wdisabled-optimization" + # Various valid glib APIs/macros trigger this warning + dontwarn=3D"$dontwarn -Wbad-function-cast" =20 # Broken in 6.0 and later # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D69602 diff --git a/m4/virt-glib.m4 b/m4/virt-glib.m4 new file mode 100644 index 0000000000..5a5bc19660 --- /dev/null +++ b/m4/virt-glib.m4 @@ -0,0 +1,36 @@ +dnl The glib.so library +dnl +dnl Copyright (C) 2016 Red Hat, Inc. +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library. If not, see +dnl . +dnl + +AC_DEFUN([LIBVIRT_ARG_GLIB], [ + LIBVIRT_ARG_WITH([GLIB], [glib-2.0 location], [check]) +]) + +AC_DEFUN([LIBVIRT_CHECK_GLIB],[ + GLIB_REQUIRED=3D2.48.0 + + LIBVIRT_CHECK_PKG([GLIB], [glib-2.0], [$GLIB_REQUIRED]) + + if test "$with_glib" =3D "no" ; then + AC_MSG_ERROR([glib-2.0 >=3D $GLIB_REQUIRED is required for libvirt]) + fi +]) + +AC_DEFUN([LIBVIRT_RESULT_GLIB], [ + LIBVIRT_RESULT_LIB([GLIB]) +]) diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in index a20c4b7d74..c29f3eeed2 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -52,6 +52,8 @@ BuildRequires: mingw32-gcc BuildRequires: mingw64-gcc BuildRequires: mingw32-binutils BuildRequires: mingw64-binutils +BuildRequires: mingw32-glib2 >=3D 2.48 +BuildRequires: mingw64-glib2 >=3D 2.48 BuildRequires: mingw32-libgpg-error BuildRequires: mingw64-libgpg-error BuildRequires: mingw32-libgcrypt --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704864; cv=none; d=zoho.com; s=zohoarc; b=PBUGuuOBlEIl2B1VdSJLerWbQMkOUriiyokcNjJgUuVakl24XaA8SyIwn/9J43bQ7sMkeJBDuElHbeK3jk2PLvv5/B4MBRD6Kiad9gnceRYdqOWCU4XckaYksRFN9khZYIEOdrTJJj7HXxY0oGntgLtNHC6L5r9LISFUw6XtXC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704864; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4i0+UpHX2/yWVjwnqZDJSNhfYUoUoFnhz8KVMbR/zIE=; b=aim9XasJjQx7DlTth+UuXT4Z56o7osauphsYGQfBDdzMUj2udJ6CnAioiB7vffm8p60CtEvlzaGs8hc+uAuNPTknYgLHQ6Jkj7Tu+rVTycrgNhFWfJBGC/kzWZFRpUVZ8eKwvalGLdzwn/on3RH+DX9YfCFPtwIIifPg1oznG8s= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704864953898.1388353136996; Thu, 10 Oct 2019 03:54:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D76E30860C3; Thu, 10 Oct 2019 10:54:22 +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 53EF019D70; Thu, 10 Oct 2019 10:54:22 +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 D5419180085A; Thu, 10 Oct 2019 10:54:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsJKe010344 for ; Thu, 10 Oct 2019 06:54:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id B688A5C22C; Thu, 10 Oct 2019 10:54:19 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12B9D5C1B5; Thu, 10 Oct 2019 10:54:18 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:53:56 +0100 Message-Id: <20191010105413.4091-3-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/19] build: link to glib library 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 10 Oct 2019 10:54:23 +0000 (UTC) Add the main glib.h to internal.h so that all common code can use it. Historically glib allowed applications to register an alternative memory allocator, so mixing g_malloc/g_free with malloc/free was not safe. This was feature was dropped in 2.46.0 with: commit 3be6ed60aa58095691bd697344765e715a327fc1 Author: Alexander Larsson Date: Sat Jun 27 18:38:42 2015 +0200 Deprecate and drop support for memory vtables Applications are still encourged to match g_malloc/g_free, but it is no longer a mandatory requirement for correctness, just stylistic. This is explicitly clarified in commit 1f24b36607bf708f037396014b2cdbc08d67b275 Author: Daniel P. Berrang=C3=A9 Date: Thu Sep 5 14:37:54 2019 +0100 gmem: clarify that g_malloc always uses the system allocator Applications can still use custom allocators in general, but they must do this by linking to a library that replaces the core malloc/free implemenentation entirely, instead of via a glib specific call. This means that libvirt does not need to be concerned about use of g_malloc/g_free causing an ABI change in the public libary, and can avoid memory copying when talking to external libraries. This patch probes for glib, which provides the foundation layer with a collection of data structures, helper APIs, and platform portability logic. Later patches will introduce linkage to gobject which provides the object type system, built on glib, and gio which providing objects for various interesting tasks, most notably including DBus client and server support and portable sockets APIs, but much more too. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- docs/hacking.html.in | 21 +++++++++++++++++++++ src/Makefile.am | 3 +++ src/access/Makefile.inc.am | 4 +++- src/bhyve/Makefile.inc.am | 1 + src/interface/Makefile.inc.am | 1 + src/internal.h | 1 + src/libxl/Makefile.inc.am | 1 + src/locking/Makefile.inc.am | 9 ++++++++- src/logging/Makefile.inc.am | 1 + src/lxc/Makefile.inc.am | 4 ++++ src/network/Makefile.inc.am | 2 ++ src/node_device/Makefile.inc.am | 5 ++++- src/nwfilter/Makefile.inc.am | 1 + src/qemu/Makefile.inc.am | 1 + src/remote/Makefile.inc.am | 2 ++ src/secret/Makefile.inc.am | 1 + src/security/Makefile.inc.am | 1 + src/storage/Makefile.inc.am | 16 ++++++++++++++++ src/vbox/Makefile.inc.am | 1 + src/vz/Makefile.inc.am | 1 + tests/Makefile.am | 7 +++++-- tools/Makefile.am | 4 ++++ 22 files changed, 83 insertions(+), 5 deletions(-) diff --git a/docs/hacking.html.in b/docs/hacking.html.in index edf2f54ce3..2e064ced5e 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -989,6 +989,27 @@ BAD: it points to, or it is aliased to another pointer that is.

=20 +

Adoption of GLib APIs

+ +

+ Libvirt has adopted use of the + GLib library. + Due to libvirt's long history of development, there are many APIs + in libvirt, for which GLib provides an alternative solution. The + general rule to follow is that the standard GLib solution will be + preferred over historical libvirt APIs. Existing code will be + ported over to use GLib APIs over time, but new code should use + the GLib APIs straight away where possible. +

+ +

+ The following is a list of libvirt APIs that should no longer be + used in new code, and their suggested GLib replacements: +

+ +
+
+

Low level memory management

=20

diff --git a/src/Makefile.am b/src/Makefile.am index bd03b09cb2..e646e954a4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,7 @@ AM_CPPFLAGS =3D -I../gnulib/lib \ WARN_CFLAGS +=3D $(STRICT_FRAME_LIMIT_CFLAGS) =20 AM_CFLAGS =3D $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(WARN_CFLAGS) \ $(LOCK_CHECKING_CFLAGS) \ $(WIN32_EXTRA_CFLAGS) \ @@ -558,6 +559,7 @@ libvirt_admin_la_LIBADD +=3D \ $(YAJL_LIBS) \ $(DEVMAPPER_LIBS) \ $(LIBXML_LIBS) \ + $(GLIB_LIBS) \ $(SSH2_LIBS) \ $(SASL_LIBS) \ $(GNUTLS_LIBS) \ @@ -773,6 +775,7 @@ libvirt_iohelper_LDFLAGS =3D \ $(NULL) libvirt_iohelper_LDADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la if WITH_DTRACE_PROBES libvirt_iohelper_LDADD +=3D libvirt_probes.lo diff --git a/src/access/Makefile.inc.am b/src/access/Makefile.inc.am index 4dc742f4e5..ea27adbe0b 100644 --- a/src/access/Makefile.inc.am +++ b/src/access/Makefile.inc.am @@ -59,7 +59,9 @@ libvirt_driver_access_la_CFLAGS =3D \ $(AM_CFLAGS) \ $(NULL) libvirt_driver_access_la_LDFLAGS =3D $(AM_LDFLAGS) -libvirt_driver_access_la_LIBADD =3D +libvirt_driver_access_la_LIBADD =3D \ + $(GLIB_LIBS) \ + $(NULL) =20 =20 $(ACCESS_DRIVER_POLKIT_POLICY): $(srcdir)/access/viraccessperm.h \ diff --git a/src/bhyve/Makefile.inc.am b/src/bhyve/Makefile.inc.am index 195069872a..a881a83c56 100644 --- a/src/bhyve/Makefile.inc.am +++ b/src/bhyve/Makefile.inc.am @@ -34,6 +34,7 @@ libvirt_driver_bhyve_la_SOURCES =3D libvirt_driver_bhyve_la_LIBADD =3D \ libvirt_driver_bhyve_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) mod_LTLIBRARIES +=3D libvirt_driver_bhyve.la diff --git a/src/interface/Makefile.inc.am b/src/interface/Makefile.inc.am index baa85b4ba9..643e041232 100644 --- a/src/interface/Makefile.inc.am +++ b/src/interface/Makefile.inc.am @@ -28,6 +28,7 @@ libvirt_driver_interface_la_CFLAGS =3D \ libvirt_driver_interface_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) libvirt_driver_interface_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ $(NULL) libvirt_driver_interface_la_SOURCES =3D $(INTERFACE_DRIVER_SOURCES) if WITH_NETCF diff --git a/src/internal.h b/src/internal.h index e1a69be9f2..56e99241b0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -28,6 +28,7 @@ #include #include #include +#include =20 #if STATIC_ANALYSIS # undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble. */ diff --git a/src/libxl/Makefile.inc.am b/src/libxl/Makefile.inc.am index c53396b7f3..49c6b4b12f 100644 --- a/src/libxl/Makefile.inc.am +++ b/src/libxl/Makefile.inc.am @@ -34,6 +34,7 @@ libvirt_driver_libxl_la_SOURCES =3D libvirt_driver_libxl_la_LIBADD =3D \ libvirt_driver_libxl_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) mod_LTLIBRARIES +=3D libvirt_driver_libxl.la diff --git a/src/locking/Makefile.inc.am b/src/locking/Makefile.inc.am index fae92a6e45..207aa9d7ef 100644 --- a/src/locking/Makefile.inc.am +++ b/src/locking/Makefile.inc.am @@ -103,6 +103,7 @@ lockd_la_CFLAGS =3D \ lockd_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) lockd_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) augeas_DATA +=3D locking/libvirt_lockd.aug @@ -145,6 +146,7 @@ virtlockd_LDFLAGS =3D \ virtlockd_LDADD =3D \ libvirt.la \ libvirt_driver_admin.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(CYGWIN_EXTRA_LIBADD) \ $(NULL) @@ -163,7 +165,12 @@ lockdriver_LTLIBRARIES +=3D sanlock.la sanlock_la_SOURCES =3D $(LOCK_DRIVER_SANLOCK_SOURCES) sanlock_la_CFLAGS =3D -I$(srcdir)/conf $(AM_CFLAGS) sanlock_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) -sanlock_la_LIBADD =3D -lsanlock_client libvirt.la ../gnulib/lib/libgnu.la +sanlock_la_LIBADD =3D \ + -lsanlock_client \ + libvirt.la \ + $(GLIB_LIBS) \ + ../gnulib/lib/libgnu.la \ + $(NULL) =20 augeas_DATA +=3D locking/libvirt_sanlock.aug =20 diff --git a/src/logging/Makefile.inc.am b/src/logging/Makefile.inc.am index 7e441dbffb..d7cb22f8bc 100644 --- a/src/logging/Makefile.inc.am +++ b/src/logging/Makefile.inc.am @@ -82,6 +82,7 @@ virtlogd_LDFLAGS =3D \ virtlogd_LDADD =3D \ libvirt_driver_admin.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(CYGWIN_EXTRA_LIBADD) \ $(NULL) diff --git a/src/lxc/Makefile.inc.am b/src/lxc/Makefile.inc.am index b4d560702c..0b8d4e5273 100644 --- a/src/lxc/Makefile.inc.am +++ b/src/lxc/Makefile.inc.am @@ -83,6 +83,7 @@ libvirt_driver_lxc_la_SOURCES =3D libvirt_driver_lxc_la_LIBADD =3D \ libvirt_driver_lxc_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) mod_LTLIBRARIES +=3D libvirt_driver_lxc.la @@ -184,10 +185,12 @@ libvirt_lxc_LDFLAGS =3D \ $(PIE_LDFLAGS) \ $(CAPNG_LIBS) \ $(LIBXML_LIBS) \ + $(GLIB_LIBS) \ $(NULL) libvirt_lxc_LDADD =3D \ libvirt.la \ $(FUSE_LIBS) \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) if WITH_DTRACE_PROBES @@ -200,6 +203,7 @@ libvirt_lxc_CFLAGS =3D \ $(PIE_CFLAGS) \ $(CAPNG_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(LIBNL_CFLAGS) \ $(FUSE_CFLAGS) \ $(DBUS_CFLAGS) \ diff --git a/src/network/Makefile.inc.am b/src/network/Makefile.inc.am index 17467a65ad..6a1bea7aed 100644 --- a/src/network/Makefile.inc.am +++ b/src/network/Makefile.inc.am @@ -32,6 +32,7 @@ libvirt_driver_network_la_SOURCES =3D libvirt_driver_network_la_LIBADD =3D \ libvirt_driver_network_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(LIBNL_LIBS) \ $(DBUS_LIBS) \ @@ -121,6 +122,7 @@ libvirt_leaseshelper_LDFLAGS =3D \ $(NULL) libvirt_leaseshelper_LDADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la if WITH_DTRACE_PROBES libvirt_leaseshelper_LDADD +=3D libvirt_probes.lo diff --git a/src/node_device/Makefile.inc.am b/src/node_device/Makefile.inc= .am index eac7f92e88..9e07bae839 100644 --- a/src/node_device/Makefile.inc.am +++ b/src/node_device/Makefile.inc.am @@ -44,7 +44,10 @@ libvirt_driver_nodedev_la_CFLAGS =3D \ $(LIBNL_CFLAGS) \ $(NULL) libvirt_driver_nodedev_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) -libvirt_driver_nodedev_la_LIBADD =3D libvirt.la +libvirt_driver_nodedev_la_LIBADD =3D \ + libvirt.la \ + $(GLIB_LIBS) \ + $(NULL) =20 if WITH_HAL libvirt_driver_nodedev_la_SOURCES +=3D $(NODE_DEVICE_DRIVER_HAL_SOURCES) diff --git a/src/nwfilter/Makefile.inc.am b/src/nwfilter/Makefile.inc.am index 6acb45705c..ceba8558fb 100644 --- a/src/nwfilter/Makefile.inc.am +++ b/src/nwfilter/Makefile.inc.am @@ -46,6 +46,7 @@ libvirt_driver_nwfilter_impl_la_LIBADD =3D \ $(LIBPCAP_LIBS) \ $(LIBNL_LIBS) \ $(DBUS_LIBS) \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) libvirt_driver_nwfilter_impl_la_SOURCES =3D $(NWFILTER_DRIVER_SOURCES) diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index e0e13fb1c3..e66da76c0a 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -83,6 +83,7 @@ libvirt_driver_qemu_la_SOURCES =3D libvirt_driver_qemu_la_LIBADD =3D \ libvirt_driver_qemu_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) mod_LTLIBRARIES +=3D libvirt_driver_qemu.la diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am index 5a5c90a922..ae11e6592d 100644 --- a/src/remote/Makefile.inc.am +++ b/src/remote/Makefile.inc.am @@ -38,6 +38,7 @@ REMOTE_DAEMON_SOURCES =3D \ =20 REMOTE_DAEMON_CFLAGS =3D \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(SASL_CFLAGS) \ $(XDR_CFLAGS) \ @@ -76,6 +77,7 @@ REMOTE_DAEMON_LD_ADD +=3D ../src/libvirt_probes.lo endif WITH_DTRACE_PROBES =20 REMOTE_DAEMON_LD_ADD +=3D \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) =20 diff --git a/src/secret/Makefile.inc.am b/src/secret/Makefile.inc.am index 76bc67418c..41a5e23da2 100644 --- a/src/secret/Makefile.inc.am +++ b/src/secret/Makefile.inc.am @@ -33,6 +33,7 @@ libvirt_driver_secret_la_CFLAGS =3D \ $(NULL) libvirt_driver_secret_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) libvirt_driver_secret_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) diff --git a/src/security/Makefile.inc.am b/src/security/Makefile.inc.am index 64e0f46857..6fe9d50f29 100644 --- a/src/security/Makefile.inc.am +++ b/src/security/Makefile.inc.am @@ -73,6 +73,7 @@ virt_aa_helper_LDFLAGS =3D \ virt_aa_helper_LDADD =3D \ libvirt.la \ libvirt_driver_storage_impl.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) if WITH_DTRACE_PROBES diff --git a/src/storage/Makefile.inc.am b/src/storage/Makefile.inc.am index 4dccb14ac1..6d5093b6a0 100644 --- a/src/storage/Makefile.inc.am +++ b/src/storage/Makefile.inc.am @@ -136,6 +136,7 @@ libvirt_driver_storage_la_SOURCES =3D libvirt_driver_storage_la_LIBADD =3D \ libvirt_driver_storage_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) mod_LTLIBRARIES +=3D libvirt_driver_storage.la @@ -217,6 +218,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _fs.la libvirt_storage_backend_fs_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_fs_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) =20 @@ -230,6 +232,7 @@ storagefile_LTLIBRARIES +=3D libvirt_storage_file_fs.la libvirt_storage_file_fs_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_file_fs_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE @@ -245,6 +248,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _logical.la libvirt_storage_backend_logical_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_logical_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE_LVM @@ -261,6 +265,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _iscsi.la libvirt_storage_backend_iscsi_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_iscsi_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE_ISCSI @@ -279,6 +284,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _iscsi-direct.la libvirt_storage_backend_iscsi_direct_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_iscsi_direct_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(LIBISCSI_LIBS) \ $(NULL) @@ -295,6 +301,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _scsi.la libvirt_storage_backend_scsi_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_scsi_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE_SCSI @@ -304,6 +311,7 @@ libvirt_storage_backend_mpath_la_SOURCES =3D $(STORAGE_= DRIVER_MPATH_SOURCES) libvirt_storage_backend_mpath_la_LIBADD =3D \ libvirt.la \ $(DEVMAPPER_LIBS) \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) libvirt_storage_backend_mpath_la_CFLAGS =3D \ @@ -327,6 +335,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _disk.la libvirt_storage_backend_disk_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_disk_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE_DISK @@ -336,6 +345,7 @@ libvirt_storage_backend_rbd_la_SOURCES =3D $(STORAGE_DR= IVER_RBD_SOURCES) libvirt_storage_backend_rbd_la_LIBADD =3D \ libvirt.la \ $(LIBRBD_LIBS) \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) libvirt_storage_backend_rbd_la_CFLAGS =3D \ @@ -368,6 +378,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _sheepdog.la libvirt_storage_backend_sheepdog_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_sheepdog_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE_SHEEPDOG @@ -378,6 +389,7 @@ libvirt_storage_backend_gluster_la_SOURCES =3D \ libvirt_storage_backend_gluster_la_LIBADD =3D \ libvirt.la \ $(GLUSTERFS_LIBS) \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) libvirt_storage_backend_gluster_la_CFLAGS =3D \ @@ -395,6 +407,7 @@ libvirt_storage_file_gluster_la_SOURCES =3D \ libvirt_storage_file_gluster_la_LIBADD =3D \ libvirt.la \ $(GLUSTERFS_LIBS) \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) libvirt_storage_file_gluster_la_CFLAGS =3D \ @@ -419,6 +432,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _zfs.la libvirt_storage_backend_zfs_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_zfs_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE_ZFS @@ -435,6 +449,7 @@ storagebackend_LTLIBRARIES +=3D libvirt_storage_backend= _vstorage.la libvirt_storage_backend_vstorage_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) libvirt_storage_backend_vstorage_la_LIBADD =3D \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) endif WITH_STORAGE_VSTORAGE @@ -450,6 +465,7 @@ libvirt_parthelper_LDFLAGS =3D \ libvirt_parthelper_LDADD =3D \ $(LIBPARTED_LIBS) \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) if WITH_DTRACE_PROBES diff --git a/src/vbox/Makefile.inc.am b/src/vbox/Makefile.inc.am index 178c360b99..35e370ac32 100644 --- a/src/vbox/Makefile.inc.am +++ b/src/vbox/Makefile.inc.am @@ -46,6 +46,7 @@ libvirt_driver_vbox_la_SOURCES =3D libvirt_driver_vbox_la_LIBADD =3D \ libvirt_driver_vbox_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) mod_LTLIBRARIES +=3D libvirt_driver_vbox.la diff --git a/src/vz/Makefile.inc.am b/src/vz/Makefile.inc.am index f56fceb8f7..63fe28be37 100644 --- a/src/vz/Makefile.inc.am +++ b/src/vz/Makefile.inc.am @@ -21,6 +21,7 @@ libvirt_driver_vz_la_SOURCES =3D libvirt_driver_vz_la_LIBADD =3D \ libvirt_driver_vz_impl.la \ libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) mod_LTLIBRARIES +=3D libvirt_driver_vz.la diff --git a/tests/Makefile.am b/tests/Makefile.am index d88ad7f686..44fe51b83d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,6 +35,7 @@ AM_CFLAGS =3D \ -Dabs_srcdir=3D"\"$(abs_srcdir)\"" \ -Dabs_top_srcdir=3D"\"$(abs_top_srcdir)\"" \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(LIBNL_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(SASL_CFLAGS) \ @@ -72,7 +73,9 @@ LDADDS =3D \ $(NO_INDIRECT_LDFLAGS) \ $(PROBES_O) \ $(GNULIB_LIBS) \ - ../src/libvirt.la + ../src/libvirt.la \ + $(GLIB_LIBS) \ + $(NULL) =20 MOCKLIBS_LIBS =3D \ $(GNULIB_LIBS) \ @@ -525,7 +528,7 @@ libxlxml2domconfigtest_LDADD =3D $(libxl_LDADDS) $(LIBX= ML_LIBS) =20 libxlmock_la_SOURCES =3D \ libxlmock.c -libxlmock_la_CFLAGS =3D $(LIBXL_CFLAGS) $(LIBXML_CFLAGS) +libxlmock_la_CFLAGS =3D $(LIBXL_CFLAGS) $(LIBXML_CFLAGS) $(GLIB_CFLAGS) libxlmock_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) libxlmock_la_LIBADD =3D $(MOCKLIBS_LIBS) =20 diff --git a/tools/Makefile.am b/tools/Makefile.am index ece70384e6..68320c7246 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -36,6 +36,7 @@ AM_CFLAGS =3D \ $(COVERAGE_CFLAGS) \ $(PIE_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(GLIB_CFLAGS) \ $(NULL) =20 AM_LDFLAGS =3D \ @@ -150,6 +151,7 @@ libvirt_shell_la_LIBADD =3D \ ../src/libvirt.la \ $(LIBXML_LIBS) \ $(READLINE_LIBS) \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) libvirt_shell_la_SOURCES =3D \ @@ -195,6 +197,7 @@ virt_host_validate_LDFLAGS =3D \ =20 virt_host_validate_LDADD =3D \ ../src/libvirt.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ $(NULL) =20 @@ -221,6 +224,7 @@ virt_login_shell_helper_LDFLAGS =3D \ virt_login_shell_helper_LDADD =3D \ ../src/libvirt.la \ ../src/libvirt-lxc.la \ + $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la =20 virt_login_shell_helper_CFLAGS =3D \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704874; cv=none; d=zoho.com; s=zohoarc; b=ScnFC5zCnw03lMAGzB9yrPqmT0SA0NOZeEYS673XQfOLbXStPSuTiWeazPKJ7/BZu54jOEqTcsNCVLvOrEcf5mFt+Mfmpa/zqpf4ASTI8VQErXbFbm8iJFEOM1F+b/M2HLKhsB1Duz4NqmKccB3oznBcF1/Skh6e5pgRUjOPg1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zjV1d/dY5J8+OT47Y4ZX6WFZ/GwqvN1Kgv/IpNFowqU=; b=eJnmY4RJyPOR0p0/W7jTjs9nfLGgpj98+H12z0/Qo57d5nE42SAdZ4+7BbKfQ6LHRGo/QzD5iy25a4Gt4sipdIbb3AFHIglmnZjASTccVjdvNYVoaPbA9jFab/Y8Kh1SfB2PAr+Q4i8lOXAR/hD1c9p72prjAispza7euXUQtYg= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704874691362.3290710597796; Thu, 10 Oct 2019 03:54:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E395A3018761; Thu, 10 Oct 2019 10:54:32 +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 BE30A5D6C8; Thu, 10 Oct 2019 10:54:32 +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 808004EBC5; Thu, 10 Oct 2019 10:54:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsKVg010349 for ; Thu, 10 Oct 2019 06:54:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id A63DC5C231; Thu, 10 Oct 2019 10:54:20 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02AA95C1B5; Thu, 10 Oct 2019 10:54:19 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:53:57 +0100 Message-Id: <20191010105413.4091-4-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 03/19] util: use glib memory allocation functions 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 10 Oct 2019 10:54:33 +0000 (UTC) Convert the VIR_ALLOC family of APIs with use of the g_malloc family of APIs. Use of VIR_ALLOC related functions should be incrementally phased out over time, allowing return value checks to be dropped. Use of VIR_FREE should be replaced with auto-cleanup whenever possible. We previously used the 'calloc-posix' gnulib module because mingw does not set errno to ENOMEM on failure. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- bootstrap.conf | 1 - docs/hacking.html.in | 106 +++++-------------------------------------- src/util/viralloc.c | 29 +++--------- src/util/viralloc.h | 9 ++++ 4 files changed, 27 insertions(+), 118 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 358d783a6b..7d73584809 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -26,7 +26,6 @@ byteswap c-ctype c-strcase c-strcasestr -calloc-posix canonicalize-lgpl chown clock-time diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 2e064ced5e..8072796312 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -1008,102 +1008,20 @@ BAD:

=20
+
VIR_ALLOC, VIR_REALLOC, VIR_RESIZE_N, VIR_EXPAND_N, + VIR_SHRINK_N, VIR_FREE, VIR_APPEND_ELEMENT, VIR_INSERT_ELEMENT, + VIR_DELETE_ELEMENT
+
Prefer the GLib APIs g_new0/g_renew/g_free in most cases. + There should rarely be a need to use g_malloc/g_realloc. + Instead of using plain C arrays, it is preferrable to use + one of the GLib types, GArray, GPtrArray or GByteArray. These + all use a struct to track the array memory and size together + and efficiently resize. NEVER MIX use of the + classic libvirt memory allocation APIs and GLib APIs within + a single method. Keep the style consistent, converting existing + code to GLib style in a separate, prior commit.
=20 -

Low level memory management

- -

- Use of the malloc/free/realloc/calloc APIs is deprecated in the libv= irt - codebase, because they encourage a number of serious coding bugs and= do - not enable compile time verification of checks for NULL. Instead of = these - routines, use the macros from viralloc.h. -

- -
    -
  • To allocate a single object:

    - -
    -  virDomainPtr domain;
    -
    -  if (VIR_ALLOC(domain) < 0)
    -      return NULL;
    -
    -
  • - -
  • To allocate an array of objects:

    -
    -  virDomainPtr domains;
    -  size_t ndomains =3D 10;
    -
    -  if (VIR_ALLOC_N(domains, ndomains) < 0)
    -      return NULL;
    -
    -
  • - -
  • To allocate an array of object pointers:

    -
    -  virDomainPtr *domains;
    -  size_t ndomains =3D 10;
    -
    -  if (VIR_ALLOC_N(domains, ndomains) < 0)
    -      return NULL;
    -
    -
  • - -
  • To re-allocate the array of domains to be 1 element - longer (however, note that repeatedly expanding an array by 1 - scales quadratically, so this is recommended only for smaller - arrays):

    -
    -  virDomainPtr domains;
    -  size_t ndomains =3D 0;
    -
    -  if (VIR_EXPAND_N(domains, ndomains, 1) < 0)
    -      return NULL;
    -  domains[ndomains - 1] =3D domain;
    -
  • - -
  • To ensure an array has room to hold at least one more - element (this approach scales better, but requires tracking - allocation separately from usage)

    - -
    -  virDomainPtr domains;
    -  size_t ndomains =3D 0;
    -  size_t ndomains_max =3D 0;
    -
    -  if (VIR_RESIZE_N(domains, ndomains_max, ndomains, 1) < 0)
    -      return NULL;
    -  domains[ndomains++] =3D domain;
    -
    -
  • - -
  • To trim an array of domains from its allocated size down - to the actual used size:

    - -
    -  virDomainPtr domains;
    -  size_t ndomains =3D x;
    -  size_t ndomains_max =3D y;
    -
    -  VIR_SHRINK_N(domains, ndomains_max, ndomains_max - ndomains);
    -
  • - -
  • To free an array of domains:

    -
    -  virDomainPtr domains;
    -  size_t ndomains =3D x;
    -  size_t ndomains_max =3D y;
    -  size_t i;
    -
    -  for (i =3D 0; i < ndomains; i++)
    -      VIR_FREE(domains[i]);
    -  VIR_FREE(domains);
    -  ndomains_max =3D ndomains =3D 0;
    -
    -
  • -
-

File handling

=20

diff --git a/src/util/viralloc.c b/src/util/viralloc.c index 10a8d0fb73..b8ca850764 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -45,10 +45,7 @@ VIR_LOG_INIT("util.alloc"); int virAlloc(void *ptrptr, size_t size) { - *(void **)ptrptr =3D calloc(1, size); - if (*(void **)ptrptr =3D=3D NULL) - abort(); - + *(void **)ptrptr =3D g_malloc0(size); return 0; } =20 @@ -69,10 +66,7 @@ int virAllocN(void *ptrptr, size_t size, size_t count) { - *(void**)ptrptr =3D calloc(count, size); - if (*(void**)ptrptr =3D=3D NULL) - abort(); - + *(void**)ptrptr =3D g_malloc0_n(count, size); return 0; } =20 @@ -94,16 +88,7 @@ int virReallocN(void *ptrptr, size_t size, size_t count) { - void *tmp; - - if (xalloc_oversized(count, size)) - abort(); - - tmp =3D realloc(*(void**)ptrptr, size * count); - if (!tmp && ((size * count) !=3D 0)) - abort(); - - *(void**)ptrptr =3D tmp; + *(void **)ptrptr =3D g_realloc_n(*(void**)ptrptr, size, count); return 0; } =20 @@ -343,9 +328,7 @@ int virAllocVar(void *ptrptr, abort(); =20 alloc_size =3D struct_size + (element_size * count); - *(void **)ptrptr =3D calloc(1, alloc_size); - if (*(void **)ptrptr =3D=3D NULL) - abort(); + *(void **)ptrptr =3D g_malloc0(alloc_size); return 0; } =20 @@ -362,7 +345,7 @@ void virFree(void *ptrptr) { int save_errno =3D errno; =20 - free(*(void**)ptrptr); + g_free(*(void**)ptrptr); *(void**)ptrptr =3D NULL; errno =3D save_errno; } @@ -395,7 +378,7 @@ void virDispose(void *ptrptr, if (*(void**)ptrptr && count > 0) memset(*(void **)ptrptr, 0, count * element_size); =20 - free(*(void**)ptrptr); + g_free(*(void**)ptrptr); *(void**)ptrptr =3D NULL; =20 if (countptr) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 3e72e40bc9..517f9aada6 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -24,6 +24,15 @@ =20 #include "internal.h" =20 +/** + * DEPRECATION WARNING + * + * APIs in this file should only be used when modifying existing code. + * Consider converting existing code to use the new APIs when touching + * it. All new code must use the GLib memory allocation APIs and/or + * GLib array data types. See the hacking file for more guidance. + */ + /* Return 1 if an array of N objects, each of size S, cannot exist due to size arithmetic overflow. S must be positive and N must be nonnegative. This is a macro, not an inline function, so that it --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704866; cv=none; d=zoho.com; s=zohoarc; b=YhgJJVb8cX/6vXH5wsNqpq+Kb6gr1SGBnbJk0xhRedQ53BmnEg+KdlS/F6c5uJoxwvlQ8Yw8+HJXZgbWex1ukcn9MG4q0Sa6uERrkQQ4IgduEXua7mmxLNW0H69AQSNWoHqWU2kveR3wkDgi4RF6RbmYexL6avTljz9yf9idhuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704866; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HMjGeJYSWV/eNnEfFxjumNfaXhhST3+Le9Ql0O1mE1E=; b=AweVg+6AW3e7GPjKKk3tDHFhGKtI8eG71TgW89oQ1YH851ApXyPyAyLR54CrWXIL7M0v9i/7qKSfame6M3njMWW+Fss8F983HBpkoz7P2iXCIlYdUNIX8VKYxXPQg360bdUo5KRWoCAOUFa03Oi2eXFRFxC6QosKmiaW3wgy64k= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15707048669021.459792385264791; Thu, 10 Oct 2019 03:54:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30A5FC004E8D; Thu, 10 Oct 2019 10:54:25 +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 0911A60BE1; Thu, 10 Oct 2019 10:54:25 +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 BECC64E58C; Thu, 10 Oct 2019 10:54:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsLJW010360 for ; Thu, 10 Oct 2019 06:54:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 975FF5C22F; Thu, 10 Oct 2019 10:54:21 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5FFB5C1B5; Thu, 10 Oct 2019 10:54:20 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:53:58 +0100 Message-Id: <20191010105413.4091-5-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 04/19] util: use glib string allocation/formatting functions 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 10 Oct 2019 10:54:25 +0000 (UTC) Convert the string duplication APIs to use the g_strdup family of APIs. We previously used the 'strdup-posix' gnulib module because mingw does not set errno to ENOMEM on failure We previously used the 'strndup' gnulib module because this function does not exist on mingw. We previously used the 'vasprintf' gnulib module because of many GNU supported format specifiers not working on non-Linux platforms. glib's own equivalent standardizes on GNU format specifiers too. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- bootstrap.conf | 3 --- docs/hacking.html.in | 8 ++++++++ src/util/virstring.c | 28 ++++++++++++++++++++++------ src/util/virstring.h | 8 ++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 7d73584809..7e264b63ad 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -80,8 +80,6 @@ snprintf socket stat-time strchrnul -strdup-posix -strndup strerror strerror_r-posix strptime @@ -96,7 +94,6 @@ ttyname_r uname unsetenv usleep -vasprintf verify vsnprintf waitpid diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 8072796312..3f1542b6de 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -1020,6 +1020,14 @@ BAD: classic libvirt memory allocation APIs and GLib APIs within a single method. Keep the style consistent, converting existing code to GLib style in a separate, prior commit. + +

VIR_STRDUP, VIR_STRNDUP
+
Prefer the GLib APIs g_strdup and g_strndup.
+ +
virAsprintf, virVasprintf
+
The GLib APIs g_strdup_printf / g_strdup_vprint should be used + instead. Don't use g_vasprintf unless having the string length + returned is unavoidable.
=20

File handling

diff --git a/src/util/virstring.c b/src/util/virstring.c index a4cc7e9c0a..6b2b6ed24e 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -18,6 +18,7 @@ =20 #include =20 +#include #include #include =20 @@ -730,10 +731,21 @@ virVasprintfInternal(char **strp, const char *fmt, va_list list) { + char *str =3D NULL; int ret; =20 - if ((ret =3D vasprintf(strp, fmt, list)) =3D=3D -1) + ret =3D g_vasprintf(&str, fmt, list); + + /* GLib is supposed to abort() on OOM, but a mistake meant + * it did not. Delete this once our min glib is at 2.64.0 + * which includes the fix: + * https://gitlab.gnome.org/GNOME/glib/merge_requests/1145 + */ +#if !GLIB_CHECK_VERSION(2, 64, 0) + if (!str) abort(); +#endif + *strp =3D str; =20 return ret; } @@ -743,11 +755,17 @@ virAsprintfInternal(char **strp, const char *fmt, ...) { va_list ap; + char *str =3D NULL; int ret; =20 va_start(ap, fmt); - ret =3D virVasprintfInternal(strp, fmt, ap); + ret =3D g_vasprintf(&str, fmt, ap); va_end(ap); + + if (!*str) + abort(); + *strp =3D str; + return ret; } =20 @@ -936,8 +954,7 @@ virStrdup(char **dest, *dest =3D NULL; if (!src) return 0; - if (!(*dest =3D strdup(src))) - abort(); + *dest =3D g_strdup(src); =20 return 1; } @@ -965,8 +982,7 @@ virStrndup(char **dest, return 0; if (n < 0) n =3D strlen(src); - if (!(*dest =3D strndup(src, n))) - abort(); + *dest =3D g_strndup(src, n); =20 return 1; } diff --git a/src/util/virstring.h b/src/util/virstring.h index f537f3472e..3ffe51f7b8 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -145,6 +145,8 @@ int virVasprintfInternal(char **strp, const char *fmt, = va_list list) * @dst: variable to hold result (char*, not char**) * @src: string to duplicate * + * DEPRECATED: use g_strdup instead + * * Duplicate @src string and store it into @dst. * * This macro is safe to use on arguments with side effects. @@ -158,6 +160,8 @@ int virVasprintfInternal(char **strp, const char *fmt, = va_list list) * @dst: variable to hold result (char*, not char**) * @src: string to duplicate * + * DEPRECATED: use g_strdup instead + * * Duplicate @src string and store it into @dst. * * This macro is safe to use on arguments with side effects. @@ -172,6 +176,8 @@ int virVasprintfInternal(char **strp, const char *fmt, = va_list list) * @src: string to duplicate * @n: the maximum number of bytes to copy * + * DEPRECATED: use g_strndup instead + * * Duplicate @src string and store it into @dst. If @src is longer than @n, * only @n bytes are copied and terminating null byte '\0' is added. If @n * is a negative number, then the whole @src string is copied. That is, @@ -189,6 +195,8 @@ int virVasprintfInternal(char **strp, const char *fmt, = va_list list) * @src: string to duplicate * @n: the maximum number of bytes to copy * + * DEPRECATED: use g_strndup instead + * * Duplicate @src string and store it into @dst. If @src is longer than @n, * only @n bytes are copied and terminating null byte '\0' is added. If @n * is a negative number, then the whole @src string is copied. That is, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704877; cv=none; d=zoho.com; s=zohoarc; b=iogGMVcXJTpEknB/0K0bDgjk+qWlJBoZJ29qUWrYTvZ5nrHrAp3zmzuILZGgsRBuexnREqRzi9mBOGr6hgrg2lTCJ6bISbzEcwWuYMLbJANkG0c0FFkJscY+WigY9QtKNtimH09A/F/VotiORkjf9HrRm1ZpaVD0iLoY2+aInGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704877; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=S1Zr8VOEER8g/6MZ1c11k5gqX3LTXX31a0Jj1FIGnvo=; b=n2Mn3RLrO0uc9pjV6k7xW4fFfBPL3i4qEj+wKqGLOlmw20lt9LQOEb7isfrujUq21OoDkklJTYgmwpdUf8ebwMoPTOXtDqK2GDBIQPBhcCce1piCkfZxlIG9vR07hLFCZlwnngm3njEiwmWYO566Ak0a/2HQO9D4HY0GF3b7Mkw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 157070487775489.93321496097042; Thu, 10 Oct 2019 03:54:37 -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 3FB933086E23; Thu, 10 Oct 2019 10:54:36 +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 1A03D5C241; Thu, 10 Oct 2019 10:54:36 +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 CC7F64EE69; Thu, 10 Oct 2019 10:54:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsMag010368 for ; Thu, 10 Oct 2019 06:54:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 865095C231; Thu, 10 Oct 2019 10:54:22 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6EFE5C1B5; Thu, 10 Oct 2019 10:54:21 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:53:59 +0100 Message-Id: <20191010105413.4091-6-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 05/19] util: convert virSystemdActivation to use VIR_DEFINE_AUTOPTR_FUNC 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 10 Oct 2019 10:54:36 +0000 (UTC) Using the standard macro will facilitate the conversion to glib's auto cleanup macros. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/virsystemd.c | 10 +++++----- src/util/virsystemd.h | 5 +++-- tests/virsystemdtest.c | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 2efc0dd72c..c2e4c3df51 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -917,7 +917,7 @@ virSystemdActivationNew(virSystemdActivationMap *map, return act; =20 error: - virSystemdActivationFree(&act); + virSystemdActivationFree(act); return NULL; } =20 @@ -1046,12 +1046,12 @@ virSystemdActivationClaimFDs(virSystemdActivationPt= r act, * associated with the activation object */ void -virSystemdActivationFree(virSystemdActivationPtr *act) +virSystemdActivationFree(virSystemdActivationPtr act) { - if (!*act) + if (!act) return; =20 - virHashFree((*act)->fds); + virHashFree(act->fds); =20 - VIR_FREE(*act); + VIR_FREE(act); } diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index 5f1a4413fe..2c0a0d8dc0 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -22,6 +22,7 @@ #pragma once =20 #include "internal.h" +#include "virautoclean.h" =20 typedef struct _virSystemdActivation virSystemdActivation; typedef virSystemdActivation *virSystemdActivationPtr; @@ -81,6 +82,6 @@ void virSystemdActivationClaimFDs(virSystemdActivationPtr= act, int **fds, size_t *nfds); =20 -void virSystemdActivationFree(virSystemdActivationPtr *act); +void virSystemdActivationFree(virSystemdActivationPtr act); =20 -#define virSystemdActivationAutoPtrFree virSystemdActivationFree +VIR_DEFINE_AUTOPTR_FUNC(virSystemdActivation, virSystemdActivationFree); diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 3add1ab56f..d33a7c192f 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -650,7 +650,7 @@ testActivationEmpty(const void *opaque ATTRIBUTE_UNUSED) =20 if (act !=3D NULL) { fprintf(stderr, "Unexpectedly got activation object"); - virSystemdActivationFree(&act); + virSystemdActivationFree(act); return -1; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704871; cv=none; d=zoho.com; s=zohoarc; b=Y287Eksgtdal3Tt3Z6zH3CJ7E8TQd8uAeeO1GKHEtMM02wVVCve1ocTtIb0wCVQXUIhTfA/tnXtiSCqCvKBgWn+fd3jjX1oM8q/xtY6FXXzL0nSXLB3sTp67x9L6fQfz+MDpfGWz7E4rfljdR1EULfIi9OH3B+k+x5TMtQR3Nk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704871; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vpQhFT+PORQeHS6c92ihnB4EkQ7mmF3PIJRBVXnp4zo=; b=LOg6YtlwnvbykCcWc9IW/6imLeV311QwrqTAMBZOVkxul1nTTNQ/4a6HA781ICyC/ApL9G3tZOmrtRgGBhpV70Tecj+pF99zYLd+hE+sY+HUcQxi7X3hTd7raEFAi8F0VXw5CZVU7hBaT9WG+6xTF6aT3vG2H7mYY6XKB4fZe9I= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704871271501.27416725750015; Thu, 10 Oct 2019 03:54:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7290A3090FE3; Thu, 10 Oct 2019 10:54:29 +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 429725D6A5; Thu, 10 Oct 2019 10:54:29 +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 018F3180B761; Thu, 10 Oct 2019 10:54:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsNa3010380 for ; Thu, 10 Oct 2019 06:54:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 79D1D5C231; Thu, 10 Oct 2019 10:54:23 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id C72385C1B5; Thu, 10 Oct 2019 10:54:22 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:00 +0100 Message-Id: <20191010105413.4091-7-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 06/19] util: rewrite auto cleanup macros to use glib's equivalent 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 10 Oct 2019 10:54:30 +0000 (UTC) To facilitate porting over to glib, this rewrites the auto cleanup macros to use glib's equivalent. As a result it is now possible to use g_autoptr/VIR_AUTOPTR, and g_auto/VIR_AUTOCLEAN, g_autofree/VIR_AUTOFREE interchangably, regardless of which macros were used to declare the cleanup types. Within the scope of any single method, code must remain consistent using either GLib or Libvirt macros, never mixing both. New code must preferentially use the GLib macros, and old code will be converted incrementally. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- build-aux/syntax-check.mk | 2 +- docs/hacking.html.in | 18 ++++++++++++++++++ m4/virt-compile-warnings.m4 | 21 ++++++++++++++++++++ src/util/viralloc.h | 5 ++++- src/util/virautoclean.h | 38 +++++++++++++++++++------------------ 5 files changed, 64 insertions(+), 20 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 8345703b3e..f4712c24c3 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1128,7 +1128,7 @@ sc_prohibit_backslash_alignment: # Rule to ensure that variables declared using a cleanup macro are # always initialized. sc_require_attribute_cleanup_initialization: - @prohibit=3D'VIR_AUTO((FREE|PTR|UNREF|CLEAN)\(.+\)|CLOSE|STRINGLIST) *[^= =3D]+;' \ + @prohibit=3D'((g_auto(ptr|free)?)|(VIR_AUTO((FREE|PTR|UNREF|CLEAN)\(.+\)|= CLOSE|STRINGLIST))) *[^=3D]+;' \ in_vc_files=3D'\.[chx]$$' \ halt=3D'variable declared with a cleanup macro must be initialized' \ $(_sc_search_regexp) diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 3f1542b6de..6e62b2d4ff 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -1028,6 +1028,24 @@ BAD:
The GLib APIs g_strdup_printf / g_strdup_vprint should be used instead. Don't use g_vasprintf unless having the string length returned is unavoidable.
+ +
VIR_AUTOPTR, VIR_AUTOCLEAN, VIR_AUTOFREE
+
The GLib macros g_autoptr, g_auto and g_autofree must be used + instead in all new code. In existing code, the GLib macros must + never be mixed with libvirt macros within a method, nor should + they be mixed with VIR_FREE. If introducing GLib macros to an + existing method, any use of libvirt macros must be converted + in an independent commit. +
+ +
VIR_DEFINE_AUTOPTR_FUNC, VIR_DEFINE_AUTOCLEAN_FUNC
+
The Gib macros G_DEFINE_AUTOPTR_CLEANUP_FUNC and + G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC must be used in all + new code. Existing code should be converted to the + new macros where relevant. It is permissible to use + g_autoptr, g_auto on an object whose cleanup function + is declared with the libvirt macros and vice-verca. +
=20

File handling

diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index 1dbe1abe27..7c86fdd3c6 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -104,6 +104,20 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ dontwarn=3D"$dontwarn -Wdouble-promotion" fi =20 + # Clang complains about unused static inline functions + # which are common with G_DEFINE_AUTOPTR_CLEANUP_FUNC + AC_CACHE_CHECK([whether clang gives bogus warnings for -Wunused-functi= on], + [lv_cv_clang_unused_function_broken], [ + save_CFLAGS=3D"$CFLAGS" + CFLAGS=3D"-Wunused-function -Werror" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + static inline void foo(void) {} + ]], [[ + return 0]])], + [lv_cv_clang_unused_function_broken=3Dno], + [lv_cv_clang_unused_function_broken=3Dyes]) + CFLAGS=3D"$save_CFLAGS"]) + # We might fundamentally need some of these disabled forever, but # ideally we'd turn many of them on dontwarn=3D"$dontwarn -Wfloat-equal" @@ -119,6 +133,13 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ # Remove the ones we don't want, blacklisted earlier gl_MANYWARN_COMPLEMENT([wantwarn], [$maybewarn], [$dontwarn]) =20 + # -Wunused-functin is implied by -Wall we must turn it + # off explicitly. + if test "$lv_cv_clang_unused_function_broken" =3D "yes"; + then + wantwarn=3D"$wantwarn -Wno-unused-function" + fi + # GNULIB uses '-W' (aka -Wextra) which includes a bunch of stuff. # Unfortunately, this means you can't simply use '-Wsign-compare' # with gl_MANYWARN_COMPLEMENT diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 517f9aada6..49bf2b86e7 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -494,8 +494,11 @@ void virDisposeString(char **strptr) * VIR_AUTOFREE: * @type: type of the variable to be freed automatically * + * DEPRECATED: use g_autofree for new code. See HACKING + * for further guidance. + * * Macro to automatically free the memory allocated to * the variable declared with it by calling virFree * when the variable goes out of scope. */ -#define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type +#define VIR_AUTOFREE(type) g_autofree type diff --git a/src/util/virautoclean.h b/src/util/virautoclean.h index 6da288e67d..71312a2782 100644 --- a/src/util/virautoclean.h +++ b/src/util/virautoclean.h @@ -20,7 +20,21 @@ =20 #pragma once =20 -#define VIR_AUTOPTR_FUNC_NAME(type) type##AutoPtrFree +/** + * DEPRECATION WARNING + * + * The macros in this file should not be used in newly written code. + * Use the equivalent GLib macros instead. + * + * For existing code, use of the libvirt and GLib macros must NEVER + * be mixed within a single method. + * + * The use of the libvirt VIR_FREE macros should also not be mixed + * with GLib auto-free macros and vice-verca. + * + * Existing code should be converted to the new GLib macros and + * g_free APIs as needed. + */ =20 /** * VIR_DEFINE_AUTOPTR_FUNC: @@ -31,15 +45,8 @@ * resources allocated to a variable of type @type. This newly * defined function works as a necessary wrapper around @func. */ -#define VIR_DEFINE_AUTOPTR_FUNC(type, func) \ - static inline void VIR_AUTOPTR_FUNC_NAME(type)(type **_ptr) \ - { \ - if (*_ptr) \ - (func)(*_ptr); \ - *_ptr =3D NULL; \ - } - -#define VIR_AUTOCLEAN_FUNC_NAME(type) type##AutoClean +#define VIR_DEFINE_AUTOPTR_FUNC(t, f) \ + G_DEFINE_AUTOPTR_CLEANUP_FUNC(t, f) =20 /** * VIR_DEFINE_AUTOCLEAN_FUNC: @@ -51,10 +58,7 @@ * take pointer to @type. */ #define VIR_DEFINE_AUTOCLEAN_FUNC(type, func) \ - static inline void VIR_AUTOCLEAN_FUNC_NAME(type)(type *_ptr) \ - { \ - (func)(_ptr); \ - } + G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(type, func) =20 /** * VIR_AUTOPTR: @@ -68,8 +72,7 @@ * Note that this macro must NOT be used with vectors! The freeing function * will not free any elements beyond the first. */ -#define VIR_AUTOPTR(type) \ - __attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type * +#define VIR_AUTOPTR(type) g_autoptr(type) =20 /** * VIR_AUTOCLEAN: @@ -83,5 +86,4 @@ * Note that this macro must NOT be used with vectors! The cleaning functi= on * will not clean any elements beyond the first. */ -#define VIR_AUTOCLEAN(type) \ - __attribute__((cleanup(VIR_AUTOCLEAN_FUNC_NAME(type)))) type +#define VIR_AUTOCLEAN(type) g_auto(type) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704874; cv=none; d=zoho.com; s=zohoarc; b=d6VRA6thblr+BH1buwaHnv4E4rqlMKliNa5gPQTT4P8T3SswnqdPcy5tdksVp+zTe2y9kaBBKsaTl81U2BL1QKr2+C2k7pcm4e47x+R0sJe+wsMFDEyL+//odkVsZ52TAR+MVuv5/QKuwJc+XztB7VOt9U3+xsC5R+uTZsoYzgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lFxzJpOezyM9ki2dojrOML3XsyfPcVnPIJn/iKQZZc4=; b=Em8lqu7xZ0f7r9uyIELzAZ+148o1bTOnvm/bhz38jkhpHP5o2NWyp0jd33kuX9LEH+GPuL6LrnCpKyJJ5A8OfnxIHQD1iN3dM9qfI8POSx/QBEtCL81KAfnoP38l9NghjK8XXyPGOW09nCO1Szaw7wZUFuGkY9WV8ptqTX81+fg= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 157070487486571.34990721078248; Thu, 10 Oct 2019 03:54:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9CA687630; Thu, 10 Oct 2019 10:54:32 +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 BF8EB6031D; Thu, 10 Oct 2019 10:54:32 +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 80426180BA9E; Thu, 10 Oct 2019 10:54:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsOIZ010392 for ; Thu, 10 Oct 2019 06:54:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E38A5C22F; Thu, 10 Oct 2019 10:54:24 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA4A05C1B5; Thu, 10 Oct 2019 10:54:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:01 +0100 Message-Id: <20191010105413.4091-8-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 07/19] src: add support for g_autoptr with virObject instances 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 10 Oct 2019 10:54:33 +0000 (UTC) Libvirt currently uses the VIR_AUTOUNREF macro for auto cleanup of virObject instances. GLib approaches things differently with GObject, reusing their g_autoptr() concept. This introduces support for g_autoptr() with virObject, to facilitate the conversion to GObject. Only virObject classes which are currently used with VIR_AUTOREF are updated. Any others should be converted to GObject before introducing use of autocleanup. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- docs/hacking.html.in | 5 +++++ src/conf/capabilities.h | 3 +++ src/conf/domain_capabilities.h | 3 +++ src/conf/domain_conf.h | 3 +++ src/conf/snapshot_conf.h | 3 +++ src/conf/storage_capabilities.h | 3 +++ src/datatypes.h | 15 +++++++++++++++ src/libxl/libxl_conf.h | 2 ++ src/qemu/qemu_blockjob.h | 1 + src/qemu/qemu_capabilities.h | 2 ++ src/qemu/qemu_conf.h | 3 +++ src/util/virhostdev.h | 3 +++ src/util/viridentity.h | 2 ++ src/util/virmdev.h | 3 +++ src/util/virobject.h | 4 ++++ src/util/virpci.h | 3 +++ src/util/virresctrl.h | 4 ++++ src/util/virscsi.h | 3 +++ src/util/virscsivhost.h | 3 +++ src/util/virstoragefile.h | 2 ++ src/util/virusb.h | 3 +++ 21 files changed, 73 insertions(+) diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 6e62b2d4ff..a92608cd3c 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -1046,6 +1046,11 @@ BAD: g_autoptr, g_auto on an object whose cleanup function is declared with the libvirt macros and vice-verca. + +
VIR_AUTOUNREF
+
The GLib macros g_autoptr and G_DEFINE_AUTOPTR_CLEANUP_FUNC + should be used to manage autoclean of virObject classes. + This matches usage with GObject classes.
=20

File handling

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index d6a4e79d77..4abd3dcabd 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -195,6 +195,9 @@ struct _virCaps { virCapsStoragePoolPtr *pools; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCaps, virObjectUnref); + + struct _virCapsDomainData { int ostype; int arch; diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h index 4756af38e9..f5571b2188 100644 --- a/src/conf/domain_capabilities.h +++ b/src/conf/domain_capabilities.h @@ -185,6 +185,9 @@ struct _virDomainCaps { /* add new domain features here */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCaps, virObjectUnref); + + virDomainCapsPtr virDomainCapsNew(const char *path, const char *machine, virArch arch, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b7ae57aa9d..f7404b814f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2594,6 +2594,9 @@ struct _virDomainObj { * restore will be required later= */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainObj, virObjectUnref); + + typedef bool (*virDomainObjListACLFilter)(virConnectPtr conn, virDomainDefPtr def); =20 diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 17d614a7e1..7e2ffa9d60 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -87,6 +87,9 @@ struct _virDomainSnapshotDef { virObjectPtr cookie; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSnapshotDef, virObjectUnref); + + typedef enum { VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE =3D 1 << 0, VIR_DOMAIN_SNAPSHOT_PARSE_DISKS =3D 1 << 1, diff --git a/src/conf/storage_capabilities.h b/src/conf/storage_capabilitie= s.h index 948e5bed5b..788ea227ea 100644 --- a/src/conf/storage_capabilities.h +++ b/src/conf/storage_capabilities.h @@ -30,6 +30,9 @@ struct _virStoragePoolCaps { virCapsPtr driverCaps; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolCaps, virObjectUnref); + + virStoragePoolCapsPtr virStoragePoolCapsNew(virCapsPtr driverCaps); =20 diff --git a/src/datatypes.h b/src/datatypes.h index 87e77fff79..16ab5b7282 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -548,6 +548,9 @@ struct _virConnect { void *userData; /* the user data */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virConnect, virObjectUnref); + + /** * _virAdmConnect: * @@ -616,6 +619,9 @@ struct _virNetwork { unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier = */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetwork, virObjectUnref); + + /** * _virNetworkPort: * @@ -627,6 +633,9 @@ struct _virNetworkPort { unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier = */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkPort, virObjectUnref); + + /** * _virInterface: * @@ -658,6 +667,9 @@ struct _virStoragePool { virFreeCallback privateDataFreeFunc; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virObjectUnref); + + /** * _virStorageVol: * @@ -678,6 +690,9 @@ struct _virStorageVol { virFreeCallback privateDataFreeFunc; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVol, virObjectUnref); + + /** * _virNodeDevice: * diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 27badfb292..80be791b7c 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -102,6 +102,8 @@ struct _libxlDriverConfig { size_t nfirmwares; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(libxlDriverConfig, virObjectUnref); + =20 struct _libxlDriverPrivate { virMutex lock; diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index 41a5cd91f8..417f253e31 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -134,6 +134,7 @@ struct _qemuBlockJobData { bool invalidData; /* the job data (except name) is not valid */ bool reconnected; /* internal field for tracking whether job is live a= fter reconnect to qemu */ }; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuBlockJobData, virObjectUnref); =20 int qemuBlockJobRegister(qemuBlockJobDataPtr job, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index ea45edb9a4..10f0ce2654 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -535,6 +535,8 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ typedef struct _virQEMUCaps virQEMUCaps; typedef virQEMUCaps *virQEMUCapsPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUCaps, virObjectUnref); + virQEMUCapsPtr virQEMUCapsNew(void); =20 void virQEMUCapsSet(virQEMUCapsPtr qemuCaps, diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8473d6d4ca..7247199d3e 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -218,6 +218,9 @@ struct _virQEMUDriverConfig { char **capabilityfilters; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref); + + /* Main driver state */ struct _virQEMUDriver { virMutex lock; diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 88501e2743..b19a9c3f45 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -55,6 +55,9 @@ struct _virHostdevManager { virMediatedDeviceListPtr activeMediatedHostdevs; }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virHostdevManager, virObjectUnref); + + virHostdevManagerPtr virHostdevManagerGetDefault(void); int virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr, diff --git a/src/util/viridentity.h b/src/util/viridentity.h index 861ecca736..7513dd4e35 100644 --- a/src/util/viridentity.h +++ b/src/util/viridentity.h @@ -26,6 +26,8 @@ typedef struct _virIdentity virIdentity; typedef virIdentity *virIdentityPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virIdentity, virObjectUnref); + virIdentityPtr virIdentityGetCurrent(void); int virIdentitySetCurrent(virIdentityPtr ident); =20 diff --git a/src/util/virmdev.h b/src/util/virmdev.h index fb125e7056..7f442b571f 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -40,6 +40,9 @@ typedef virMediatedDevice *virMediatedDevicePtr; typedef struct _virMediatedDeviceList virMediatedDeviceList; typedef virMediatedDeviceList *virMediatedDeviceListPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceList, virObjectUnref); + + typedef struct _virMediatedDeviceType virMediatedDeviceType; typedef virMediatedDeviceType *virMediatedDeviceTypePtr; struct _virMediatedDeviceType { diff --git a/src/util/virobject.h b/src/util/virobject.h index fe5dbe7326..773a009f5e 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -116,12 +116,16 @@ virObjectAutoUnref(void *objptr); * VIR_AUTOUNREF: * @type: type of an virObject subclass to be unref'd automatically * + * DEPRECATED: Use g_autoptr(type) instead + * * Declares a variable of @type which will be automatically unref'd when * control goes out of the scope. */ #define VIR_AUTOUNREF(type) \ __attribute__((cleanup(virObjectAutoUnref))) type =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virObject, virObjectUnref); + void * virObjectRef(void *obj); =20 diff --git a/src/util/virpci.h b/src/util/virpci.h index dc20f91710..f3226f1f1b 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -34,6 +34,9 @@ typedef virPCIDeviceAddress *virPCIDeviceAddressPtr; typedef struct _virPCIDeviceList virPCIDeviceList; typedef virPCIDeviceList *virPCIDeviceListPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIDeviceList, virObjectUnref); + + #define VIR_DOMAIN_DEVICE_ZPCI_MAX_UID UINT16_MAX #define VIR_DOMAIN_DEVICE_ZPCI_MAX_FID UINT32_MAX =20 diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 216a7302cd..3dd7c96348 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -20,6 +20,7 @@ =20 #include "internal.h" =20 +#include "virobject.h" #include "virbitmap.h" #include "virutil.h" #include "virenum.h" @@ -114,6 +115,9 @@ virResctrlInfoGetMemoryBandwidth(virResctrlInfoPtr resc= trl, typedef struct _virResctrlAlloc virResctrlAlloc; typedef virResctrlAlloc *virResctrlAllocPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virResctrlAlloc, virObjectUnref); + + typedef int virResctrlAllocForeachCacheCallback(unsigned int level, virCacheType type, unsigned int cache, diff --git a/src/util/virscsi.h b/src/util/virscsi.h index 6cc68835b7..8c2c84e07b 100644 --- a/src/util/virscsi.h +++ b/src/util/virscsi.h @@ -30,6 +30,9 @@ typedef virSCSIDevice *virSCSIDevicePtr; typedef struct _virSCSIDeviceList virSCSIDeviceList; typedef virSCSIDeviceList *virSCSIDeviceListPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSCSIDeviceList, virObjectUnref); + + char *virSCSIDeviceGetSgName(const char *sysfs_prefix, const char *adapter, unsigned int bus, diff --git a/src/util/virscsivhost.h b/src/util/virscsivhost.h index a1a0ea5618..334eb81af6 100644 --- a/src/util/virscsivhost.h +++ b/src/util/virscsivhost.h @@ -30,6 +30,9 @@ typedef virSCSIVHostDevice *virSCSIVHostDevicePtr; typedef struct _virSCSIVHostDeviceList virSCSIVHostDeviceList; typedef virSCSIVHostDeviceList *virSCSIVHostDeviceListPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSCSIVHostDeviceList, virObjectUnref); + + typedef int (*virSCSIVHostDeviceFileActor)(virSCSIVHostDevicePtr dev, const char *name, void *opaque); =20 diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 81b83a53ef..5b01f9303b 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -339,6 +339,8 @@ struct _virStorageSource { bool hostcdrom; /* backing device is a cdrom */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref); + =20 #ifndef DEV_BSIZE # define DEV_BSIZE 512 diff --git a/src/util/virusb.h b/src/util/virusb.h index c95514ed3d..33ddb6c84e 100644 --- a/src/util/virusb.h +++ b/src/util/virusb.h @@ -31,6 +31,9 @@ typedef virUSBDevice *virUSBDevicePtr; typedef struct _virUSBDeviceList virUSBDeviceList; typedef virUSBDeviceList *virUSBDeviceListPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virUSBDeviceList, virObjectUnref); + + virUSBDevicePtr virUSBDeviceNew(unsigned int bus, unsigned int devno, const char *vroot); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704881; cv=none; d=zoho.com; s=zohoarc; b=dcaN4KFCMtwekooNvNuZM/6tO6wjSZhRtsPWGEyxAcs9iG77ajT525mBjlRywWY4OqkEMDtrATJar5Iv6kavnLHNOqiH7MoChQkJsC56e5XrRhgSWE2ssFTcKGi0oihKRYZXKYttyairr0xMka2COXm7uTWPkYk31YFYs1f+0pM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704881; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2vwzXuHJo3P25OAGcGpisZpPd24AXQOK5zdiTA27Pvo=; b=PSvB/lqiLBpioAZOHLBMJF7Tgxs+vdpmFcaxnhQtKCUAAMk0RnNRKV0hbjl9JfvNImmK695zttdToiuIeLpaaheZGTI5SzV+5LUpbDNszLSahfzBX8YuGvRCbeicwtLO1wPnx0Y3XxWwP5BotvoF5mP0aw/3niaJ+uZbk0NAvbI= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704881280694.3820492670973; Thu, 10 Oct 2019 03:54:41 -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 BA04FA44AE6; Thu, 10 Oct 2019 10:54:39 +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 8D0525C1B5; Thu, 10 Oct 2019 10:54:39 +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 3A0B4180BAA2; Thu, 10 Oct 2019 10:54:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsPcY010407 for ; Thu, 10 Oct 2019 06:54:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E23F5C22F; Thu, 10 Oct 2019 10:54:25 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADFA45C1B5; Thu, 10 Oct 2019 10:54:24 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:02 +0100 Message-Id: <20191010105413.4091-9-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 08/19] conf: convert virSecretObj APIs to use autofree 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Thu, 10 Oct 2019 10:54:40 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/virsecretobj.c | 46 +++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 7800912bff..aeae82332b 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -678,43 +678,33 @@ virSecretObjDeleteData(virSecretObjPtr obj) int virSecretObjSaveConfig(virSecretObjPtr obj) { - char *xml =3D NULL; - int ret =3D -1; + g_autofree char *xml =3D NULL; =20 if (!(xml =3D virSecretDefFormat(obj->def))) - goto cleanup; + return -1; =20 if (virFileRewriteStr(obj->configFile, S_IRUSR | S_IWUSR, xml) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(xml); - return ret; + return 0; } =20 =20 int virSecretObjSaveData(virSecretObjPtr obj) { - char *base64 =3D NULL; - int ret =3D -1; + g_autofree char *base64 =3D NULL; =20 if (!obj->value) return 0; =20 if (!(base64 =3D virStringEncodeBase64(obj->value, obj->value_size))) - goto cleanup; + return -1; =20 if (virFileRewriteStr(obj->base64File, S_IRUSR | S_IWUSR, base64) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(base64); - return ret; + return 0; } =20 =20 @@ -762,7 +752,8 @@ virSecretObjSetValue(virSecretObjPtr obj, size_t value_size) { virSecretDefPtr def =3D obj->def; - unsigned char *old_value, *new_value; + g_autofree unsigned char *old_value =3D NULL; + g_autofree unsigned char *new_value =3D NULL; size_t old_value_size; =20 if (VIR_ALLOC_N(new_value, value_size) < 0) @@ -772,26 +763,24 @@ virSecretObjSetValue(virSecretObjPtr obj, old_value_size =3D obj->value_size; =20 memcpy(new_value, value, value_size); - obj->value =3D new_value; + obj->value =3D g_steal_pointer(&new_value); obj->value_size =3D value_size; =20 if (!def->isephemeral && virSecretObjSaveData(obj) < 0) goto error; =20 /* Saved successfully - drop old value */ - if (old_value) { + if (old_value) memset(old_value, 0, old_value_size); - VIR_FREE(old_value); - } =20 return 0; =20 error: /* Error - restore previous state and free new value */ - obj->value =3D old_value; + new_value =3D g_steal_pointer(&obj->value); + obj->value =3D g_steal_pointer(&old_value); obj->value_size =3D old_value_size; memset(new_value, 0, value_size); - VIR_FREE(new_value); return -1; } =20 @@ -835,7 +824,8 @@ virSecretLoadValue(virSecretObjPtr obj) { int ret =3D -1, fd =3D -1; struct stat st; - char *contents =3D NULL, *value =3D NULL; + g_autofree char *contents =3D NULL; + char *value =3D NULL; size_t value_size; =20 if ((fd =3D open(obj->base64File, O_RDONLY)) =3D=3D -1) { @@ -892,10 +882,8 @@ virSecretLoadValue(virSecretObjPtr obj) memset(value, 0, value_size); VIR_FREE(value); } - if (contents !=3D NULL) { + if (contents !=3D NULL) memset(contents, 0, st.st_size); - VIR_FREE(contents); - } VIR_FORCE_CLOSE(fd); return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704885; cv=none; d=zoho.com; s=zohoarc; b=IW/dZ9jvCgd3tR5dUaSxVmlu01oSMRZyO65qdmPqG/Hoi3USDJ3Gp2ESQ2AKVJD/dFdEYdc8Y6JCCfWDAWLUEEldIviLghTcqLrfIrFvjUhLKn0dS26v4KIpDyvvvuMbeNxE2+F+In4PtWCbxDORtmufpULLknQOyTYbyQGXpc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704885; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ffMvmf2gzB1sIG1PWTf2YjVWAZ1P394HBpaHsVzicOU=; b=dJ2ghQ6GiZIRtgEc1e53rnn8mMsi3TEGprAXTNGVAAFYxAAxm4/PTV0RDHouOMjKG9qvvDDUbFk2DQ94Dm0hrE7BFLAtqVs8S6j/Fh5tQTsxYq8P3eRoMroKTUeilmOlM/kj3Zreb+QqUXiM6WEFIJA3EKkXMMJTvH9uppzXqgw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704885256830.1564691546312; Thu, 10 Oct 2019 03:54:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0ACE18C4289; Thu, 10 Oct 2019 10:54:43 +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 834915D713; Thu, 10 Oct 2019 10:54:43 +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 479AD4EE6F; Thu, 10 Oct 2019 10:54:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsQxl010415 for ; Thu, 10 Oct 2019 06:54:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4DC5E5C22F; Thu, 10 Oct 2019 10:54:26 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E8035C1B5; Thu, 10 Oct 2019 10:54:25 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:03 +0100 Message-Id: <20191010105413.4091-10-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 09/19] util: use glib base64 encoding/decoding APIs 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 10 Oct 2019 10:54:44 +0000 (UTC) Replace use of the gnulib base64 module with glib's own base64 API family. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- bootstrap.conf | 1 - configure.ac | 5 ----- src/conf/virsecretobj.c | 26 ++++---------------------- src/libvirt_private.syms | 1 - src/libxl/libxl_conf.c | 3 +-- src/qemu/qemu_agent.c | 6 ++---- src/qemu/qemu_command.c | 5 ++--- src/qemu/qemu_domain.c | 8 +++----- src/secret/secret_driver.c | 1 - src/storage/storage_backend_rbd.c | 4 +--- src/util/virstring.c | 21 --------------------- src/util/virstring.h | 2 -- tools/virsh-secret.c | 17 ++++------------- 13 files changed, 17 insertions(+), 83 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 7e264b63ad..bb40e978aa 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -20,7 +20,6 @@ gnulib_modules=3D' accept areadlink -base64 bind byteswap c-ctype diff --git a/configure.ac b/configure.ac index 9b4e6fdd6d..acac1bed41 100644 --- a/configure.ac +++ b/configure.ac @@ -911,11 +911,6 @@ test "x$lv_cv_static_analysis" =3D xyes && t=3D1 AC_DEFINE_UNQUOTED([STATIC_ANALYSIS], [$t], [Define to 1 when performing static analysis.]) =20 -# Some GNULIB base64 symbols clash with a kerberos library -AC_DEFINE_UNQUOTED([isbase64],[libvirt_gl_isbase64],[Hack to avoid symbol = clash]) -AC_DEFINE_UNQUOTED([base64_encode],[libvirt_gl_base64_encode],[Hack to avo= id symbol clash]) -AC_DEFINE_UNQUOTED([base64_encode_alloc],[libvirt_gl_base64_encode_alloc],= [Hack to avoid symbol clash]) - GNUmakefile=3DGNUmakefile m4_if(m4_version_compare([2.61a.100], m4_defn([m4_PACKAGE_VERSION])), [1], [], diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index aeae82332b..5bd84d82ed 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -31,7 +31,6 @@ #include "virhash.h" #include "virlog.h" #include "virstring.h" -#include "base64.h" =20 #define VIR_FROM_THIS VIR_FROM_SECRET =20 @@ -698,8 +697,7 @@ virSecretObjSaveData(virSecretObjPtr obj) if (!obj->value) return 0; =20 - if (!(base64 =3D virStringEncodeBase64(obj->value, obj->value_size))) - return -1; + base64 =3D g_base64_encode(obj->value, obj->value_size); =20 if (virFileRewriteStr(obj->base64File, S_IRUSR | S_IWUSR, base64) < 0) return -1; @@ -825,8 +823,6 @@ virSecretLoadValue(virSecretObjPtr obj) int ret =3D -1, fd =3D -1; struct stat st; g_autofree char *contents =3D NULL; - char *value =3D NULL; - size_t value_size; =20 if ((fd =3D open(obj->base64File, O_RDONLY)) =3D=3D -1) { if (errno =3D=3D ENOENT) { @@ -851,7 +847,7 @@ virSecretLoadValue(virSecretObjPtr obj) goto cleanup; } =20 - if (VIR_ALLOC_N(contents, st.st_size) < 0) + if (VIR_ALLOC_N(contents, st.st_size + 1) < 0) goto cleanup; =20 if (saferead(fd, contents, st.st_size) !=3D st.st_size) { @@ -859,29 +855,15 @@ virSecretLoadValue(virSecretObjPtr obj) obj->base64File); goto cleanup; } + contents[st.st_size] =3D '\0'; =20 VIR_FORCE_CLOSE(fd); =20 - if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid base64 in '%s'"), - obj->base64File); - goto cleanup; - } - if (value =3D=3D NULL) - goto cleanup; - - obj->value =3D (unsigned char *)value; - value =3D NULL; - obj->value_size =3D value_size; + obj->value =3D g_base64_decode(contents, &obj->value_size); =20 ret =3D 0; =20 cleanup: - if (value !=3D NULL) { - memset(value, 0, value_size); - VIR_FREE(value); - } if (contents !=3D NULL) memset(contents, 0, st.st_size); VIR_FORCE_CLOSE(fd); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5949cba08d..e88518a1ce 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3069,7 +3069,6 @@ virSkipSpacesBackwards; virStrcpy; virStrdup; virStringBufferIsPrintable; -virStringEncodeBase64; virStringFilterChars; virStringHasCaseSuffix; virStringHasChars; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index c76704a11d..de56567cf0 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -999,8 +999,7 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char *= *srcstr) goto cleanup; =20 /* RBD expects an encoded secret */ - if (!(base64secret =3D virStringEncodeBase64(secret, secretlen))) - goto cleanup; + base64secret =3D g_base64_encode(secret, secretlen); } =20 if (!(*srcstr =3D libxlMakeNetworkDiskSrcStr(src, username, base64secr= et))) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 34e1a85d64..0ef8b563f5 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -39,7 +39,6 @@ #include "virtime.h" #include "virobject.h" #include "virstring.h" -#include "base64.h" #include "virenum.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU @@ -2518,9 +2517,8 @@ qemuAgentSetUserPassword(qemuAgentPtr mon, virJSONValuePtr reply =3D NULL; char *password64 =3D NULL; =20 - if (!(password64 =3D virStringEncodeBase64((unsigned char *)password, - strlen(password)))) - goto cleanup; + password64 =3D g_base64_encode((unsigned char *)password, + strlen(password)); =20 if (!(cmd =3D qemuAgentMakeCommand("guest-set-user-password", "b:crypted", crypted, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 50cc3bdf7c..0f1625d401 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -837,9 +837,8 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf, =20 switch ((qemuDomainSecretInfoType) secinfo->type) { case VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN: - if (!(base64secret =3D virStringEncodeBase64(secinfo->s.plain.secr= et, - secinfo->s.plain.secret= len))) - return -1; + base64secret =3D g_base64_encode(secinfo->s.plain.secret, + secinfo->s.plain.secretlen); virBufferEscape(buf, '\\', ":", ":id=3D%s", secinfo->s.plain.usern= ame); virBufferEscape(buf, '\\', ":", ":key=3D%s:auth_supported=3Dcephx\\;none", diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index dc7568fe18..35067c851f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1470,8 +1470,7 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv, goto cleanup; =20 /* Encode the IV and save that since qemu will need it */ - if (!(secinfo->s.aes.iv =3D virStringEncodeBase64(raw_iv, ivlen))) - goto cleanup; + secinfo->s.aes.iv =3D g_base64_encode(raw_iv, ivlen); =20 /* Grab the unencoded secret */ if (virSecretGetSecretString(conn, seclookupdef, usageType, @@ -1488,9 +1487,8 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv, memset(secret, 0, secretlen); =20 /* Now encode the ciphertext and store to be passed to qemu */ - if (!(secinfo->s.aes.ciphertext =3D virStringEncodeBase64(ciphertext, - ciphertextlen)= )) - goto cleanup; + secinfo->s.aes.ciphertext =3D g_base64_encode(ciphertext, + ciphertextlen); =20 ret =3D 0; =20 diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index ed3bd3c751..13f75ee4fa 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -25,7 +25,6 @@ #include =20 #include "internal.h" -#include "base64.h" #include "datatypes.h" #include "driver.h" #include "virlog.h" diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index c4781debd8..b10ca1503d 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -28,7 +28,6 @@ #include "storage_conf.h" #include "viralloc.h" #include "virlog.h" -#include "base64.h" #include "viruuid.h" #include "virstring.h" #include "virrandom.h" @@ -218,8 +217,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDS= tatePtr ptr, &secret_value, &secret_value_size) < = 0) goto cleanup; =20 - if (!(rados_key =3D virStringEncodeBase64(secret_value, secret_val= ue_size))) - goto cleanup; + rados_key =3D g_base64_encode(secret_value, secret_value_size); =20 if (virStorageBackendRBDRADOSConfSet(ptr->cluster, "key", rados_key) < 0) diff --git a/src/util/virstring.c b/src/util/virstring.c index 6b2b6ed24e..0abdcd8b04 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -22,7 +22,6 @@ #include #include =20 -#include "base64.h" #include "c-ctype.h" #include "virstring.h" #include "virthread.h" @@ -1438,26 +1437,6 @@ virStringBufferIsPrintable(const uint8_t *buf, } =20 =20 -/** - * virStringEncodeBase64: - * @buf: buffer of bytes to encode - * @buflen: number of bytes to encode - * - * Encodes @buf to base 64 and returns the resulting string. The caller is - * responsible for freeing the result. - */ -char * -virStringEncodeBase64(const uint8_t *buf, size_t buflen) -{ - char *ret; - - base64_encode_alloc((const char *) buf, buflen, &ret); - if (!ret) - abort(); - - return ret; -} - /** * virStringTrimOptionalNewline: * @str: the string to modify in-place diff --git a/src/util/virstring.h b/src/util/virstring.h index 3ffe51f7b8..af6e234d83 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -291,8 +291,6 @@ void virStringFilterChars(char *str, const char *valid); bool virStringIsPrintable(const char *str); bool virStringBufferIsPrintable(const uint8_t *buf, size_t buflen); =20 -char *virStringEncodeBase64(const uint8_t *buf, size_t buflen); - void virStringTrimOptionalNewline(char *str); =20 int virStringParsePort(const char *str, diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index b34ae12bbe..48058bea05 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -22,7 +22,6 @@ #include "virsh-secret.h" =20 #include "internal.h" -#include "base64.h" #include "virbuffer.h" #include "viralloc.h" #include "virfile.h" @@ -192,7 +191,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) virSecretPtr secret; size_t value_size; const char *base64 =3D NULL; - char *value; + unsigned char *value; int res; bool ret =3D false; =20 @@ -202,16 +201,9 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0) goto cleanup; =20 - if (!base64_decode_alloc(base64, strlen(base64), &value, &value_size))= { - vshError(ctl, "%s", _("Invalid base64 data")); - goto cleanup; - } - if (value =3D=3D NULL) { - vshError(ctl, "%s", _("Failed to allocate memory")); - goto cleanup; - } + value =3D g_base64_decode(base64, &value_size); =20 - res =3D virSecretSetValue(secret, (unsigned char *)value, value_size, = 0); + res =3D virSecretSetValue(secret, value, value_size, 0); memset(value, 0, value_size); VIR_FREE(value); =20 @@ -267,8 +259,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) if (value =3D=3D NULL) goto cleanup; =20 - if (!(base64 =3D virStringEncodeBase64(value, value_size))) - goto cleanup; + base64 =3D g_base64_encode(value, value_size); =20 vshPrint(ctl, "%s", base64); ret =3D true; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704888; cv=none; d=zoho.com; s=zohoarc; b=oQ6dWPUpDXLd2fLWFLqhd/9NSKCTTQaDWgkXdFHuo0YcBSvVZ/icJmAZtWiwhImz/gOGS2xOTYT6yAXiYiAOwqTQv7Aex7yPJVEHGL3yua7CD2haOoeUgeMArM6sTUCZ5PNwRf0c/uEn6t1YJo8aWKxC+dfH4HGETqBSpblNguI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704888; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kRhKNjUH8Qszaw6tWgjJvO8/bKa6g068l06EKvD6BcI=; b=mNrnMSRZjJfPnqVEqh7xFXmA4J3DqVxWlErw0nZFmGkuSpgvfRtfRI/2zYX5Oe0//x6Q/Wj/xqeknOqa8sEOA3HKFPXLCA5VLFsTLxi9kXK2ru40ku44nALoJXmo8cwM4QEEwIM6tCwEzHTGaOLNAK0lpKmMwm1vCiy00KzYyR0= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704888560612.3660685827534; Thu, 10 Oct 2019 03:54:48 -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 F341218CB914; Thu, 10 Oct 2019 10:54:46 +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 CF6E161B61; Thu, 10 Oct 2019 10:54:46 +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 97CBB180BA98; Thu, 10 Oct 2019 10:54:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsTJT010436 for ; Thu, 10 Oct 2019 06:54:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA3335C22C; Thu, 10 Oct 2019 10:54:29 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8ECDD5C22F; Thu, 10 Oct 2019 10:54:26 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:04 +0100 Message-Id: <20191010105413.4091-11-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 10/19] util: convert virIdentity implementation and test suite to g_autoptr 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Thu, 10 Oct 2019 10:54:47 +0000 (UTC) To simplify the later conversion from virObject to GObject, introduce the use of g_autoptr to the virIdentity implementnation and test suite. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/viridentity.c | 36 ++++++++++++++------------------- tests/viridentitytest.c | 44 +++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 22e2644c19..6636077161 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -105,7 +105,7 @@ virIdentityPtr virIdentityGetCurrent(void) */ int virIdentitySetCurrent(virIdentityPtr ident) { - virIdentityPtr old; + g_autoptr(virIdentity) old =3D NULL; =20 if (virIdentityInitialize() < 0) return -1; @@ -120,8 +120,6 @@ int virIdentitySetCurrent(virIdentityPtr ident) return -1; } =20 - virObjectUnref(old); - return 0; } =20 @@ -136,60 +134,56 @@ int virIdentitySetCurrent(virIdentityPtr ident) */ virIdentityPtr virIdentityGetSystem(void) { - VIR_AUTOFREE(char *) username =3D NULL; - VIR_AUTOFREE(char *) groupname =3D NULL; + g_autofree char *username =3D NULL; + g_autofree char *groupname =3D NULL; unsigned long long startTime; - virIdentityPtr ret =3D NULL; + g_autoptr(virIdentity) ret =3D NULL; #if WITH_SELINUX security_context_t con; #endif =20 if (!(ret =3D virIdentityNew())) - goto error; + return NULL; =20 if (virIdentitySetProcessID(ret, getpid()) < 0) - goto error; + return NULL; =20 if (virProcessGetStartTime(getpid(), &startTime) < 0) - goto error; + return NULL; if (startTime !=3D 0 && virIdentitySetProcessTime(ret, startTime) < 0) - goto error; + return NULL; =20 if (!(username =3D virGetUserName(geteuid()))) return ret; if (virIdentitySetUserName(ret, username) < 0) - goto error; + return NULL; if (virIdentitySetUNIXUserID(ret, getuid()) < 0) - goto error; + return NULL; =20 if (!(groupname =3D virGetGroupName(getegid()))) return ret; if (virIdentitySetGroupName(ret, groupname) < 0) - goto error; + return NULL; if (virIdentitySetUNIXGroupID(ret, getgid()) < 0) - goto error; + return NULL; =20 #if WITH_SELINUX if (is_selinux_enabled() > 0) { if (getcon(&con) < 0) { virReportSystemError(errno, "%s", _("Unable to lookup SELinux process conte= xt")); - return ret; + return NULL; } if (virIdentitySetSELinuxContext(ret, con) < 0) { freecon(con); - goto error; + return NULL; } freecon(con); } #endif =20 - return ret; - - error: - virObjectUnref(ret); - return NULL; + return g_steal_pointer(&ret); } =20 =20 diff --git a/tests/viridentitytest.c b/tests/viridentitytest.c index 1eadd6173a..db041a98a8 100644 --- a/tests/viridentitytest.c +++ b/tests/viridentitytest.c @@ -38,58 +38,53 @@ VIR_LOG_INIT("tests.identitytest"); =20 static int testIdentityAttrs(const void *data ATTRIBUTE_UNUSED) { - int ret =3D -1; - virIdentityPtr ident; + g_autoptr(virIdentity) ident =3D NULL; const char *val; int rc; =20 if (!(ident =3D virIdentityNew())) - goto cleanup; + return -1; =20 if (virIdentitySetUserName(ident, "fred") < 0) - goto cleanup; + return -1; =20 if ((rc =3D virIdentityGetUserName(ident, &val)) < 0) - goto cleanup; + return -1; =20 if (STRNEQ_NULLABLE(val, "fred") || rc !=3D 1) { VIR_DEBUG("Expected 'fred' got '%s'", NULLSTR(val)); - goto cleanup; + return -1; } =20 if ((rc =3D virIdentityGetGroupName(ident, &val)) < 0) - goto cleanup; + return -1; =20 if (val !=3D NULL || rc !=3D 0) { VIR_DEBUG("Unexpected groupname attribute"); - goto cleanup; + return -1; } =20 if (virIdentitySetUserName(ident, "joe") >=3D 0) { VIR_DEBUG("Unexpectedly overwrote attribute"); - goto cleanup; + return -1; } =20 if ((rc =3D virIdentityGetUserName(ident, &val)) < 0) - goto cleanup; + return -1; =20 if (STRNEQ_NULLABLE(val, "fred") || rc !=3D 1) { VIR_DEBUG("Expected 'fred' got '%s'", NULLSTR(val)); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virObjectUnref(ident); - return ret; + return 0; } =20 =20 static int testIdentityGetSystem(const void *data) { const char *context =3D data; - int ret =3D -1; - virIdentityPtr ident =3D NULL; + g_autoptr(virIdentity) ident =3D NULL; const char *val; int rc; =20 @@ -97,35 +92,32 @@ static int testIdentityGetSystem(const void *data) if (context) { VIR_DEBUG("libvirt not compiled with SELinux, skipping this test"); ret =3D EXIT_AM_SKIP; - goto cleanup; + return -1; } #endif =20 if (!(ident =3D virIdentityGetSystem())) { VIR_DEBUG("Unable to get system identity"); - goto cleanup; + return -1; } =20 if ((rc =3D virIdentityGetSELinuxContext(ident, &val)) < 0) - goto cleanup; + return -1; =20 if (context =3D=3D NULL) { if (val !=3D NULL || rc !=3D 0) { VIR_DEBUG("Unexpected SELinux context %s", NULLSTR(val)); - goto cleanup; + return -1; } } else { if (STRNEQ_NULLABLE(val, context) || rc !=3D 1) { VIR_DEBUG("Want SELinux context '%s' got '%s'", context, val); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - virObjectUnref(ident); - return ret; + return 0; } =20 static int testSetFakeSELinuxContext(const void *data ATTRIBUTE_UNUSED) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704892; cv=none; d=zoho.com; s=zohoarc; b=JJ2TPhUzu4FZcGQSO7GuvMXyzZey/oo0uIu0xRl4/yDcn6KSWwv+AsXW0+VUDMOB6A7x+jz8woIqE5Xf5WCnMASO/15W2vELgzbtTQqMpuuXGhxYEUxvI/VYu7qQCmktR/Gm4f8mbQdWOFjVj31V9DTzOg6aCjFgc7rEZq4fMR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704892; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FnHGLZKFTNOF65pZSV6vH2DX28jwzQ5XLbqx4xX5h9U=; b=UyPSveP2tZSXjWAh32JFHnfACXc8DZjpbcU0iu0C2LCdap2LPIPFnP8znelCu/aJDecOY7ndl8xJ3xspJgCoILhl/Yjv/lSDBNG7z+hxIOvCfOVAQ/EU0S4B9PGGK35+NIsyQnCB+hyu2NY7w64SC9b3Aka1ScKNC/3IgXXZa74= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704892200703.7967314860102; Thu, 10 Oct 2019 03:54:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9406318C428C; Thu, 10 Oct 2019 10:54:50 +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 6AE32167A3; Thu, 10 Oct 2019 10:54:50 +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 2D63F180BAA5; Thu, 10 Oct 2019 10:54:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsUQR010441 for ; Thu, 10 Oct 2019 06:54:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9DB635C231; Thu, 10 Oct 2019 10:54:30 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA2FC5C1B5; Thu, 10 Oct 2019 10:54:29 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:05 +0100 Message-Id: <20191010105413.4091-12-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 11/19] access: convert polkit driver to auto free memory 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 10 Oct 2019 10:54:51 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/access/viraccessdriverpolkit.c | 38 +++++++++++------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/access/viraccessdriverpolkit.c b/src/access/viraccessdrive= rpolkit.c index e61ac6fa19..fbe7789ccd 100644 --- a/src/access/viraccessdriverpolkit.c +++ b/src/access/viraccessdriverpolkit.c @@ -78,8 +78,7 @@ virAccessDriverPolkitGetCaller(const char *actionid, unsigned long long *startTime, uid_t *uid) { - virIdentityPtr identity =3D virIdentityGetCurrent(); - int ret =3D -1; + g_autoptr(virIdentity) identity =3D virIdentityGetCurrent(); int rc; =20 if (!identity) { @@ -90,37 +89,33 @@ virAccessDriverPolkitGetCaller(const char *actionid, } =20 if ((rc =3D virIdentityGetProcessID(identity, pid)) < 0) - goto cleanup; + return -1; =20 if (rc =3D=3D 0) { virAccessError(VIR_ERR_INTERNAL_ERROR, "%s", _("No process ID available")); - goto cleanup; + return -1; } =20 if ((rc =3D virIdentityGetProcessTime(identity, startTime)) < 0) - goto cleanup; + return -1; =20 if (rc =3D=3D 0) { virAccessError(VIR_ERR_INTERNAL_ERROR, "%s", _("No process start time available")); - goto cleanup; + return -1; } =20 if ((rc =3D virIdentityGetUNIXUserID(identity, uid)) < 0) - goto cleanup; + return -1; =20 if (rc =3D=3D 0) { virAccessError(VIR_ERR_INTERNAL_ERROR, "%s", _("No UNIX caller UID available")); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virObjectUnref(identity); - return ret; + return 0; } =20 =20 @@ -130,21 +125,20 @@ virAccessDriverPolkitCheck(virAccessManagerPtr manage= r ATTRIBUTE_UNUSED, const char *permname, const char **attrs) { - char *actionid =3D NULL; - int ret =3D -1; + g_autofree char *actionid =3D NULL; pid_t pid; uid_t uid; unsigned long long startTime; int rv; =20 if (!(actionid =3D virAccessDriverPolkitFormatAction(typename, permnam= e))) - goto cleanup; + return -1; =20 if (virAccessDriverPolkitGetCaller(actionid, &pid, &startTime, &uid) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Check action '%s' for process '%lld' time %lld uid %d", actionid, (long long)pid, startTime, uid); @@ -157,18 +151,14 @@ virAccessDriverPolkitCheck(virAccessManagerPtr manage= r ATTRIBUTE_UNUSED, false); =20 if (rv =3D=3D 0) { - ret =3D 1; /* Allowed */ + return 1; /* Allowed */ } else { if (rv =3D=3D -2) { - ret =3D 0; /* Denied */ + return 0; /* Denied */ } else { - ret =3D -1; /* Error */ + return -1; /* Error */ } } - - cleanup: - VIR_FREE(actionid); - return ret; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704876; cv=none; d=zoho.com; s=zohoarc; b=USYGFY72TJd6aewokAS6AKqTQ0F5YuIRRA/FQU0J1+9YXSEn47LlRYa1Ew4V/yxWVbcaThgur9T3zocAt9jhWjxDgjhB5yeJvgvcZ11P+JmsYoKO98hY3HEVqKHvzQ4pZMv8K5yG38a4AAMfW5UzRqDuSw43cX74lTurUQbm4lM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704876; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zSOQmfbf28dPL6rWx/rdyXchrXjf/7FqpYOqqvLHuT0=; b=VjEE0OaHU91wwR1Ue76RG7VHQqOeFNRlirkL3lyQPOmzYaVn1FgwwNVGB18+/i58zrscbVU/ml9arC3gM9B1O8LSoBq+3PKIS0Pe98bSYS/CwAjm7nYjRvXQbXquD1EqgcVjFHmSdIJFu0iLtoj9KHI3JA5R4aKfoK3253caO7Q= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704876512945.211854745111; Thu, 10 Oct 2019 03:54:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFD448E588; Thu, 10 Oct 2019 10:54:34 +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 A6605167A3; Thu, 10 Oct 2019 10:54:34 +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 61E41180BA9F; Thu, 10 Oct 2019 10:54:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsVCM010450 for ; Thu, 10 Oct 2019 06:54:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9017C5C231; Thu, 10 Oct 2019 10:54:31 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id E00E55C22C; Thu, 10 Oct 2019 10:54:30 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:06 +0100 Message-Id: <20191010105413.4091-13-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 12/19] admin: convert admin server code to use auto free macros 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 10 Oct 2019 10:54:35 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/admin/admin_server.c | 204 ++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 119 deletions(-) diff --git a/src/admin/admin_server.c b/src/admin/admin_server.c index 0d6091937d..ba87f701c3 100644 --- a/src/admin/admin_server.c +++ b/src/admin/admin_server.c @@ -75,15 +75,13 @@ adminServerGetThreadPoolParameters(virNetServerPtr srv, int *nparams, unsigned int flags) { - int ret =3D -1; - int maxparams =3D 0; size_t minWorkers; size_t maxWorkers; size_t nWorkers; size_t freeWorkers; size_t nPrioWorkers; size_t jobQueueDepth; - virTypedParameterPtr tmpparams =3D NULL; + g_autoptr(virTypedParamList) paramlist =3D g_new0(virTypedParamList, 1= ); =20 virCheckFlags(0, -1); =20 @@ -93,46 +91,36 @@ adminServerGetThreadPoolParameters(virNetServerPtr srv, &jobQueueDepth) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to retrieve threadpool parameters")); - goto cleanup; + return -1; } =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_MIN, - minWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, minWorkers, + "%s", VIR_THREADPOOL_WORKERS_MIN) < 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_MAX, - maxWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, maxWorkers, + "%s", VIR_THREADPOOL_WORKERS_MAX) < 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_CURRENT, - nWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, nWorkers, + "%s", VIR_THREADPOOL_WORKERS_CURRENT) < 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_FREE, - freeWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, freeWorkers, + "%s", VIR_THREADPOOL_WORKERS_FREE) < 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_PRIORITY, - nPrioWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, nPrioWorkers, + "%s", VIR_THREADPOOL_WORKERS_PRIORITY) < = 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_JOB_QUEUE_DEPTH, - jobQueueDepth) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, jobQueueDepth, + "%s", VIR_THREADPOOL_JOB_QUEUE_DEPTH) < 0) + return -1; =20 - *params =3D tmpparams; - tmpparams =3D NULL; - ret =3D 0; + *nparams =3D virTypedParamListStealParams(paramlist, params); =20 - cleanup: - virTypedParamsFree(tmpparams, *nparams); - return ret; + return 0; } =20 int @@ -215,106 +203,90 @@ adminClientGetInfo(virNetServerClientPtr client, int *nparams, unsigned int flags) { - int ret =3D -1; - int maxparams =3D 0; bool readonly; - char *sock_addr =3D NULL; + g_autofree char *sock_addr =3D NULL; const char *attr =3D NULL; - virTypedParameterPtr tmpparams =3D NULL; - virIdentityPtr identity =3D NULL; + g_autoptr(virTypedParamList) paramlist =3D g_new0(virTypedParamList, 1= ); + g_autoptr(virIdentity) identity =3D NULL; int rc; =20 virCheckFlags(0, -1); =20 if (virNetServerClientGetInfo(client, &readonly, &sock_addr, &identity) < 0) - goto cleanup; + return -1; =20 - if (virTypedParamsAddBoolean(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_READONLY, - readonly) < 0) - goto cleanup; + if (virTypedParamListAddBoolean(paramlist, readonly, + "%s", VIR_CLIENT_INFO_READONLY) < 0) + return -1; =20 if ((rc =3D virIdentityGetSASLUserName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_SASL_USER_NAME, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_SASL_USER_NAME) <= 0) + return -1; =20 if (!virNetServerClientIsLocal(client)) { - if (virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_SOCKET_ADDR, - sock_addr) < 0) - goto cleanup; + if (virTypedParamListAddString(paramlist, sock_addr, + "%s", VIR_CLIENT_INFO_SOCKET_ADDR) = < 0) + return -1; =20 if ((rc =3D virIdentityGetX509DName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_X509_DISTINGUISHED_NAM= E, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_X509_DISTINGU= ISHED_NAME) < 0) + return -1; } else { pid_t pid; uid_t uid; gid_t gid; if ((rc =3D virIdentityGetUNIXUserID(identity, &uid)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddInt(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_USER_ID, uid) < 0) - goto cleanup; + virTypedParamListAddInt(paramlist, uid, + "%s", VIR_CLIENT_INFO_UNIX_USER_ID) < = 0) + return -1; =20 if ((rc =3D virIdentityGetUserName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_USER_NAME, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_UNIX_USER_NAM= E) < 0) + return -1; =20 if ((rc =3D virIdentityGetUNIXGroupID(identity, &gid)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddInt(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_GROUP_ID, gid) < 0) - goto cleanup; + virTypedParamListAddInt(paramlist, gid, + "%s", VIR_CLIENT_INFO_UNIX_GROUP_ID) <= 0) + return -1; =20 if ((rc =3D virIdentityGetGroupName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_GROUP_NAME, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_UNIX_GROUP_NA= ME) < 0) + return -1; =20 if ((rc =3D virIdentityGetProcessID(identity, &pid)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddInt(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_PROCESS_ID, pid) < 0) - goto cleanup; + virTypedParamListAddInt(paramlist, pid, + "%s", VIR_CLIENT_INFO_UNIX_PROCESS_ID)= < 0) + return -1; } =20 if ((rc =3D virIdentityGetSELinuxContext(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_SELINUX_CONTEXT, attr) < 0) - goto cleanup; - - *params =3D tmpparams; - tmpparams =3D NULL; - ret =3D 0; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_SELINUX_CONTEXT) = < 0) + return -1; =20 - cleanup: - if (tmpparams) - virTypedParamsFree(tmpparams, *nparams); - virObjectUnref(identity); - VIR_FREE(sock_addr); - return ret; + *nparams =3D virTypedParamListStealParams(paramlist, params); + return 0; } =20 int adminClientClose(virNetServerClientPtr client, @@ -332,39 +304,33 @@ adminServerGetClientLimits(virNetServerPtr srv, int *nparams, unsigned int flags) { - int ret =3D -1; - int maxparams =3D 0; - virTypedParameterPtr tmpparams =3D NULL; + g_autoptr(virTypedParamList) paramlist =3D g_new0(virTypedParamList, 1= ); =20 virCheckFlags(0, -1); =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_MAX, - virNetServerGetMaxClients(srv)) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetMaxClients(srv), + "%s", VIR_SERVER_CLIENTS_MAX) < 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_CURRENT, - virNetServerGetCurrentClients(srv)) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetCurrentClients(srv), + "%s", VIR_SERVER_CLIENTS_CURRENT) < 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_UNAUTH_MAX, - virNetServerGetMaxUnauthClients(srv)) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetMaxUnauthClients(srv), + "%s", VIR_SERVER_CLIENTS_UNAUTH_MAX) < 0) + return -1; =20 - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_UNAUTH_CURRENT, - virNetServerGetCurrentUnauthClients(srv)) < = 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetCurrentUnauthClients(srv), + "%s", VIR_SERVER_CLIENTS_UNAUTH_CURRENT) = < 0) + return -1; =20 - *params =3D tmpparams; - tmpparams =3D NULL; - ret =3D 0; + *nparams =3D virTypedParamListStealParams(paramlist, params); =20 - cleanup: - virTypedParamsFree(tmpparams, *nparams); - return ret; + return 0; } =20 int --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704895; cv=none; d=zoho.com; s=zohoarc; b=fxUcQvT7u0RCP/d7u/Uh+lgCqNgqj8KveGGgz3gksc+XCfnQzesP47Y1ZDWmhlrq92FkJPcp6WKXsW/mgoz7JgmeE4k0uFHBQj38mRC1orMVSoJ6/SjxwQMhA+O4UkWth5tGB3iZo7tOSM9xU9bbQdiGcHzceo1hQegqGGEPUbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704895; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l3ALoqWTionoMeRu0Pznj4aa9jD7QhfL9YU7XtypoKg=; b=XGHtDvXXu5A3au/W00xBpRqqfe5sxPlr8EoHSQN55rfAJ0H8wJOclRaOq0A2nsYxrKFO06QcYxt5un+UOHsJcKcCBapaBVTDCTqcwcQT1THG6vpz0QcAAW/hpyXMZ0Rw9v0/wwsARC3fM9nt8nktTWvbV0cY57thQMiLZfDMLxE= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704895776119.36810396679687; Thu, 10 Oct 2019 03:54:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9FA52D6A25; Thu, 10 Oct 2019 10:54:53 +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 BF2E36017E; Thu, 10 Oct 2019 10:54:53 +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 806D1180BAA7; Thu, 10 Oct 2019 10:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsYIs010471 for ; Thu, 10 Oct 2019 06:54:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id C12C55C231; Thu, 10 Oct 2019 10:54:34 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0D7B5C22C; Thu, 10 Oct 2019 10:54:31 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:07 +0100 Message-Id: <20191010105413.4091-14-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 13/19] rpc: convert methods using virIdentityPtr to auto free macros 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 10 Oct 2019 10:54:54 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/rpc/virnetserverclient.c | 47 ++++++++++++++-------------------- src/rpc/virnetserverprogram.c | 13 +++------- tests/virnetserverclienttest.c | 3 +-- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 171ee636dd..79287572b6 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -759,13 +759,13 @@ int virNetServerClientGetUNIXIdentity(virNetServerCli= entPtr client, static virIdentityPtr virNetServerClientCreateIdentity(virNetServerClientPtr client) { - char *username =3D NULL; - char *groupname =3D NULL; - char *seccontext =3D NULL; - virIdentityPtr ret =3D NULL; + g_autofree char *username =3D NULL; + g_autofree char *groupname =3D NULL; + g_autofree char *seccontext =3D NULL; + g_autoptr(virIdentity) ret =3D NULL; =20 if (!(ret =3D virIdentityNew())) - goto error; + return NULL; =20 if (client->sock && virNetSocketIsLocal(client->sock)) { gid_t gid; @@ -775,59 +775,50 @@ virNetServerClientCreateIdentity(virNetServerClientPt= r client) if (virNetSocketGetUNIXIdentity(client->sock, &uid, &gid, &pid, ×tamp) < 0) - goto error; + return NULL; =20 if (!(username =3D virGetUserName(uid))) - goto error; + return NULL; if (virIdentitySetUserName(ret, username) < 0) - goto error; + return NULL; if (virIdentitySetUNIXUserID(ret, uid) < 0) - goto error; + return NULL; =20 if (!(groupname =3D virGetGroupName(gid))) - goto error; + return NULL; if (virIdentitySetGroupName(ret, groupname) < 0) - goto error; + return NULL; if (virIdentitySetUNIXGroupID(ret, gid) < 0) - goto error; + return NULL; =20 if (virIdentitySetProcessID(ret, pid) < 0) - goto error; + return NULL; if (virIdentitySetProcessTime(ret, timestamp) < 0) - goto error; + return NULL; } =20 #if WITH_SASL if (client->sasl) { const char *identity =3D virNetSASLSessionGetIdentity(client->sasl= ); if (virIdentitySetSASLUserName(ret, identity) < 0) - goto error; + return NULL; } #endif =20 if (client->tls) { const char *identity =3D virNetTLSSessionGetX509DName(client->tls); if (virIdentitySetX509DName(ret, identity) < 0) - goto error; + return NULL; } =20 if (client->sock && virNetSocketGetSELinuxContext(client->sock, &seccontext) < 0) - goto error; + return NULL; if (seccontext && virIdentitySetSELinuxContext(ret, seccontext) < 0) - goto error; - - cleanup: - VIR_FREE(username); - VIR_FREE(groupname); - VIR_FREE(seccontext); - return ret; + return NULL; =20 - error: - virObjectUnref(ret); - ret =3D NULL; - goto cleanup; + return g_steal_pointer(&ret); } =20 =20 diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 7ae1d2e955..cca820ca5a 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -370,13 +370,13 @@ virNetServerProgramDispatchCall(virNetServerProgramPt= r prog, virNetServerClientPtr client, virNetMessagePtr msg) { - char *arg =3D NULL; - char *ret =3D NULL; + g_autofree char *arg =3D NULL; + g_autofree char *ret =3D NULL; int rv =3D -1; virNetServerProgramProcPtr dispatcher; virNetMessageError rerr; size_t i; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; =20 memset(&rerr, 0, sizeof(rerr)); =20 @@ -484,10 +484,7 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr= prog, } =20 xdr_free(dispatcher->ret_filter, ret); - VIR_FREE(arg); - VIR_FREE(ret); =20 - virObjectUnref(identity); /* Put reply on end of tx queue to send out */ return virNetServerClientSendMessage(client, msg); =20 @@ -496,10 +493,6 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr= prog, * RPC error message we can send back to the client */ rv =3D virNetServerProgramSendReplyError(prog, client, msg, &rerr, &ms= g->header); =20 - VIR_FREE(arg); - VIR_FREE(ret); - virObjectUnref(identity); - return rv; } =20 diff --git a/tests/virnetserverclienttest.c b/tests/virnetserverclienttest.c index d094de9840..42393d7dbe 100644 --- a/tests/virnetserverclienttest.c +++ b/tests/virnetserverclienttest.c @@ -51,7 +51,7 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUS= ED) int ret =3D -1; virNetSocketPtr sock =3D NULL; virNetServerClientPtr client =3D NULL; - virIdentityPtr ident =3D NULL; + g_autoptr(virIdentity) ident =3D NULL; const char *gotUsername =3D NULL; uid_t gotUserID; const char *gotGroupname =3D NULL; @@ -141,7 +141,6 @@ static int testIdentity(const void *opaque ATTRIBUTE_UN= USED) if (client) virNetServerClientClose(client); virObjectUnref(client); - virObjectUnref(ident); VIR_FORCE_CLOSE(sv[0]); VIR_FORCE_CLOSE(sv[1]); return ret; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704881; cv=none; d=zoho.com; s=zohoarc; b=ZevAk9RwbnBXH5OkQuME1WSvdOC7d+dQ5ieLzYeMcir9zEyu9uYXG0xtzRn/SvM0AZVoZMQM9/ffxm/Wp5vDMfRaNK+2yEGvFpF1e46PewOoOr/wrN2/nsfCM9QW6RrWqb5kzbyiJgPl60luEA8yif5Mnxm4gQOnvxTlSi376CE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704881; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=H2VdNDDZQgHZCDTmnkouD/F0IUX/ogFjqq608+p7l8Y=; b=nrkTIWyrIdN5lK6l9qkfP9GqUmYuXrK9d4HwUHLmy78rEQibAjkwVJiokPrbty8D6UmsGPsp7hHDcFs3vPCk1ntX/Wg/N8l4NicUAqJfyM/i7DR7MBTL+CM7PV5l7+9d9d0bx2qTs8Fj6p1wgvKJZY/q3uk7qzzh0kAKeaTr+pU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704881718813.5209401681647; Thu, 10 Oct 2019 03:54:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32B3E3004E5B; Thu, 10 Oct 2019 10:54:40 +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 0BB9E194B2; Thu, 10 Oct 2019 10:54:40 +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 BB2654EE6A; Thu, 10 Oct 2019 10:54:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAscer010493 for ; Thu, 10 Oct 2019 06:54:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 808955E1D1; Thu, 10 Oct 2019 10:54:38 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9C4E5C231; Thu, 10 Oct 2019 10:54:34 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:08 +0100 Message-Id: <20191010105413.4091-15-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 14/19] remote: convert methods using virIdentityPtr to auto free macros 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 10 Oct 2019 10:54:40 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon.c | 3 +-- src/remote/remote_daemon_dispatch.c | 35 ++++++++++------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 9281e226c4..7fcaa31c49 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -826,7 +826,7 @@ handleSystemMessageFunc(DBusConnection *connection ATTR= IBUTE_UNUSED, static void daemonRunStateInit(void *opaque) { virNetDaemonPtr dmn =3D opaque; - virIdentityPtr sysident =3D virIdentityGetSystem(); + g_autoptr(virIdentity) sysident =3D virIdentityGetSystem(); #ifdef MODULE_NAME bool mandatory =3D true; #else /* ! MODULE_NAME */ @@ -879,7 +879,6 @@ static void daemonRunStateInit(void *opaque) cleanup: daemonInhibitCallback(false, dmn); virObjectUnref(dmn); - virObjectUnref(sysident); virIdentitySetCurrent(NULL); } =20 diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index dbd2985c38..9fc5dc3998 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -159,7 +159,7 @@ remoteRelayDomainEventCheckACL(virNetServerClientPtr cl= ient, virConnectPtr conn, virDomainPtr dom) { virDomainDef def; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; =20 /* For now, we just create a virDomainDef with enough contents to @@ -177,7 +177,6 @@ remoteRelayDomainEventCheckACL(virNetServerClientPtr cl= ient, =20 cleanup: ignore_value(virIdentitySetCurrent(NULL)); - virObjectUnref(identity); return ret; } =20 @@ -187,7 +186,7 @@ remoteRelayNetworkEventCheckACL(virNetServerClientPtr c= lient, virConnectPtr conn, virNetworkPtr net) { virNetworkDef def; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; =20 /* For now, we just create a virNetworkDef with enough contents to @@ -204,7 +203,6 @@ remoteRelayNetworkEventCheckACL(virNetServerClientPtr c= lient, =20 cleanup: ignore_value(virIdentitySetCurrent(NULL)); - virObjectUnref(identity); return ret; } =20 @@ -214,7 +212,7 @@ remoteRelayStoragePoolEventCheckACL(virNetServerClientP= tr client, virStoragePoolPtr pool) { virStoragePoolDef def; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; =20 /* For now, we just create a virStoragePoolDef with enough contents to @@ -231,7 +229,6 @@ remoteRelayStoragePoolEventCheckACL(virNetServerClientP= tr client, =20 cleanup: ignore_value(virIdentitySetCurrent(NULL)); - virObjectUnref(identity); return ret; } =20 @@ -241,7 +238,7 @@ remoteRelayNodeDeviceEventCheckACL(virNetServerClientPt= r client, virNodeDevicePtr dev) { virNodeDeviceDef def; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; =20 /* For now, we just create a virNodeDeviceDef with enough contents to @@ -257,7 +254,6 @@ remoteRelayNodeDeviceEventCheckACL(virNetServerClientPt= r client, =20 cleanup: ignore_value(virIdentitySetCurrent(NULL)); - virObjectUnref(identity); return ret; } =20 @@ -267,7 +263,7 @@ remoteRelaySecretEventCheckACL(virNetServerClientPtr cl= ient, virSecretPtr secret) { virSecretDef def; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; =20 /* For now, we just create a virSecretDef with enough contents to @@ -285,7 +281,6 @@ remoteRelaySecretEventCheckACL(virNetServerClientPtr cl= ient, =20 cleanup: ignore_value(virIdentitySetCurrent(NULL)); - virObjectUnref(identity); return ret; } =20 @@ -294,7 +289,7 @@ remoteRelayDomainQemuMonitorEventCheckACL(virNetServerC= lientPtr client, virConnectPtr conn, virDomainPtr= dom) { virDomainDef def; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; bool ret =3D false; =20 /* For now, we just create a virDomainDef with enough contents to @@ -311,7 +306,6 @@ remoteRelayDomainQemuMonitorEventCheckACL(virNetServerC= lientPtr client, =20 cleanup: ignore_value(virIdentitySetCurrent(NULL)); - virObjectUnref(identity); return ret; } =20 @@ -1869,7 +1863,7 @@ void remoteRelayConnectionClosedEvent(virConnectPtr c= onn ATTRIBUTE_UNUSED, int r static void remoteClientFreePrivateCallbacks(struct daemonClientPrivate *priv) { - virIdentityPtr sysident =3D virIdentityGetSystem(); + g_autoptr(virIdentity) sysident =3D virIdentityGetSystem(); virIdentitySetCurrent(sysident); =20 DEREG_CB(priv->conn, priv->domainEventCallbacks, @@ -1898,7 +1892,6 @@ remoteClientFreePrivateCallbacks(struct daemonClientP= rivate *priv) } =20 virIdentitySetCurrent(NULL); - virObjectUnref(sysident); } #undef DEREG_CB =20 @@ -1965,7 +1958,7 @@ remoteOpenConn(const char *uri, } =20 if (preserveIdentity) { - VIR_AUTOUNREF(virIdentityPtr) ident =3D NULL; + g_autoptr(virIdentity) ident =3D NULL; =20 if (!(ident =3D virIdentityGetCurrent())) return -1; @@ -2436,7 +2429,7 @@ remoteDispatchConnectSetIdentity(virNetServerPtr serv= er ATTRIBUTE_UNUSED, int nparams =3D 0; int rv =3D -1; virConnectPtr conn =3D remoteGetHypervisorConn(client); - VIR_AUTOUNREF(virIdentityPtr) ident =3D NULL; + g_autoptr(virIdentity) ident =3D NULL; if (!conn) goto cleanup; =20 @@ -3982,7 +3975,7 @@ static int remoteSASLFinish(virNetServerPtr server, virNetServerClientPtr client) { - virIdentityPtr clnt_identity =3D NULL; + g_autoptr(virIdentity) clnt_identity =3D NULL; const char *identity; struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(= client); int ssf; @@ -3990,7 +3983,7 @@ remoteSASLFinish(virNetServerPtr server, /* TLS or UNIX domain sockets trivially OK */ if (!virNetServerClientIsSecure(client)) { if ((ssf =3D virNetSASLSessionGetKeySize(priv->sasl)) < 0) - goto error; + return -1; =20 VIR_DEBUG("negotiated an SSF of %d", ssf); if (ssf < 56) { /* 56 is good for Kerberos */ @@ -4006,7 +3999,7 @@ remoteSASLFinish(virNetServerPtr server, return -2; =20 if (!(clnt_identity =3D virNetServerClientGetIdentity(client))) - goto error; + return -1; =20 virNetServerSetClientAuthenticated(server, client); virNetServerClientSetSASLSession(client, priv->sasl); @@ -4018,14 +4011,10 @@ remoteSASLFinish(virNetServerPtr server, "client=3D%p auth=3D%d identity=3D%s", client, REMOTE_AUTH_SASL, identity); =20 - virObjectUnref(clnt_identity); virObjectUnref(priv->sasl); priv->sasl =3D NULL; =20 return 0; - - error: - return -1; } =20 /* --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704885; cv=none; d=zoho.com; s=zohoarc; b=MVxlYNavFiyBJTDERafLPTXPqoQUfTw5vnXGfn9pROadSQSlMpLKBYOicRQgerJMZgUb10WthBVTs/cp7FL99RnA8voKxYUcfEPxjQfbuNRbxYHiGvFPaAjC0fugKOqxztG85BCw5wGEHzM2fq2A1ARLBRjzYvCb501ga/+x8fw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704885; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xwzsIxPhOqW8Ukor/nh7QMGQHI608UuqrDZoN8wcWt8=; b=JjspckhIYwA9PC7Ue11kPNE9j5oy/L4/pkA+E07cNjvNc2z3/lcuG8FKNCHNBUyLshAoHFS8PCvRB5HvGUGLnd9VfXk3yWQC8JRmXR13Naozvdtkr7L3hEOsBE4NPnL2MFaImXIp7zK/71RqRn3yepqP4ll0LuDgwyytd8Ver4Q= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704885355381.90390211973977; Thu, 10 Oct 2019 03:54:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 928E910CC1FF; Thu, 10 Oct 2019 10:54:43 +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 6BF98600C4; Thu, 10 Oct 2019 10:54:43 +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 2BE79180B536; Thu, 10 Oct 2019 10:54:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsdGT010498 for ; Thu, 10 Oct 2019 06:54:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B1925C22F; Thu, 10 Oct 2019 10:54:39 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB7E35C1B5; Thu, 10 Oct 2019 10:54:38 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:09 +0100 Message-Id: <20191010105413.4091-16-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 15/19] util: convert virIdentity class to use GObject 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Thu, 10 Oct 2019 10:54:44 +0000 (UTC) Converting from virObject to GObject is reasonably straightforward, as illustrated by this patch for virIdentity In the header file - Remove typedef struct _virIdentity virIdentity - Add #define VIR_TYPE_IDENTITY virIdentity_get_type () G_DECLARE_FINAL_TYPE (virIdentity, vir_identity, VIR, IDENTITY, GObjec= t); Which provides the typedef we just removed, and class declaration boilerplate and various other constants/macros. In the source file - Change 'virObject parent' to 'GObject parent' in the struct - Remove the virClass variable and its initializing call - Add G_DEFINE_TYPE(virIdentity, vir_identity, G_TYPE_OBJECT) which declares the instance & class constructor functions - Add an impl of the instance & class constructors wiring up the finalize method to point to our dispose impl In all files - Replace VIR_AUTOUNREF(virIdentityPtr) with g_autoptr(virIdentity) - Replace virObjectRef/Unref with g_object_ref/unref. Note the latter functions do *NOT* accept a NULL object where as libvirt's do. If you replace g_object_unref with g_clear_object it is NULL safe, but also clears the pointer. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- m4/virt-glib.m4 | 4 +-- src/qemu/qemu_process.c | 4 +-- src/rpc/virnetserverclient.c | 10 +++---- src/util/viridentity.c | 56 ++++++++++++++++++++++-------------- src/util/viridentity.h | 9 +++--- tests/viridentitytest.c | 5 +--- 6 files changed, 49 insertions(+), 39 deletions(-) diff --git a/m4/virt-glib.m4 b/m4/virt-glib.m4 index 5a5bc19660..eb2c77b25b 100644 --- a/m4/virt-glib.m4 +++ b/m4/virt-glib.m4 @@ -24,10 +24,10 @@ AC_DEFUN([LIBVIRT_ARG_GLIB], [ AC_DEFUN([LIBVIRT_CHECK_GLIB],[ GLIB_REQUIRED=3D2.48.0 =20 - LIBVIRT_CHECK_PKG([GLIB], [glib-2.0], [$GLIB_REQUIRED]) + LIBVIRT_CHECK_PKG([GLIB], [glib-2.0 gobject-2.0], [$GLIB_REQUIRED]) =20 if test "$with_glib" =3D "no" ; then - AC_MSG_ERROR([glib-2.0 >=3D $GLIB_REQUIRED is required for libvirt]) + AC_MSG_ERROR([glib-2.0, gobject-2.0 >=3D $GLIB_REQUIRED are required f= or libvirt]) fi ]) =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c14c09da11..3b45b2f641 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8040,7 +8040,7 @@ qemuProcessReconnect(void *opaque) bool tryMonReconn =3D false; =20 virIdentitySetCurrent(data->identity); - virObjectUnref(data->identity); + g_clear_object(&data->identity); VIR_FREE(data); =20 qemuDomainObjRestoreJob(obj, &oldjob); @@ -8353,7 +8353,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj, =20 virDomainObjEndAPI(&obj); virNWFilterUnlockFilterUpdates(); - virObjectUnref(data->identity); + g_clear_object(&data->identity); VIR_FREE(data); return -1; } diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 79287572b6..8482c5c29c 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -829,7 +829,7 @@ virIdentityPtr virNetServerClientGetIdentity(virNetServ= erClientPtr client) if (!client->identity) client->identity =3D virNetServerClientCreateIdentity(client); if (client->identity) - ret =3D virObjectRef(client->identity); + ret =3D g_object_ref(client->identity); virObjectUnlock(client); return ret; } @@ -839,10 +839,10 @@ void virNetServerClientSetIdentity(virNetServerClient= Ptr client, virIdentityPtr identity) { virObjectLock(client); - virObjectUnref(client->identity); + g_clear_object(&client->identity); client->identity =3D identity; if (client->identity) - virObjectRef(client->identity); + g_object_ref(client->identity); virObjectUnlock(client); } =20 @@ -979,7 +979,7 @@ void virNetServerClientDispose(void *obj) if (client->privateData) client->privateDataFreeFunc(client->privateData); =20 - virObjectUnref(client->identity); + g_clear_object(&client->identity); =20 #if WITH_SASL virObjectUnref(client->sasl); @@ -1674,7 +1674,7 @@ virNetServerClientGetInfo(virNetServerClientPtr clien= t, goto cleanup; } =20 - *identity =3D virObjectRef(client->identity); + *identity =3D g_object_ref(client->identity); =20 ret =3D 0; cleanup: diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 6636077161..8cc2db2568 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -43,25 +43,29 @@ VIR_LOG_INIT("util.identity"); =20 struct _virIdentity { - virObject parent; + GObject parent; =20 int nparams; int maxparams; virTypedParameterPtr params; }; =20 -static virClassPtr virIdentityClass; +G_DEFINE_TYPE(virIdentity, vir_identity, G_TYPE_OBJECT) + static virThreadLocal virIdentityCurrent; =20 -static void virIdentityDispose(void *obj); +static void virIdentityFinalize(GObject *obj); =20 -static int virIdentityOnceInit(void) +static void virIdentityCurrentCleanup(void *ident) { - if (!VIR_CLASS_NEW(virIdentity, virClassForObject())) - return -1; + if (ident) + g_object_unref(ident); +} =20 +static int virIdentityOnceInit(void) +{ if (virThreadLocalInit(&virIdentityCurrent, - (virThreadLocalCleanup)virObjectUnref) < 0) { + virIdentityCurrentCleanup) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot initialize thread local for current ident= ity")); return -1; @@ -72,13 +76,24 @@ static int virIdentityOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(virIdentity); =20 +static void vir_identity_init(virIdentity *ident G_GNUC_UNUSED) +{ +} + +static void vir_identity_class_init(virIdentityClass *klass) +{ + GObjectClass *obj =3D G_OBJECT_CLASS(klass); + + obj->finalize =3D virIdentityFinalize; +} + /** * virIdentityGetCurrent: * * Get the current identity associated with this thread. The * caller will own a reference to the returned identity, but * must not modify the object in any way, other than to - * release the reference when done with virObjectUnref + * release the reference when done with g_object_unref * * Returns: a reference to the current identity, or NULL */ @@ -90,7 +105,9 @@ virIdentityPtr virIdentityGetCurrent(void) return NULL; =20 ident =3D virThreadLocalGet(&virIdentityCurrent); - return virObjectRef(ident); + if (ident) + g_object_ref(ident); + return ident; } =20 =20 @@ -113,10 +130,11 @@ int virIdentitySetCurrent(virIdentityPtr ident) old =3D virThreadLocalGet(&virIdentityCurrent); =20 if (virThreadLocalSet(&virIdentityCurrent, - virObjectRef(ident)) < 0) { + ident ? g_object_ref(ident) : NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to set thread local identity")); - virObjectUnref(ident); + if (ident) + g_object_unref(ident); return -1; } =20 @@ -197,23 +215,17 @@ virIdentityPtr virIdentityGetSystem(void) */ virIdentityPtr virIdentityNew(void) { - virIdentityPtr ident; - - if (virIdentityInitialize() < 0) - return NULL; - - if (!(ident =3D virObjectNew(virIdentityClass))) - return NULL; - - return ident; + return VIR_IDENTITY(g_object_new(VIR_TYPE_IDENTITY, NULL)); } =20 =20 -static void virIdentityDispose(void *object) +static void virIdentityFinalize(GObject *object) { - virIdentityPtr ident =3D object; + virIdentityPtr ident =3D VIR_IDENTITY(object); =20 virTypedParamsFree(ident->params, ident->nparams); + + G_OBJECT_CLASS(vir_identity_parent_class)->finalize(object); } =20 =20 diff --git a/src/util/viridentity.h b/src/util/viridentity.h index 7513dd4e35..2940e02054 100644 --- a/src/util/viridentity.h +++ b/src/util/viridentity.h @@ -21,12 +21,13 @@ =20 #pragma once =20 -#include "virobject.h" +#include "internal.h" +#include =20 -typedef struct _virIdentity virIdentity; -typedef virIdentity *virIdentityPtr; +#define VIR_TYPE_IDENTITY vir_identity_get_type() +G_DECLARE_FINAL_TYPE(virIdentity, vir_identity, VIR, IDENTITY, GObject); =20 -G_DEFINE_AUTOPTR_CLEANUP_FUNC(virIdentity, virObjectUnref); +typedef virIdentity *virIdentityPtr; =20 virIdentityPtr virIdentityGetCurrent(void); int virIdentitySetCurrent(virIdentityPtr ident); diff --git a/tests/viridentitytest.c b/tests/viridentitytest.c index db041a98a8..90e7247817 100644 --- a/tests/viridentitytest.c +++ b/tests/viridentitytest.c @@ -38,13 +38,10 @@ VIR_LOG_INIT("tests.identitytest"); =20 static int testIdentityAttrs(const void *data ATTRIBUTE_UNUSED) { - g_autoptr(virIdentity) ident =3D NULL; + g_autoptr(virIdentity) ident =3D virIdentityNew(); const char *val; int rc; =20 - if (!(ident =3D virIdentityNew())) - return -1; - if (virIdentitySetUserName(ident, "fred") < 0) return -1; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704888; cv=none; d=zoho.com; s=zohoarc; b=RvzpMag2K/KqDRce6Ssee4I56OMqgqwAmUSK72Z+KBITh1WRreZaI1sb6fpDXZIAM1CC2ud9MMSE5PYr450TWgzLZfPPM80JMjTWTw8u2MNyfA+Fkn8JxuLEH+HFAUmzDWofbC2LVGoX+6ZEDzYEnfvms8Do0Nt63SSV4WfEtDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704888; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DnZG+87AR0H6eaNjeAupxl1EXMT9YyNAonWXbcfANKk=; b=VvWE2y0ckQvA1AoUQBGzYiMaajzqS3/bHd7qAEItEz8ur6OC9pH+hcKvNyUFValEeKZS/XJxxAMTD/0tbapj6vJFALlxDzhoHFv2/2iSgkFcsI0C9Ea3X8/Zz5HM8Vo7+GCFBPaWswxYjUrESZoPpkqpaVLLqNemcpb5d0LLih8= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704888407374.4257633945963; Thu, 10 Oct 2019 03:54:48 -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 D3A426696C; Thu, 10 Oct 2019 10:54:46 +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 B359960A9F; Thu, 10 Oct 2019 10:54:46 +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 7B2F3180BA9B; Thu, 10 Oct 2019 10:54:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAseHK010509 for ; Thu, 10 Oct 2019 06:54:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D4A75C1B5; Thu, 10 Oct 2019 10:54:40 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB9EB5C22C; Thu, 10 Oct 2019 10:54:39 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:10 +0100 Message-Id: <20191010105413.4091-17-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= , Pavel Hrdina Subject: [libvirt] [PATCH v3 16/19] libxl: convert over to use GRegex for regular expressions 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.38]); Thu, 10 Oct 2019 10:54:47 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_capabilities.c | 42 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 73ae0b3fa1..65c68ffb52 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -21,7 +21,6 @@ #include =20 #include -#include =20 #include "internal.h" #include "virlog.h" @@ -374,10 +373,10 @@ static int libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) { const libxl_version_info *ver_info; - int err; - regex_t regex; + g_autoptr(GRegex) regex =3D NULL; + g_autoptr(GError) err =3D NULL; + g_autoptr(GMatchInfo) info =3D NULL; char *str, *token; - regmatch_t subs[4]; char *saveptr =3D NULL; size_t i; =20 @@ -398,12 +397,10 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) return -1; } =20 - err =3D regcomp(®ex, XEN_CAP_REGEX, REG_EXTENDED); - if (err !=3D 0) { - char error[100]; - regerror(err, ®ex, error, sizeof(error)); + regex =3D g_regex_new(XEN_CAP_REGEX, G_REGEX_EXTENDED, 0, &err); + if (!regex) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to compile regex %s"), error); + _("Failed to compile regex %s"), err->message); return -1; } =20 @@ -436,31 +433,31 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) nr_guest_archs < sizeof(guest_archs) / sizeof(guest_archs[0]) && (token =3D strtok_r(str, " ", &saveptr)) !=3D NULL; str =3D NULL) { - if (regexec(®ex, token, sizeof(subs) / sizeof(subs[0]), - subs, 0) =3D=3D 0) { - int hvm =3D STRPREFIX(&token[subs[1].rm_so], "hvm"); + if (g_regex_match(regex, token, 0, &info)) { + g_autofree char *modestr =3D g_match_info_fetch(info, 1); + g_autofree char *archstr =3D g_match_info_fetch(info, 2); + g_autofree char *suffixstr =3D g_match_info_fetch(info, 3); + int hvm =3D STRPREFIX(modestr, "hvm"); virArch arch; int pae =3D 0, nonpae =3D 0, ia64_be =3D 0; =20 - if (STRPREFIX(&token[subs[2].rm_so], "x86_32")) { + if (STRPREFIX(archstr, "x86_32")) { arch =3D VIR_ARCH_I686; - if (subs[3].rm_so !=3D -1 && - STRPREFIX(&token[subs[3].rm_so], "p")) + if (suffixstr !=3D NULL && STRPREFIX(suffixstr, "p")) pae =3D 1; else nonpae =3D 1; - } else if (STRPREFIX(&token[subs[2].rm_so], "x86_64")) { + } else if (STRPREFIX(archstr, "x86_64")) { arch =3D VIR_ARCH_X86_64; - } else if (STRPREFIX(&token[subs[2].rm_so], "ia64")) { + } else if (STRPREFIX(archstr, "ia64")) { arch =3D VIR_ARCH_ITANIUM; - if (subs[3].rm_so !=3D -1 && - STRPREFIX(&token[subs[3].rm_so], "be")) + if (suffixstr !=3D NULL && STRPREFIX(suffixstr, "be")) ia64_be =3D 1; - } else if (STRPREFIX(&token[subs[2].rm_so], "powerpc64")) { + } else if (STRPREFIX(archstr, "powerpc64")) { arch =3D VIR_ARCH_PPC64; - } else if (STRPREFIX(&token[subs[2].rm_so], "armv7l")) { + } else if (STRPREFIX(archstr, "armv7l")) { arch =3D VIR_ARCH_ARMV7L; - } else if (STRPREFIX(&token[subs[2].rm_so], "aarch64")) { + } else if (STRPREFIX(archstr, "aarch64")) { arch =3D VIR_ARCH_AARCH64; } else { continue; @@ -515,7 +512,6 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) #endif } } - regfree(®ex); =20 for (i =3D 0; i < nr_guest_archs; ++i) { virCapsGuestPtr guest; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704892; cv=none; d=zoho.com; s=zohoarc; b=bkI4/SUbZslQJl7IPeak5Gbb7NG5GUyxN4EOIvu0wN5fmAt4/ZTeK6ejqWOLrA+C4thRpEp4MR2DwFqxmzVzWizHATzwR8elDJ47ZnvG5r6crikGJuAYCA+/TN2+IPlMs/BzcvFaTDaHXvWOlc5BxBBS6iU8AaFq3Jm4KcuBIcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704892; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RgHt5eWexFoGcpzwtr/Yq1XE60YEtZ9D9rEN/rWHGCQ=; b=OhhmniPsuza7JzwgkwH7vgW0e8dvdXNsq3EsvguKZr2odz8RicMu326X5t3401IHdLXaaR9p7WzmV/wZDZgBdINSDmTW0B4GmnO9IlUDR1EY/JGx9xNtW83Ddk8KhBKrUGckjktcF3Ruh+SpLjHMoB8h1JSLI6kCL1eR73SYB+Q= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704892181170.2739164197419; Thu, 10 Oct 2019 03:54:52 -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 5E2CC2D0FC7; Thu, 10 Oct 2019 10:54:50 +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 37ED45C231; Thu, 10 Oct 2019 10:54:50 +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 EB1274EE73; Thu, 10 Oct 2019 10:54:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsf45010518 for ; Thu, 10 Oct 2019 06:54:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8D9245C231; Thu, 10 Oct 2019 10:54:41 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD71B5C1B5; Thu, 10 Oct 2019 10:54:40 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:11 +0100 Message-Id: <20191010105413.4091-18-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= , Pavel Hrdina Subject: [libvirt] [PATCH v3 17/19] conf: convert over to use GRegex for regular expressions 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 10 Oct 2019 10:54:50 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_event.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index b33589f472..40031a46c8 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -22,8 +22,6 @@ =20 #include =20 -#include - #include "domain_event.h" #include "object_event.h" #include "object_event_private.h" @@ -2009,7 +2007,7 @@ virDomainQemuMonitorEventNew(int id, * deregisters. */ struct virDomainQemuMonitorEventData { char *event; - regex_t regex; + GRegex *regex; unsigned int flags; void *opaque; virFreeCallback freecb; @@ -2241,7 +2239,7 @@ virDomainQemuMonitorEventFilter(virConnectPtr conn AT= TRIBUTE_UNUSED, if (data->flags =3D=3D -1) return true; if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) - return regexec(&data->regex, monitorEvent->event, 0, NULL, 0) =3D= =3D 0; + return g_regex_match(data->regex, monitorEvent->event, 0, NULL) = =3D=3D TRUE; if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCAS= E) return STRCASEEQ(monitorEvent->event, data->event); return STREQ(monitorEvent->event, data->event); @@ -2255,7 +2253,7 @@ virDomainQemuMonitorEventCleanup(void *opaque) =20 VIR_FREE(data->event); if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) - regfree(&data->regex); + g_regex_unref(data->regex); if (data->freecb) (data->freecb)(data->opaque); VIR_FREE(data); @@ -2306,20 +2304,17 @@ virDomainQemuMonitorEventStateRegisterID(virConnect= Ptr conn, return -1; data->flags =3D flags; if (event && flags !=3D -1) { - int rflags =3D REG_NOSUB; - - if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE) - rflags |=3D REG_ICASE; if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) { - int err =3D regcomp(&data->regex, event, rflags); + int cflags =3D G_REGEX_OPTIMIZE; + g_autoptr(GError) err =3D NULL; =20 - if (err) { - char error[100]; - regerror(err, &data->regex, error, sizeof(error)); + if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOC= ASE) + cflags |=3D G_REGEX_CASELESS; + data->regex =3D g_regex_new(event, cflags, 0, &err); + if (!data->regex) { virReportError(VIR_ERR_INVALID_ARG, _("failed to compile regex '%s': %s"), - event, error); - regfree(&data->regex); + event, err->message); VIR_FREE(data); return -1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704895; cv=none; d=zoho.com; s=zohoarc; b=LL5AalgVCdJQm4kSaez9gEtIOTrRbQQbQrvF1ahSxezF8QN/HEWVqdEToqG9+jfnqz1OLIMMmAp0D/AmmC2iC4RJbkSjcCQti6Ks+3cSM/Rm9Car4srDEBZTYdw/puN8D8Sv+PROr064PusvQXG0Wege5ubDdnLSHD3Z6zWAM6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704895; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+CLWSLbCZnF+J/md4rQD0J6s7bxo844IpiuK0I44bnI=; b=EfzKQ5knV1q1fQZcDWVeK/Cp92wg30Sl/HPJw+J9R9hX+Lc7v+gjVkzG9HJcjhxS8YhN3yMcKNMSUuTBBRLvLKIJH2GYXWEGkse7l/EzJT9Dl80RQtyCKWewctQt3LizWMRtAPN4/JMd/1P7tyWxdvvxHBTj6CsDPNSG2wmkLcc= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 157070489550161.61315510996519; Thu, 10 Oct 2019 03:54:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5F58883C45; Thu, 10 Oct 2019 10:54:53 +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 8FFD75EE1D; Thu, 10 Oct 2019 10:54:53 +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 4A7D34EEB8; Thu, 10 Oct 2019 10:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsgOj010526 for ; Thu, 10 Oct 2019 06:54:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CA3A5C231; Thu, 10 Oct 2019 10:54:42 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD6795C1B5; Thu, 10 Oct 2019 10:54:41 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:12 +0100 Message-Id: <20191010105413.4091-19-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 18/19] util: replace strerror/strerror_r with g_strerror 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 10 Oct 2019 10:54:54 +0000 (UTC) g_strerror is offers the safety/correctness benefits of strerror_r, with the API design convenience of strerror. Use of virStrerror should be eliminated through the codebase in favour of g_strerror. commandhelper.c is a special case as its a tiny single threaded test program, not linked to glib, so it just uses traditional strerror(). Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- bootstrap.conf | 2 -- docs/hacking.html.in | 4 ++++ src/util/virerror.c | 9 +++++---- src/util/virerror.h | 1 + tests/commandtest.c | 10 +++++----- tests/qemumonitortestutils.c | 2 +- tests/seclabeltest.c | 4 ++-- tests/testutils.c | 6 +++--- tests/virhostcputest.c | 4 ++-- tests/virtestmock.c | 4 ++-- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index bb40e978aa..241dce50c2 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -79,8 +79,6 @@ snprintf socket stat-time strchrnul -strerror -strerror_r-posix strptime strsep strtok_r diff --git a/docs/hacking.html.in b/docs/hacking.html.in index a92608cd3c..6cf796a175 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -1051,6 +1051,10 @@ BAD:
The GLib macros g_autoptr and G_DEFINE_AUTOPTR_CLEANUP_FUNC should be used to manage autoclean of virObject classes. This matches usage with GObject classes.
+ +
virStrerror
+
The GLib g_strerror() function should be used instead, + which has a simpler calling convention as an added benefit.
=20

File handling

diff --git a/src/util/virerror.c b/src/util/virerror.c index 3bb9d1d32c..5d69e4e972 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1322,8 +1322,11 @@ const char *virStrerror(int theerrno, char *errBuf, = size_t errBufLen) { int save_errno =3D errno; const char *ret; + const char *str =3D g_strerror(theerrno); + size_t len =3D strlen(str); =20 - strerror_r(theerrno, errBuf, errBufLen); + memcpy(errBuf, str, MIN(len, errBufLen)); + errBuf[errBufLen-1] =3D '\0'; ret =3D errBuf; errno =3D save_errno; return ret; @@ -1349,11 +1352,9 @@ void virReportSystemErrorFull(int domcode, const char *fmt, ...) { int save_errno =3D errno; - char strerror_buf[VIR_ERROR_MAX_LENGTH]; char msgDetailBuf[VIR_ERROR_MAX_LENGTH]; =20 - const char *errnoDetail =3D virStrerror(theerrno, strerror_buf, - sizeof(strerror_buf)); + const char *errnoDetail =3D g_strerror(theerrno); const char *msg =3D virErrorMsg(VIR_ERR_SYSTEM_ERROR, fmt); const char *msgDetail =3D NULL; =20 diff --git a/src/util/virerror.h b/src/util/virerror.h index fa88217b27..201195d660 100644 --- a/src/util/virerror.h +++ b/src/util/virerror.h @@ -193,6 +193,7 @@ void virReportOOMErrorFull(int domcode, int virSetError(virErrorPtr newerr); virErrorPtr virErrorCopyNew(virErrorPtr err); void virDispatchError(virConnectPtr conn); +/* DEPRECATED: use g_strerror() directly */ const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen); =20 typedef int (*virErrorLogPriorityFunc)(virErrorPtr, int); diff --git a/tests/commandtest.c b/tests/commandtest.c index c6fd826003..2aaddef3d1 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -636,12 +636,12 @@ static int test16(const void *unused ATTRIBUTE_UNUSED) } if ((fd =3D open(abs_builddir "/commandhelper.log", O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) { - printf("Cannot open log file: %s\n", strerror(errno)); + printf("Cannot open log file: %s\n", g_strerror(errno)); goto cleanup; } virCommandWriteArgLog(cmd, fd); if (VIR_CLOSE(fd) < 0) { - printf("Cannot close log file: %s\n", strerror(errno)); + printf("Cannot close log file: %s\n", g_strerror(errno)); goto cleanup; } =20 @@ -1116,12 +1116,12 @@ static int test26(const void *unused ATTRIBUTE_UNUS= ED) } if ((fd =3D open(abs_builddir "/commandhelper.log", O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) { - printf("Cannot open log file: %s\n", strerror(errno)); + printf("Cannot open log file: %s\n", g_strerror(errno)); goto cleanup; } virCommandWriteArgLog(cmd, fd); if (VIR_CLOSE(fd) < 0) { - printf("Cannot close log file: %s\n", strerror(errno)); + printf("Cannot close log file: %s\n", g_strerror(errno)); goto cleanup; } =20 @@ -1186,7 +1186,7 @@ static int test27(const void *unused ATTRIBUTE_UNUSED) } =20 if (pipe(pipe1) < 0 || pipe(pipe2) < 0) { - printf("Could not create pipe: %s\n", strerror(errno)); + printf("Could not create pipe: %s\n", g_strerror(errno)); goto cleanup; } =20 diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index c7580c5f28..9f2594b09a 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -417,7 +417,7 @@ qemuMonitorTestFree(qemuMonitorTestPtr test) VIR_FREE(test->items); =20 if (test->tmpdir && rmdir(test->tmpdir) < 0) - VIR_WARN("Failed to remove tempdir: %s", strerror(errno)); + VIR_WARN("Failed to remove tempdir: %s", g_strerror(errno)); =20 VIR_FREE(test->tmpdir); =20 diff --git a/tests/seclabeltest.c b/tests/seclabeltest.c index 42dcb8c97f..105c25ea2d 100644 --- a/tests/seclabeltest.c +++ b/tests/seclabeltest.c @@ -20,14 +20,14 @@ mymain(void) model =3D virSecurityManagerGetModel(mgr); if (!model) { fprintf(stderr, "Failed to copy secModel model: %s", - strerror(errno)); + g_strerror(errno)); return EXIT_FAILURE; } =20 doi =3D virSecurityManagerGetDOI(mgr); if (!doi) { fprintf(stderr, "Failed to copy secModel DOI: %s", - strerror(errno)); + g_strerror(errno)); return EXIT_FAILURE; } =20 diff --git a/tests/testutils.c b/tests/testutils.c index 1b663f9d5d..1f3718b5cd 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -172,12 +172,12 @@ virTestLoadFile(const char *file, char **buf) int len, tmplen, buflen; =20 if (!fp) { - fprintf(stderr, "%s: failed to open: %s\n", file, strerror(errno)); + fprintf(stderr, "%s: failed to open: %s\n", file, g_strerror(errno= )); return -1; } =20 if (fstat(fileno(fp), &st) < 0) { - fprintf(stderr, "%s: failed to fstat: %s\n", file, strerror(errno)= ); + fprintf(stderr, "%s: failed to fstat: %s\n", file, g_strerror(errn= o)); VIR_FORCE_FCLOSE(fp); return -1; } @@ -208,7 +208,7 @@ virTestLoadFile(const char *file, char **buf) tmplen -=3D len; } if (ferror(fp)) { - fprintf(stderr, "%s: read failed: %s\n", file, strerror(errno)= ); + fprintf(stderr, "%s: read failed: %s\n", file, g_strerror(errn= o)); VIR_FORCE_FCLOSE(fp); VIR_FREE(*buf); return -1; diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 03ed3b1609..d9bdef701d 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -37,7 +37,7 @@ linuxTestCompareFiles(const char *cpuinfofile, cpuinfo =3D fopen(cpuinfofile, "r"); if (!cpuinfo) { fprintf(stderr, "unable to open: %s : %s\n", - cpuinfofile, strerror(errno)); + cpuinfofile, g_strerror(errno)); goto fail; } =20 @@ -86,7 +86,7 @@ linuxCPUStatsToBuf(virBufferPtr buf, =20 if ((sc_clk_tck =3D sysconf(_SC_CLK_TCK)) < 0) { fprintf(stderr, "sysconf(_SC_CLK_TCK) fails : %s\n", - strerror(errno)); + g_strerror(errno)); return -1; } tick_to_nsec =3D (1000ull * 1000ull * 1000ull) / sc_clk_tck; diff --git a/tests/virtestmock.c b/tests/virtestmock.c index df8cac6441..fa52667a2b 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -76,12 +76,12 @@ printFile(const char *file, } =20 if (!(fp =3D real_fopen(output, "a"))) { - fprintf(stderr, "Unable to open %s: %s\n", output, strerror(errno)= ); + fprintf(stderr, "Unable to open %s: %s\n", output, g_strerror(errn= o)); abort(); } =20 if (flock(fileno(fp), LOCK_EX) < 0) { - fprintf(stderr, "Unable to lock %s: %s\n", output, strerror(errno)= ); + fprintf(stderr, "Unable to lock %s: %s\n", output, g_strerror(errn= o)); fclose(fp); abort(); } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:55:44 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 ARC-Seal: i=1; a=rsa-sha256; t=1570704892; cv=none; d=zoho.com; s=zohoarc; b=Upu9eFZmsfZfw8JoSkI6J3DFpjubXABn/kzNDZDpGXvKnJzlq2z21x2AWfsFWKqc/E0xaoYzwgocU5JORqYuE6KulezP1GR0XD5mfgSs1kGv8SOzj5b/59iI69DE3N/Ekbf59stWtc9WFsGEnbN/2HQiJgyKeVfL42IZ5CdR6Cw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704892; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DmmN+MtSZMfJDQpUd4vQsxXe345/TOGdwc92SlYycgs=; b=UHqqG8hvEniZSTPM4xLJQXVaGL3j47MagM0Eq/JGVMvns2dA7Wlh3njwnoBk72lAXrP+YSYw6WSuPZB44YfB7u0rqblPySKwqqukL75yA9mYp8dNMNPI5ZwXHyoXdF0HeQleYzrfi/LALKpUL9qkApWQxeC7tA5L+2rRqjAcXcg= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704892347665.8660699983739; Thu, 10 Oct 2019 03:54:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC5F23086E26; Thu, 10 Oct 2019 10:54:50 +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 A29A05D6A5; Thu, 10 Oct 2019 10:54:50 +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 5EA914EE7E; Thu, 10 Oct 2019 10:54:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsnv4010611 for ; Thu, 10 Oct 2019 06:54:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB0ED5C553; Thu, 10 Oct 2019 10:54:49 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDE325C231; Thu, 10 Oct 2019 10:54:42 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:13 +0100 Message-Id: <20191010105413.4091-20-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 19/19] build: remove use of usleep gnulib module in favour of g_usleep 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 10 Oct 2019 10:54:51 +0000 (UTC) The usleep function was missing on older mingw versions, but we can rely on it existing everywhere these days. It may only support times upto 1 second in duration though, so we'll prefer to use g_usleep instead. The commandhelper program is not changed since that can't link to glib. Fortunately it doesn't need to build on Windows platforms either. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- bootstrap.conf | 1 - src/hyperv/hyperv_driver.c | 2 +- src/hyperv/hyperv_wmi.c | 4 ++-- src/locking/lock_daemon.c | 2 +- src/locking/lock_driver_sanlock.c | 2 +- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_driver.c | 2 +- src/lxc/lxc_process.c | 2 +- src/network/bridge_driver.c | 2 +- src/nwfilter/nwfilter_dhcpsnoop.c | 4 ++-- src/nwfilter/nwfilter_learnipaddr.c | 2 +- src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_process.c | 2 +- src/qemu/qemu_tpm.c | 2 +- src/rpc/virnetsocket.c | 2 +- src/security/security_manager.c | 2 +- src/storage/storage_util.c | 4 ++-- src/util/vircgroup.c | 2 +- src/util/virfile.c | 2 +- src/util/virnetdev.c | 2 +- src/util/virnetdevip.c | 2 +- src/util/virnetdevmacvlan.c | 2 +- src/util/virnetdevvportprofile.c | 2 +- src/util/virpci.c | 8 ++++---- src/util/virprocess.c | 4 ++-- src/util/virtime.c | 2 +- src/vbox/vbox_common.c | 2 +- tests/commandtest.c | 6 +++--- tests/eventtest.c | 4 ++-- tests/fdstreamtest.c | 4 ++-- tools/virsh-domain.c | 2 +- 31 files changed, 41 insertions(+), 42 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 241dce50c2..1b5a68b873 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -90,7 +90,6 @@ timegm ttyname_r uname unsetenv -usleep verify vsnprintf waitpid diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 0e2c6c55ef..ceaf528dd3 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1415,7 +1415,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int= codeset, =20 /* simulate holdtime by sleeping */ if (holdtime > 0) - usleep(holdtime * 1000); + g_usleep(holdtime * 1000); =20 /* release the keys */ for (i =3D 0; i < nkeycodes; i++) { diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 0f39bd4431..c2c1f082e1 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -909,7 +909,7 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokePar= amsListPtr params, case MSVM_CONCRETEJOB_JOBSTATE_SHUTTING_DOWN: hypervFreeObject(priv, (hypervObject *)job); job =3D NULL; - usleep(100 * 1000); /* sleep 100 ms */ + g_usleep(100 * 1000); /* sleep 100 ms */ timeout -=3D 100; continue; case MSVM_CONCRETEJOB_JOBSTATE_COMPLETED: @@ -1418,7 +1418,7 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virD= omainPtr domain, hypervFreeObject(priv, (hypervObject *)concreteJob); concreteJob =3D NULL; =20 - usleep(100 * 1000); + g_usleep(100 * 1000); continue; =20 case MSVM_CONCRETEJOB_JOBSTATE_COMPLETED: diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index a5a3a97e99..c12cb4ea0f 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -657,7 +657,7 @@ virLockDaemonClientFree(void *opaque) VIR_WARN("Failed to kill off pid %lld", (unsigned long long)priv->clientPid); } - usleep(200 * 1000); + g_usleep(200 * 1000); } } } diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index 85a23c7642..7ebd63913e 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -376,7 +376,7 @@ virLockManagerSanlockSetupLockspace(virLockManagerSanlo= ckDriverPtr driver) #else /* fall back to polling */ VIR_DEBUG("Sleeping for %dms", LOCKSPACE_SLEEP); - usleep(LOCKSPACE_SLEEP * 1000); + g_usleep(LOCKSPACE_SLEEP * 1000); #endif VIR_DEBUG("Retrying to add lockspace (left %d)", retries); goto retry; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 37851bf284..9097655b4d 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -574,7 +574,7 @@ static int virLXCControllerAppendNBDPids(virLXCControll= erPtr ctrl, while (!virFileExists(pidpath)) { /* wait for 100ms before checking again, but don't do it for ever = */ if (errno =3D=3D ENOENT && loops < 10) { - usleep(100 * 1000); + g_usleep(100 * 1000); loops++; } else { virReportSystemError(errno, diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index a69589e50c..c0bbeb09e8 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2965,7 +2965,7 @@ static int lxcFreezeContainer(virDomainObjPtr vm) * decide that the freezing has been complete only with * the state actually transit to "FROZEN". */ - usleep(check_interval * 1000); + g_usleep(check_interval * 1000); =20 r =3D virCgroupGetFreezerState(priv->cgroup, &state); =20 diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index cbdc7b1268..318b4c1653 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1095,7 +1095,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm, goto cleanup; } =20 - usleep(100*1000); + g_usleep(100*1000); retries--; } =20 diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index c05157c3ca..d10665efa3 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1034,7 +1034,7 @@ networkKillDaemon(pid_t pid, * than modifications to domains, this seems a reasonable * tradeoff in exchange for less code disruption. */ - usleep(20 * 1000); + g_usleep(20 * 1000); } VIR_WARN("Timed out waiting after SIG%s to %s process %d " "(network '%s')", diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 2af8cfdd32..c82457989e 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -1273,7 +1273,7 @@ virNWFilterSnoopRatePenalty(virNWFilterSnoopPcapConfP= tr pc, unsigned long long now; =20 if (virTimeMillisNowRaw(&now) < 0) { - usleep(PCAP_FLOOD_TIMEOUT_MS); /* 1 ms */ + g_usleep(PCAP_FLOOD_TIMEOUT_MS); /* 1 ms */ pc->penaltyTimeoutAbs =3D 0; } else { /* don't listen to the fd for 1 ms */ @@ -2010,7 +2010,7 @@ virNWFilterSnoopJoinThreads(void) while (virAtomicIntGet(&virNWFilterSnoopState.nThreads) !=3D 0) { VIR_WARN("Waiting for snooping threads to terminate: %u", virAtomicIntGet(&virNWFilterSnoopState.nThreads)); - usleep(1000 * 1000); + g_usleep(1000 * 1000); } } =20 diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index cd66e3ea7d..34b8d7fcd9 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -812,7 +812,7 @@ virNWFilterLearnThreadsTerminate(bool allowNewThreads) threadsTerminate =3D true; =20 while (virHashSize(pendingLearnReq) !=3D 0) - usleep((PKT_TIMEOUT_MS * 1000) / 3); + g_usleep((PKT_TIMEOUT_MS * 1000) / 3); =20 if (allowNewThreads) threadsTerminate =3D false; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a6facdc09b..dbc32acb5e 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1650,7 +1650,7 @@ qemuMonitorJSONStartCPUs(qemuMonitorPtr mon) =20 virJSONValueFree(reply); reply =3D NULL; - usleep(250000); + g_usleep(250000); } while (++i <=3D timeout); =20 virJSONValueFree(cmd); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3b45b2f641..c6fac01ada 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7611,7 +7611,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, retry: if ((ret =3D qemuRemoveCgroup(vm)) < 0) { if (ret =3D=3D -EBUSY && (retries++ < 5)) { - usleep(200*1000); + g_usleep(200*1000); goto retry; } VIR_WARN("Failed to remove cgroup for %s", diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 1d68803a28..31fdfa995f 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -884,7 +884,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, rc =3D qemuTPMEmulatorGetPid(cfg->swtpmStateDir, shortName, &pid); if (rc < 0) { timeout -=3D 50; - usleep(50 * 1000); + g_usleep(50 * 1000); continue; } if (rc =3D=3D 0 && pid =3D=3D (pid_t)-1) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index a469907779..bd5fa96751 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -749,7 +749,7 @@ int virNetSocketNewConnectUNIX(const char *path, daemonLaunched =3D true; } =20 - usleep(10000); + g_usleep(10000); } =20 localAddr.len =3D sizeof(localAddr.data); diff --git a/src/security/security_manager.c b/src/security/security_manage= r.c index 7c905f0785..7f187c9068 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -1349,7 +1349,7 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr = mgr ATTRIBUTE_UNUSED, if (retries && (errno =3D=3D EACCES || errno =3D=3D EAGAIN= )) { /* File is locked. Try again. */ retries--; - usleep(1000); + g_usleep(1000); continue; } else { virReportSystemError(errno, diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 6165dd43b2..be084119f4 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1940,7 +1940,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, if (virDirOpenQuiet(&dh, def->target.path) < 0) { opentries++; if (loop && errno =3D=3D ENOENT && opentries < 50) { - usleep(100 * 1000); + g_usleep(100 * 1000); goto reopen; } virReportSystemError(errno, @@ -1975,7 +1975,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, } =20 if (!direrr && loop && ++retry < 100) { - usleep(100 * 1000); + g_usleep(100 * 1000); goto retry; } =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 4f9d80666d..70d41c4ba5 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2656,7 +2656,7 @@ virCgroupKillPainfully(virCgroupPtr group) if (ret <=3D 0) break; =20 - usleep(200 * 1000); + g_usleep(200 * 1000); } VIR_DEBUG("Complete %d", ret); return ret; diff --git a/src/util/virfile.c b/src/util/virfile.c index bb844c64e5..dead335c62 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -4387,7 +4387,7 @@ virFileWaitForExists(const char *path, if (tries =3D=3D 0 || errno !=3D ENOENT) return -1; =20 - usleep(ms * 1000); + g_usleep(ms * 1000); } =20 return 0; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 5c0e9723b9..5fef0b79aa 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -2304,7 +2304,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, * wait, then upcoming operations on the VF may fail. */ while (retries-- > 0 && !virNetDevExists(linkdev)) - usleep(1000); + g_usleep(1000); } =20 if (pfDevOrig && setMACrc =3D=3D 0) { diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index e2009fd829..e9d1ce0831 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -465,7 +465,7 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) /* Parse response. */ dad =3D virNetDevIPParseDadStatus(resp, recvbuflen, addrs, count); if (dad) - usleep(1000 * 10); + g_usleep(1000 * 10); } /* Check timeout. */ if (dad) { diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index e8a9b052b6..efd81c3aa0 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -404,7 +404,7 @@ virNetDevMacVLanTapOpen(const char *ifname, tapfd[i] =3D fd; } else if (retries-- > 0) { /* may need to wait for udev to be done */ - usleep(20000); + g_usleep(20000); } else { /* However, if haven't succeeded, quit. */ virReportSystemError(errno, diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprof= ile.c index a5ecd783f2..048f891920 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -999,7 +999,7 @@ virNetDevVPortProfileOpCommon(const char *ifname, int i= findex, break; } =20 - usleep(STATUS_POLL_INTERVL_USEC); + g_usleep(STATUS_POLL_INTERVL_USEC); } =20 if (status =3D=3D PORT_PROFILE_RESPONSE_INPROGRESS) { diff --git a/src/util/virpci.c b/src/util/virpci.c index ee78151e74..9b828b7781 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -833,11 +833,11 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, virPCIDeviceWrite16(parent, parentfd, PCI_BRIDGE_CONTROL, ctl | PCI_BRIDGE_CTL_RESET); =20 - usleep(200 * 1000); /* sleep 200ms */ + g_usleep(200 * 1000); /* sleep 200ms */ =20 virPCIDeviceWrite16(parent, parentfd, PCI_BRIDGE_CONTROL, ctl); =20 - usleep(200 * 1000); /* sleep 200ms */ + g_usleep(200 * 1000); /* sleep 200ms */ =20 if (virPCIDeviceWrite(dev, cfgfd, 0, config_space, PCI_CONF_LEN) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -881,12 +881,12 @@ virPCIDeviceTryPowerManagementReset(virPCIDevicePtr d= ev, int cfgfd) virPCIDeviceWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL, ctl | PCI_PM_CTRL_STATE_D3hot); =20 - usleep(10 * 1000); /* sleep 10ms */ + g_usleep(10 * 1000); /* sleep 10ms */ =20 virPCIDeviceWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL, ctl | PCI_PM_CTRL_STATE_D0); =20 - usleep(10 * 1000); /* sleep 10ms */ + g_usleep(10 * 1000); /* sleep 10ms */ =20 if (virPCIDeviceWrite(dev, cfgfd, 0, &config_space[0], PCI_CONF_LEN) <= 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 66834d37d3..b1544af730 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -177,7 +177,7 @@ virProcessAbort(pid_t pid) } else if (ret =3D=3D 0) { VIR_DEBUG("trying SIGTERM to child process %d", pid); kill(pid, SIGTERM); - usleep(10 * 1000); + g_usleep(10 * 1000); while ((ret =3D waitpid(pid, &status, WNOHANG)) =3D=3D -1 && errno =3D=3D EINTR); if (ret =3D=3D pid) { @@ -399,7 +399,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, uns= igned int extradelay) goto cleanup; /* process is dead */ } =20 - usleep(200 * 1000); + g_usleep(200 * 1000); } =20 virReportSystemError(EBUSY, diff --git a/src/util/virtime.c b/src/util/virtime.c index 86993e4e8d..6f978d7c64 100644 --- a/src/util/virtime.c +++ b/src/util/virtime.c @@ -448,6 +448,6 @@ virTimeBackOffWait(virTimeBackOffVar *var) =20 VIR_DEBUG("sleeping for %llu ms", next); =20 - usleep(next * 1000); + g_usleep(next * 1000); return 1; } diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index d3b8fb625f..748133933c 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7932,7 +7932,7 @@ vboxDomainSendKey(virDomainPtr dom, /* since VBOX does not support holdtime, simulate it by sleeping and then sending the release key scancodes */ if (holdtime > 0) - usleep(holdtime * 1000); + g_usleep(holdtime * 1000); =20 rc =3D gVBoxAPI.UIKeyboard.PutScancodes(keyboard, nkeycodes, keyUpCode= s, &codesStored); diff --git a/tests/commandtest.c b/tests/commandtest.c index 2aaddef3d1..2ec3434f1e 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -262,7 +262,7 @@ static int test4(const void *unused ATTRIBUTE_UNUSED) goto cleanup; } while (kill(pid, 0) !=3D -1) - usleep(100*1000); + g_usleep(100*1000); =20 ret =3D checkoutput("test4", NULL); =20 @@ -751,7 +751,7 @@ static int test18(const void *unused ATTRIBUTE_UNUSED) } =20 while (kill(pid, SIGINT) !=3D -1) - usleep(100*1000); + g_usleep(100*1000); =20 ret =3D 0; =20 @@ -1052,7 +1052,7 @@ static int test25(const void *unused ATTRIBUTE_UNUSED) goto cleanup; } =20 - usleep(10 * 1000); + g_usleep(10 * 1000); } else { break; } diff --git a/tests/eventtest.c b/tests/eventtest.c index f426469d21..f04b416ad2 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -382,7 +382,7 @@ mymain(void) startJob(); pthread_mutex_unlock(&eventThreadMutex); sched_yield(); - usleep(100 * 1000); + g_usleep(100 * 1000); pthread_mutex_lock(&eventThreadMutex); virEventPollRemoveHandle(handles[1].watch); if (finishJob("Interrupted during poll", -1, -1) !=3D EXIT_SUCCESS) @@ -448,7 +448,7 @@ mymain(void) startJob(); pthread_mutex_unlock(&eventThreadMutex); sched_yield(); - usleep(100 * 1000); + g_usleep(100 * 1000); pthread_mutex_lock(&eventThreadMutex); virEventPollRemoveTimeout(timers[1].timer); if (finishJob("Interrupted during poll", -1, -1) !=3D EXIT_SUCCESS) diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c index 054c405cec..98519e6266 100644 --- a/tests/fdstreamtest.c +++ b/tests/fdstreamtest.c @@ -101,7 +101,7 @@ static int testFDStreamReadCommon(const char *scratchdi= r, bool blocking) got =3D st->driver->streamRecv(st, buf + offset, want); if (got < 0) { if (got =3D=3D -2 && !blocking) { - usleep(20 * 1000); + g_usleep(20 * 1000); goto reread; } virFilePrintf(stderr, "Failed to read stream: %s\n", @@ -222,7 +222,7 @@ static int testFDStreamWriteCommon(const char *scratchd= ir, bool blocking) got =3D st->driver->streamSend(st, pattern + offset, want); if (got < 0) { if (got =3D=3D -2 && !blocking) { - usleep(20 * 1000); + g_usleep(20 * 1000); goto rewrite; } if (i =3D=3D 9 && diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fbfdc09c0d..c2e7c2b227 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1945,7 +1945,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) break; } =20 - usleep(500 * 1000); + g_usleep(500 * 1000); } =20 /* print 100% completed */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list