From nobody Wed Apr 24 04:48:34 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=1570468479; cv=none;
d=zoho.com; s=zohoarc;
b=DHL6CdGoEqGDs6DzLrVuxCV3NCy2uXO6KUem1RjR98jam6Ilm9SromqrFqQ2aTXmMa4xMT2HabmFVPrttKqRuyy+6a+JyLgeqi4UDcLthP3EjzICYhHXOMD6Jf4Je1iTPR0oFbq/dKkPrb9Sqz8a8XhqyYvi1wAoEh5xb1RXCxQ=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468479;
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:ARC-Authentication-Results;
bh=mtOvxvnUfeI078IPo2/p8EnkAVwaxTEu/jMWRAaAVrE=;
b=l8fIj1loyi4LzX7GrwbStxQ6sRIChHqvlvPPJWbGI3VCHX58KwWoQ46WIGW8P1ZiJF2zRC4WdAdZ8f3Ysw3WviFjfw1RCwsyGZ2/IfgKpWx+Wo+hTdn2Xfb8Gf7cXXgANyXlw3uhk689oVIrvdvDRM3r+5x7iwAyZj++r7c47Z4=
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 1570468479958930.23316085369;
Mon, 7 Oct 2019 10:14:39 -0700 (PDT)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
(No client certificate requested)
by mx1.redhat.com (Postfix) with ESMTPS id C6C8D88384C;
Mon, 7 Oct 2019 17:14:37 +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 1A3C210018FF;
Mon, 7 Oct 2019 17:14:35 +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 E37B74EE68;
Mon, 7 Oct 2019 17:14:31 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEVCp030725 for ;
Mon, 7 Oct 2019 13:14:31 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 016CC1001DE0; Mon, 7 Oct 2019 17:14: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 50CAF1001B11;
Mon, 7 Oct 2019 17:14:30 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:03 +0100
Message-Id: <20191007171425.32362-2-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Cc: Pavel Hrdina
Subject: [libvirt] [PATCH v2 01/23] 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.84 on 10.5.11.22
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]);
Mon, 07 Oct 2019 17:14:38 +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.
Reviewed-by: Pavel Hrdina
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
configure.ac | 2 ++
libvirt.spec.in | 1 +
m4/virt-glib.m4 | 36 ++++++++++++++++++++++++++++++++++++
mingw-libvirt.spec.in | 2 ++
4 files changed, 41 insertions(+)
create mode 100644 m4/virt-glib.m4
diff --git a/configure.ac b/configure.ac
index 40e93e251e..81f061f058 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
@@ -1001,6 +1002,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-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 Wed Apr 24 04:48:34 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=1570468525; cv=none;
d=zoho.com; s=zohoarc;
b=Gpsp1F2dn60UEbps9QOc1YNkfKn2ce/TnA7QIFa9KaDFkBRJvwJuGSSWbIiD/4znChJsGT3Shsjcd70X+7EEp5WnXBjO3aOT+fY2UIfeE+5TciQd0htTC8x5KvQm9iNtgx7j/MpSZ9VZpUOtHPMZNxnB0gTv1QpZVY5Abs70gT4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468525;
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:ARC-Authentication-Results;
bh=9ZQAgy1BoanAa5vYMmBIBmp7c/4ak279xfPKly4n5SU=;
b=YZFL1Cb5XlYrEkPubgaZP8s7lSwas2/+TeJx5GPx+IS/PLWPRq4ViljKypNHJwDltCfHNqsT/cch7DADlVG2WXVw/pFDOWAEpd7KEtUtsbGFZDLR0KJZ/TOtqOQO4fF/o/1SKbZHB5hAgBsEMYOyuZDS0C5lUZUMkkp76y9CJw4=
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 1570468525480451.9917042589494;
Mon, 7 Oct 2019 10:15:25 -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 F107090C87;
Mon, 7 Oct 2019 17:15:23 +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 C87685D9C9;
Mon, 7 Oct 2019 17:15:23 +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 83FF162CF7;
Mon, 7 Oct 2019 17:15:23 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEVHF030733 for ;
Mon, 7 Oct 2019 13:14:31 -0400
Received: by smtp.corp.redhat.com (Postfix)
id E7E5A1001DE0; Mon, 7 Oct 2019 17:14: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 436821001DD8;
Mon, 7 Oct 2019 17:14:31 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:04 +0100
Message-Id: <20191007171425.32362-3-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Cc: Pavel Hrdina
Subject: [libvirt] [PATCH v2 02/23] 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.79 on 10.5.11.14
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]);
Mon, 07 Oct 2019 17:15:24 +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.
Reviewed-by: Pavel Hrdina
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
docs/hacking.html.in | 21 +++++++++++++++++++++
src/Makefile.am | 2 ++
src/internal.h | 1 +
src/lxc/Makefile.inc.am | 2 ++
src/remote/Makefile.inc.am | 1 +
src/util/Makefile.inc.am | 1 +
tests/Makefile.am | 3 ++-
tools/Makefile.am | 1 +
8 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index edf2f54ce3..93b451591e 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
+
+=20
+
+ 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:
+
+
+
+
+
=20
diff --git a/src/Makefile.am b/src/Makefile.am
index bd03b09cb2..9d21395892 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) \
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/lxc/Makefile.inc.am b/src/lxc/Makefile.inc.am
index b4d560702c..0c9618e185 100644
--- a/src/lxc/Makefile.inc.am
+++ b/src/lxc/Makefile.inc.am
@@ -184,6 +184,7 @@ libvirt_lxc_LDFLAGS =3D \
$(PIE_LDFLAGS) \
$(CAPNG_LIBS) \
$(LIBXML_LIBS) \
+ $(GLIB_LIBS) \
$(NULL)
libvirt_lxc_LDADD =3D \
libvirt.la \
@@ -200,6 +201,7 @@ libvirt_lxc_CFLAGS =3D \
$(PIE_CFLAGS) \
$(CAPNG_CFLAGS) \
$(LIBXML_CFLAGS) \
+ $(GLIB_CFLAGS) \
$(LIBNL_CFLAGS) \
$(FUSE_CFLAGS) \
$(DBUS_CFLAGS) \
diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am
index 5a5c90a922..e02c20d47c 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) \
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index 9747816fac..454f8e1a8c 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -290,6 +290,7 @@ libvirt_util_la_LIBADD =3D \
$(DBUS_LIBS) \
$(WIN32_EXTRA_LIBS) \
$(LIBXML_LIBS) \
+ $(GLIB_LIBS) \
$(SECDRIVER_LIBS) \
$(NUMACTL_LIBS) \
$(ACL_LIBS) \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d88ad7f686..7b81ee88f1 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) \
@@ -525,7 +526,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..94fb4ecb8b 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 \
--=20
2.21.0
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
From nobody Wed Apr 24 04:48:34 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=1570468480; cv=none;
d=zoho.com; s=zohoarc;
b=VRuTB9zVodivGeNkZt1yxZ/zzwU/tTj36tcWNh5MDBuZJoDxpFhg54pPyWfGCAtoBqzehG4GUu+vuUU5RWbvHpF7tI5vZLgfHBUmEyPheXxNlOEV1Z4usS3VNxtkM66jXwnwhdJKpLf0tLJBFzInZbxTIIwnIFz/rsshf8tfDRM=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468480;
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:ARC-Authentication-Results;
bh=9qtGe2FYMFCIMesxuZH5CJuaQso7U11NhFIDrMjRYiI=;
b=B/UxfXxsLpkxZa9Hu+51ELLhc26JJBwFm9jEIXUrsCFK2Vc41hxe5qxhJXYGw4VgnIHtAwzMqFfPT3/7KNNbbqlB98i4McSUK140Sk8sqAGVTqmOEVED9knB0aG9MjMdEiqKlwHBxhQ9+gzlJw32sS/H5q7Ztiuy1XT5SsZicT0=
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 1570468480278391.0710017938753;
Mon, 7 Oct 2019 10:14:40 -0700 (PDT)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
(No client certificate requested)
by mx1.redhat.com (Postfix) with ESMTPS id 33CDD50F45;
Mon, 7 Oct 2019 17:14:38 +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 C5DDE10016EB;
Mon, 7 Oct 2019 17:14:37 +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 297714EE69;
Mon, 7 Oct 2019 17:14:35 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEWvh030745 for ;
Mon, 7 Oct 2019 13:14:32 -0400
Received: by smtp.corp.redhat.com (Postfix)
id B83AE1001E75; Mon, 7 Oct 2019 17:14:32 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id 34A081001B11;
Mon, 7 Oct 2019 17:14:32 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:05 +0100
Message-Id: <20191007171425.32362-4-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 03/23] 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.84 on 10.5.11.22
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]);
Mon, 07 Oct 2019 17:14:38 +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.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
bootstrap.conf | 1 -
docs/hacking.html.in | 108 ++++++-------------------------------------
src/util/viralloc.c | 29 +++---------
src/util/viralloc.h | 9 ++++
4 files changed, 28 insertions(+), 119 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index e40170a77b..b98fdedeb1 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 93b451591e..8072796312 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -990,7 +990,7 @@ BAD:
=20
-=20
+
Libvirt has adopted use of the
GLib library.
@@ -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
-
-
-
- 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;
-
-
-
-
=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 Wed Apr 24 04:48:34 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=1570468494; cv=none;
d=zoho.com; s=zohoarc;
b=fU/onfgutImzXnDuqtI4Kc6k3oyJjs5lAG6N/DybnZcKtuz4VMK8wDx03VK3GBsq0NyoDxlyg/WX9krcrznnMii1HiAf0Sa/KGtdwj4333uathGQxKTqNmrT8YuBh6HXaA9H+tKP+SWVKTU5i1h404GjlmS5T486fwpxmuPw3N4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468494;
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:ARC-Authentication-Results;
bh=0wdRXYok3zDdBNsblH4wwAHhtJNSDzomJBPD1eSPFQI=;
b=TqJpj0Os9B1HTHmrrMfL74QfZ7cduQMoUR22pocl7unzswvPcbQEnA0OR48DJl7o7xlzUojJ90+DLCc213iSEmilJUFXXzpbZJa2Ea3frh/QZsLcOlxhZbl5YJHxiV2hgNzXJv8So/MLYHWWaxhQi4+9GQBwEIzVNU1Z65XO5KY=
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 1570468494982492.10597503283316;
Mon, 7 Oct 2019 10:14:54 -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 02A2618CB8E6;
Mon, 7 Oct 2019 17:14: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 D0B1C6061E;
Mon, 7 Oct 2019 17:14:52 +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 906C518005A0;
Mon, 7 Oct 2019 17:14:52 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEXWC030755 for ;
Mon, 7 Oct 2019 13:14:33 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 8814210018FF; Mon, 7 Oct 2019 17:14:33 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id 051211001E75;
Mon, 7 Oct 2019 17:14:32 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:06 +0100
Message-Id: <20191007171425.32362-5-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 04/23] 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.13
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]);
Mon, 07 Oct 2019 17:14:53 +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.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 b98fdedeb1..7105ae2eeb 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -82,8 +82,6 @@ snprintf
socket
stat-time
strchrnul
-strdup-posix
-strndup
strerror
strerror_r-posix
strptime
@@ -99,7 +97,6 @@ uname
unsetenv
useless-if-before-free
usleep
-vasprintf
verify
vc-list-files
vsnprintf
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index 8072796312..5839464e99 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 can be used,
+ but beware that they don't abort on OOM, so the libvirt wrappers
+ may still be desirable to use. Don't use g_vasprintf or g_asprintf=
.
=20
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 Wed Apr 24 04:48:34 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=1570468529; cv=none;
d=zoho.com; s=zohoarc;
b=bhbMcT3BV+wd/yMWy0Ff7iEvA07CD9bB6nm3HWK7R9CKrTWRFUNS6blMl+gtfl7JoXRsLhEL7Mhb0CifYRbcxus4ELd0BgXx2pAeSK6Q1h3ZTexeL4GhQcOxauRl63GmWxNSsgX9uEU3nhOaF3vhLvZJ0ZEFsNWoVD7pZaSXmVU=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468529;
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:ARC-Authentication-Results;
bh=pUJFipj1wVR5kuSPk54hWPZYrQzfV5/7HvL7LA9Sgj8=;
b=F2u7FUXfwJJMSFm7YrikCdgHhl74Q+5Q7TNVMGqFtVpCyT88pk+3QdxcihGlnV9pCFdlmJbZF2DUThpwmP/GpT0LpW4bW5iL1dz1jqhFrPI98BXvn/mclF07dCJFbyx4XmbsGVtjS/7bpHKSksJpXAWUu045ksclQ0xBIW0QsTc=
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 157046852981318.884114629092437;
Mon, 7 Oct 2019 10:15:29 -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 DA04E300BC7F;
Mon, 7 Oct 2019 17:15:27 +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 AF7E760C5E;
Mon, 7 Oct 2019 17:15:27 +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 4F61C180BA9F;
Mon, 7 Oct 2019 17:15:27 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEYKS030762 for ;
Mon, 7 Oct 2019 13:14:34 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 58EB41001DD8; Mon, 7 Oct 2019 17:14: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 C86F710016EB;
Mon, 7 Oct 2019 17:14:33 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:07 +0100
Message-Id: <20191007171425.32362-6-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 05/23] 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.12
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]);
Mon, 07 Oct 2019 17:15:28 +0000 (UTC)
Using the standard macro will facilitate the conversion to glib's
auto cleanup macros.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 Wed Apr 24 04:48:34 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=1570468499; cv=none;
d=zoho.com; s=zohoarc;
b=ceMYfPfNqW44NSQt70p0vNWWNTAkcmeeT75P2Z0BxPo5FY8tadbBU44y7WOxUxpq5fbEVhIIx6OQBQYbekOcbKLgc6gHIIg/JOjRvbC+LyUtzgqOrjVO6MjSlJnwlnzB7yTP2pLi5Jbi7mpKZNQEJCdXuARkDglGfuTxxKQ7ywM=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468499;
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:ARC-Authentication-Results;
bh=f75woDLjkFoYK1lNh5O9y2P/BtW29VmZOuI5rL1eQgs=;
b=dwFo2ix3nq/WiB3NTNz8twGQ0fVD3gRsdkabDdoS5DcwQqHP2AhMkGDQaIGpGsLwm1qvyygIfRp0SVuUjxTrVJzj+UCN7sfFrYyfDuI8I/qN93raL8xCd27F0kWdWvYzcnId4dvbEdiyIKrEk0RUDhdfmn2wzKtG4qhaXqrGy54=
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 1570468499745669.0113122803062;
Mon, 7 Oct 2019 10:14:59 -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 81C6AC057F88;
Mon, 7 Oct 2019 17:14:57 +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 5B00E5C224;
Mon, 7 Oct 2019 17:14:57 +0000 (UTC)
Received: from lists01.pubmisc.prod.ext.phx2.redhat.com
(lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33])
by colo-mx.corp.redhat.com (Postfix) with ESMTP id 07629180B761;
Mon, 7 Oct 2019 17:14:57 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEZFt030769 for ;
Mon, 7 Oct 2019 13:14:35 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 2B8971001DD8; Mon, 7 Oct 2019 17:14:35 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id 9B4E210018FF;
Mon, 7 Oct 2019 17:14:34 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:08 +0100
Message-Id: <20191007171425.32362-7-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 06/23] 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.16
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]);
Mon, 07 Oct 2019 17:14:58 +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.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
cfg.mk | 2 +-
docs/hacking.html.in | 18 ++++++++++++++++++
src/util/viralloc.h | 5 ++++-
src/util/virautoclean.h | 38 ++++++++++++++++++++------------------
4 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 3eae469165..7319a14d19 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1061,7 +1061,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 5839464e99..40a3c60573 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 can be used,
but beware that they don't abort on OOM, so the libvirt wrappers
may still be desirable to use. Don't use g_vasprintf or g_asprintf=
.
+
+ 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 vica-verca.
+
=20
diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index 517f9aada6..f81ea42902 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..d7c1c1ec8b 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 vica-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 Wed Apr 24 04:48:34 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=1570468533; cv=none;
d=zoho.com; s=zohoarc;
b=Mv90r4ruAMlcICpMyOza74mn98s7pV5kqOIO56isvTjpi+CHcrgqrDjEXvEOktm3XKnnHjEEh6OieGAm2UijKF8W1LL3vqEo+yINPePtuBMEPPw2gtqwsIeHVY/pKiy7A3b6zlHJHxYVdDO7SARLMv0mtDOJId00p5bGWxWUfZc=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468533;
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:ARC-Authentication-Results;
bh=T2a7+eaKoZBH0kExK/kdfxtObb7xg9SPWhFOIjuCDNE=;
b=MCHgIESXm5qIktd8r2M0+pniWJVrNDKDOuj3NXPyIoDfZI2ULKXqOv8GqsFiuAkruagNGCOrT1t666dTxU1SYvQ9fTaVr8kZWOwgtuoQkioGUfn+sLIdgXF20bVAg/mjEgxpWdTCa5ao9/OzS45Rx54Gj9TmGWJOROOrRIPdTVc=
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 1570468533204428.1646002921166;
Mon, 7 Oct 2019 10:15:33 -0700 (PDT)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
(No client certificate requested)
by mx1.redhat.com (Postfix) with ESMTPS id 91F1A64D28;
Mon, 7 Oct 2019 17:15:31 +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 691071001B28;
Mon, 7 Oct 2019 17:15:31 +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 2603C62D11;
Mon, 7 Oct 2019 17:15:31 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEZg4030774 for ;
Mon, 7 Oct 2019 13:14:36 -0400
Received: by smtp.corp.redhat.com (Postfix)
id EF7A510018FF; Mon, 7 Oct 2019 17:14:35 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id 6BE0F1001B11;
Mon, 7 Oct 2019 17:14:35 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:09 +0100
Message-Id: <20191007171425.32362-8-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 07/23] 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.84 on 10.5.11.22
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]);
Mon, 07 Oct 2019 17:15:32 +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.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 40a3c60573..0d04270699 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 vica-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
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 2884af49d8..db4de1a7f5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2592,6 +2592,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 72da3691f2..a1045b436e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -533,6 +533,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 Wed Apr 24 04:48:34 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=1570468502; cv=none;
d=zoho.com; s=zohoarc;
b=C/OvHkHk7mZvVFg7RHdrEg2g+OR0OAvyGC7+qmXz26gFtmyleMeUf93qfA9mIMtOH+fF2dRUc/K+qQKo7AUTCXyLqKpfHBQUvwakFLIvy3/BM2IYVK2n65XixyZMvlJWXfgaaBvR+aVRsq8J0LUpIB3Cfz2y/5ckSyh7nB4wVbk=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468502;
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:ARC-Authentication-Results;
bh=oo4X+Es2ouHySBksPcvtZ7cinZ9NV3hMS+NHXaJdSww=;
b=AKaQjitWkJk7Oupcl8daplJqJpawof1YwzLFJhztvbNerbt7LjKcMavQl+8ZE1Y99UufLRN6sXcOMBLgIsl+MASnZad1PVA+fvZoE89MtGLGXgV1Yx61rudRkpeDg3dxBsKRv0EORJHtvKU/z/iSew7BH+zhtU2ZvZy89M/eAgM=
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 1570468502844248.44767445375828;
Mon, 7 Oct 2019 10:15:02 -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 ED15010DCC8A;
Mon, 7 Oct 2019 17:15:00 +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 C133860A9F;
Mon, 7 Oct 2019 17:15:00 +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 7F85F4EE70;
Mon, 7 Oct 2019 17:15:00 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEadf030788 for ;
Mon, 7 Oct 2019 13:14:36 -0400
Received: by smtp.corp.redhat.com (Postfix)
id C40BE100EBA4; Mon, 7 Oct 2019 17:14:36 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id 3C4811001B28;
Mon, 7 Oct 2019 17:14:36 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:10 +0100
Message-Id: <20191007171425.32362-9-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 08/23] 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.13
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]);
Mon, 07 Oct 2019 17:15:01 +0000 (UTC)
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 Wed Apr 24 04:48:34 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=1570468499; cv=none;
d=zoho.com; s=zohoarc;
b=YwA4ztFtzFK/YI8sxw/3SP16jyUQiBKJxwzzQZJoWDH+j8QJd2rZyNaqd8xmqOxR9O00hYSXO2gkGmWvLMZb0tnQWe16zd8b1DgchZ9uiTa3Y7DT/WBhL7dhuxWSrLyBhnFHX+O2TkwttLL6hlSblQncKpULzX5SWpuoALvE90Q=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468499;
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:ARC-Authentication-Results;
bh=QDOOT/UCTS1LbiPodt3KuS3tmJ/rvUlnqNpW8XCGnWY=;
b=HLulYjyaeDZkkrnd19mbWr0TE9Dk9XsvI3GVTGdUhj8ygSS8H9UfXBTcyQ04v9k2SpKudO6Dsdlz1w67UUz0+56kmggAzQEOgS1/Bg7EKvxuzI2nJMmV0LjgxlPNwV7R9kUVfhq9uI78tYPCWIGFfh8zNTAN1nj5W3DkjGqMXkA=
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 1570468499084877.7529189256796;
Mon, 7 Oct 2019 10:14:59 -0700 (PDT)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
(No client certificate requested)
by mx1.redhat.com (Postfix) with ESMTPS id BCACD88D316;
Mon, 7 Oct 2019 17:14:56 +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 89CEE10016EB;
Mon, 7 Oct 2019 17:14:56 +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 4DDE94EE50;
Mon, 7 Oct 2019 17:14:56 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEbKC030805 for ;
Mon, 7 Oct 2019 13:14:37 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 9573C1001B11; Mon, 7 Oct 2019 17:14:37 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id 11D8E10016EB;
Mon, 7 Oct 2019 17:14:36 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:11 +0100
Message-Id: <20191007171425.32362-10-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 09/23] 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.84 on 10.5.11.22
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]);
Mon, 07 Oct 2019 17:14:58 +0000 (UTC)
Replace use of the gnulib base64 module with glib's own base64 API family.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 7105ae2eeb..acb0e25a37 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 81f061f058..1782665835 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])
-
AC_CONFIG_FILES([run],
[chmod +x,-w run])
AC_CONFIG_FILES([\
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 eeab820eca..b27b20ecd0 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 cbf25d5f07..f3151caefd 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -834,9 +834,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 b4175a846e..1186eb61af 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 Wed Apr 24 04:48:34 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=1570468536; cv=none;
d=zoho.com; s=zohoarc;
b=HTVBrXLihJlq9qGjSerNYtM5hnceFbUdGSXfsSF+qD6xozHGSXmNyTcRco5N3f9WSrMQ5tf25m8Wmvaeo3D3xANBYDRiUeP1mnwm+7v8z+wHanhTJH+7i6zOUnNzkcLIiGb6ZaVL/mYH0BSwPzHSepJNEGZ+sY0RnV/Hk3nQr7c=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468536;
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:ARC-Authentication-Results;
bh=E5IckZIfXhaRNLOw35DxzG6QbDno/pLQlCsovJEYit0=;
b=XG5Ls05WQrrppFVYG4gKRhrgNps5QloGG7HqQZ4No+kztUBmC5PI+BpaV/L7vFcbFj73y3MIyuSkm4e/eW5bBq81yGqcfE/+I4Z+SzDoirC9sqWCkHgCf+3oZXORIUJUamcxlf/DbdgfdwMMS2UE0bKNUaHoSIS4uNQCkzYoL1M=
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 1570468536595845.1292516207787;
Mon, 7 Oct 2019 10:15: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 11CA0307BCC5;
Mon, 7 Oct 2019 17:15:35 +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 DE523A226;
Mon, 7 Oct 2019 17:15: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 9B1CA6B4B1;
Mon, 7 Oct 2019 17:15:34 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEcIM030811 for ;
Mon, 7 Oct 2019 13:14:38 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 67B3D1001B28; Mon, 7 Oct 2019 17:14: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 D664C1001B11;
Mon, 7 Oct 2019 17:14:37 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:12 +0100
Message-Id: <20191007171425.32362-11-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 10/23] 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.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.49]);
Mon, 07 Oct 2019 17:15:35 +0000 (UTC)
To simplify the later conversion from virObject to GObject, introduce
the use of g_autoptr to the virIdentity implementnation and test suite.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
src/util/viridentity.c | 40 +++++++++++++++----------------------
tests/viridentitytest.c | 44 +++++++++++++++++------------------------
2 files changed, 34 insertions(+), 50 deletions(-)
diff --git a/src/util/viridentity.c b/src/util/viridentity.c
index 22e2644c19..a24704b690 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,54 @@ 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;
-#if WITH_SELINUX
- security_context_t con;
-#endif
+ g_autoptr(virIdentity) ret =3D NULL;
=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) {
+ security_context_t con;
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 Wed Apr 24 04:48:34 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=1570468540; cv=none;
d=zoho.com; s=zohoarc;
b=JczTto24Qqacfcyh5eqaEdGD3N9FGDU9dtJq+FU1FemLF15d1kTdXBsLmDT9HK8Y2D2s+HpBsujvbyGSVMLGNHANqO5x1vGGaRQ7fm6OxQgazipMpXZ7laBS+Xer/2Gl/kh1TQqmERxWEW7vBPh8lljUjKs4Ei56DjJf89YmxKM=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468540;
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:ARC-Authentication-Results;
bh=VjPlDMKNXlstwTDmJf/Ronmu82gecefZa3PELF3OEso=;
b=RQ6avyM/adaMvc69IOA/pgJ4aLF4eJgSRzDHO74oY7if89OF4IZsAICi67S0IaGJ/224a23KgefZKU5dv5eZwGzvuurFviwCA5Ld+ZT4j7K8ISxk0hhKOYq0P8r8FEp2q2ccLogGoOlBbyL7rH+w1hJs/wgTM0eDob13c85uzcI=
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 1570468540061639.5584267248514;
Mon, 7 Oct 2019 10:15:40 -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 807EB8770C;
Mon, 7 Oct 2019 17:15:38 +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 578DD5D70E;
Mon, 7 Oct 2019 17:15:38 +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 1E988180B536;
Mon, 7 Oct 2019 17:15:38 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEdfX030824 for ;
Mon, 7 Oct 2019 13:14:39 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 38BD81001B11; Mon, 7 Oct 2019 17:14: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 A857710018FF;
Mon, 7 Oct 2019 17:14:38 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:13 +0100
Message-Id: <20191007171425.32362-12-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 11/23] 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.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.71]);
Mon, 07 Oct 2019 17:15:39 +0000 (UTC)
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 Wed Apr 24 04:48:34 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=1570468503; cv=none;
d=zoho.com; s=zohoarc;
b=Zq6NzCAP8Leaesgrvtz32Kr3iqX4In0zk9rv0QiVm0wi92o0WzGxqokct8S1v2AkLFNfHtYWAswXErB5jTLKLedrtAGBH0aKTAQARq8sTfNrkkAe/SVnl/xLiZ5kVq8wO62JEyoClm8ZwmXaP+Zi+TW2me0NW7HFRIyhGcRuF8Y=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468503;
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:ARC-Authentication-Results;
bh=AUMOMRS79PqkriG5GQx/mNCRP7j/pQKfnoVZCtqWOSY=;
b=V/EM+RhUDuvp66wM0LEkQWBV7ZQKA28zP0iCEOaUdds4PnpRsiWc0hWaLy+a+I3Wy0apJ0EaC47W3SOozn0JMePYuH5XshMnsJR8gu13C8154Ur6+E+3NPZ5q00JsR2tBDNk7d2cZpc8CxvTMevYYGqQf3lb57JkuXYmDULfN6g=
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 1570468503339589.7220712537928;
Mon, 7 Oct 2019 10:15:03 -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 13E5F757C5;
Mon, 7 Oct 2019 17:15:01 +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 DBF77194B9;
Mon, 7 Oct 2019 17:15:00 +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 92B444EE6D;
Mon, 7 Oct 2019 17:15:00 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEede030836 for ;
Mon, 7 Oct 2019 13:14:40 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 0A80B1001B28; Mon, 7 Oct 2019 17:14: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 796001001B11;
Mon, 7 Oct 2019 17:14:39 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:14 +0100
Message-Id: <20191007171425.32362-13-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 12/23] 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.26]);
Mon, 07 Oct 2019 17:15:02 +0000 (UTC)
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 Wed Apr 24 04:48:34 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=1570468509; cv=none;
d=zoho.com; s=zohoarc;
b=akZrcfZMF9nU6yykkw4f7OQEwfYLBivyoJ1F/inamebx2QAgZYoMpgEacVADSCpaWBkhmp3ECt4WYTn5/U7gJ5kTXK3xiVI8yeSTW4PY7HNRmWX64TBe7t5B4IQPO/jNf2iMwFrQ/oeAEu+PQigS8yOtwb1BNRByaYKzLExDWVo=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468509;
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:ARC-Authentication-Results;
bh=xMEhLe5WL0c4/OVGIEjua1DTY40NnyE8sKczXErr0FQ=;
b=O9Si5LvDv70e3SVIDGQnTHHsI7Ie9CGrcHE2ltlk+g06+kJ0GfOgz9tV/fBhcok6T+NPOHtE+ny52PhjMbfQyfHGY0cQtPdbAMcbkR8nLBFsFiTXKVpVVN4TgOEAJSXH6Ood7c56RMtp1kClV6lWN9oN3onIOijvmpfXqCDnr2M=
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 1570468509782386.3983848884038;
Mon, 7 Oct 2019 10:15:09 -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 ECDB68553B;
Mon, 7 Oct 2019 17:15:06 +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 A986B5D9C9;
Mon, 7 Oct 2019 17:15:06 +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 44F661803B4D;
Mon, 7 Oct 2019 17:15:06 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEe5H030844 for ;
Mon, 7 Oct 2019 13:14:40 -0400
Received: by smtp.corp.redhat.com (Postfix)
id D18FF10016EB; Mon, 7 Oct 2019 17:14: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 4D33E1001DD8;
Mon, 7 Oct 2019 17:14:40 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:15 +0100
Message-Id: <20191007171425.32362-14-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 13/23] 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.14
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]);
Mon, 07 Oct 2019 17:15:08 +0000 (UTC)
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 Wed Apr 24 04:48:34 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=1570468515; cv=none;
d=zoho.com; s=zohoarc;
b=nd7OS4LMuLevo3H/43PgyFaOKs4Qdf5GAlZPFXM+lm12Bh1tGsvsWocAt9rIeTIMaRUsdMo/942V4P5lClIzNEGQKoNcpLwflqM157bsT1Hp26V1EXkcqTlF0rJ2AuW/SdN6+vh9SNGQXvrYui3/SwXMg/h2hT7/tZVBmN9ENBc=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468515;
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:ARC-Authentication-Results;
bh=Qx6AT93rRfOM77/ZNNNHzuxelZ799IXppFvOikff6AU=;
b=TnF7Pv/OXTDgpfyyhpoTJc3atVfvW/Q6ShkangwaQIMRadeDoAo7SWBflOvzZwK4m49fBIQ3gXwMQ2ZCPUFBf2h4eLHDxdbzkUmj5+6TpZ3566wSR09oxvXIyZGc/1bDIUebdvkXpKok8bDNexy+lFvwgRL+Bh8iSadZDSxDZmk=
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 157046851533124.384565464929324;
Mon, 7 Oct 2019 10:15:15 -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 2741D87700;
Mon, 7 Oct 2019 17:15:13 +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 EE2C25ED21;
Mon, 7 Oct 2019 17:15:12 +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 993C24EE97;
Mon, 7 Oct 2019 17:15:12 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEfGf030861 for ;
Mon, 7 Oct 2019 13:14:41 -0400
Received: by smtp.corp.redhat.com (Postfix)
id A23831001B11; Mon, 7 Oct 2019 17:14: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 1EA8710016EB;
Mon, 7 Oct 2019 17:14:40 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:16 +0100
Message-Id: <20191007171425.32362-15-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 14/23] 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.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.71]);
Mon, 07 Oct 2019 17:15:13 +0000 (UTC)
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 Wed Apr 24 04:48:34 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=1570468519; cv=none;
d=zoho.com; s=zohoarc;
b=gwgBFw/99TSw4Z0579P2ErCjdCbVlf9uU+p4YjN3VM6WuGXSw52T/dJE808xqRsag73K9fj+Tub1R/AXYtXnydx5Rx87NvLIYn/ewPli9AR0xTvqW4PrS9A0n1CmzAma+gKxfnbDUbApXtXvUSfnKeHrWaTvbS+GtaFY12sSs8M=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468519;
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:ARC-Authentication-Results;
bh=M8qm/dgC9QE9TP7FRN0nxs+2jG4YQHpSmc7FLzeMQvA=;
b=RktLpyjHOMinRJeZip9QePf6RIdgKR7Co+dItXsOWasckaZfeSIDShxfX9Sw68q2K8GxOtKDmi/9zCnAObe5x9sWnW4FqTJCs783xCbtNo9uiFYQC5f0OAjzo7h81Uo4sBq2Xx80Dd9DZUGr0HZxkJMFumuufU47OH30k3iscXc=
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 1570468519705421.59412488803423;
Mon, 7 Oct 2019 10:15:19 -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 B869712E5;
Mon, 7 Oct 2019 17:15:17 +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 85D40614C1;
Mon, 7 Oct 2019 17:15:17 +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 2C9474EEBA;
Mon, 7 Oct 2019 17:15:17 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEg61030866 for ;
Mon, 7 Oct 2019 13:14:42 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 73D671001B28; Mon, 7 Oct 2019 17:14: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 E3BC510018FF;
Mon, 7 Oct 2019 17:14:41 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:17 +0100
Message-Id: <20191007171425.32362-16-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 15/23] 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.13
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]);
Mon, 07 Oct 2019 17:15:18 +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, virIdentity, VIR, IDENTITY, GObject=
);
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, virIdentity, 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.
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
m4/virt-glib.m4 | 4 +--
src/qemu/qemu_process.c | 4 +--
src/rpc/virnetserverclient.c | 10 +++----
src/util/viridentity.c | 57 ++++++++++++++++++++++--------------
src/util/viridentity.h | 9 +++---
tests/viridentitytest.c | 5 +---
6 files changed, 50 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 a50cd54393..872750ff4d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8051,7 +8051,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);
@@ -8364,7 +8364,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 a24704b690..c6299a6b09 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, virIdentity, 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 virIdentity_init(virIdentity *ident G_GNUC_UNUSED)
+{
+}
+
+static void virIdentity_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
@@ -195,26 +213,21 @@ 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(virIdentity_parent_class)->finalize(object);
}
=20
=20
+
/*
* Returns: 0 if not present, 1 if present, -1 on error
*/
diff --git a/src/util/viridentity.h b/src/util/viridentity.h
index 7513dd4e35..df658ea844 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 virIdentity_get_type()
+G_DECLARE_FINAL_TYPE(virIdentity, virIdentity, 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 Wed Apr 24 04:48:34 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=1570468543; cv=none;
d=zoho.com; s=zohoarc;
b=G+KOKbdofBA4xnOMH7BivkiqyhodiGKQgdprfmSs/4SmoD9OrCM2T95IU8mrig0pQ005PkcceJbopuYzzhRCKjzifgpx6nEjywbZYigoZbdu+AgAP9dsMPD2Rm0UVPoxwYifGAD8d5FQWYzXb9XJqzV8Xub/yC/kHiFIuNDoB+I=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468543;
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:ARC-Authentication-Results;
bh=nwD50n0NpibizD6wctXW4myyOsgSSNrFYqLZvhLY1cA=;
b=CR00u8VIyHuWxKB4lkWvUajcU6y9NHtJ/VcJBCBOc+cG3Mg/0WcH6eY5ddILo7QLW7tW2NlITBRn9QrbmVOVZpyI+wq4mkqJ5LcUmPEYFqICnmyrHfZ3+LHnU9/2cjdlRbtnS21fu8B8xty5DEkszS22HpUn2/QQluUgG8msrYE=
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 1570468543626588.3826032781046;
Mon, 7 Oct 2019 10:15:43 -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 144C0970D7;
Mon, 7 Oct 2019 17:15:42 +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 DEB3B5D9C9;
Mon, 7 Oct 2019 17:15:41 +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 970322551B;
Mon, 7 Oct 2019 17:15:41 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEhqi030881 for ;
Mon, 7 Oct 2019 13:14:43 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 65EEC1001B11; Mon, 7 Oct 2019 17:14:43 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id B4FCC10016EB;
Mon, 7 Oct 2019 17:14:42 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:18 +0100
Message-Id: <20191007171425.32362-17-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Cc: Pavel Hrdina
Subject: [libvirt] [PATCH v2 16/23] 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.14
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]);
Mon, 07 Oct 2019 17:15:42 +0000 (UTC)
Reviewed-by: Pavel Hrdina
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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 Wed Apr 24 04:48:34 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=1570468547; cv=none;
d=zoho.com; s=zohoarc;
b=heLMOS1270SsDwVXCjthYOADVY/BZdZvdpNZk7Jh257TRtYVa15bwDFz7OibkzpFPD5IFlG7GBmJkST7KXcMS+mEzFtHmytCQm7wff0cNHL1yK9eeS8QGhoYbQdSfGQxjjLQUfqZ0qNOOzYTFk6snD5CJJq+WqlWnaqjZLIa2lY=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468547;
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:ARC-Authentication-Results;
bh=4g5b2ujFT7FT0mcFUkA+qb0tf2RDO9I7aIyWa8D4zJE=;
b=gHJsskF7G2oq58Wz4mmzdHOmr+wr4PzRBlGmLoPFymMp9l9k8u1QTVaGucRPwrmD9XhdH/pSorvQMUUhpdA3eJsgiUyMQ+si9Sw92BKMXb7DG1qLoL7I7eGoy2Px+65KxUISCDmRQCXDqVwvABx36rBALmJPpAKtNRlf5rxrwgs=
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 157046854704317.06779869413515;
Mon, 7 Oct 2019 10:15:47 -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 7602A18CB8E6;
Mon, 7 Oct 2019 17:15:45 +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 51E9560166;
Mon, 7 Oct 2019 17:15:45 +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 08E5124FDF;
Mon, 7 Oct 2019 17:15:45 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEiPt030887 for ;
Mon, 7 Oct 2019 13:14:44 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 581891001B28; Mon, 7 Oct 2019 17:14:44 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id A849510016EB;
Mon, 7 Oct 2019 17:14:43 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:19 +0100
Message-Id: <20191007171425.32362-18-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Cc: Pavel Hrdina
Subject: [libvirt] [PATCH v2 17/23] 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.11
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]);
Mon, 07 Oct 2019 17:15:46 +0000 (UTC)
Reviewed-by: Pavel Hrdina
Signed-off-by: Daniel P. Berrang=C3=A9
Reviewed-by: J=C3=A1n Tomko
---
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..f7d1a38e46 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 0;
+ 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 Wed Apr 24 04:48:34 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=1570468523; cv=none;
d=zoho.com; s=zohoarc;
b=B2fXAnzotY6XsGaAJ5ieVgWlGKgq59IRblLUcPCLVxdBJdTcNtcL36ojBpid9XbJ3pBecue4WXgKwPPRHv3KEllBr6SzvxymVbkr7qbkF6uZ/eu1j3cg34dpWHztsXcqk08ITw4XAA+8bWt6LCTsY6xgIsAUpll25sBlvcQ8tiE=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com;
s=zohoarc;
t=1570468523;
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:ARC-Authentication-Results;
bh=SQZ0Ra2RVeTJsXFp1rnx6NmIAF4dKa9pwoOr5iYGZRg=;
b=iDIs99fNxgueJObMt/It3x+DeNTwoL1EcL2z+yZnS7QXpksqPUoIzJWv7K97Er260aQsOmGWTZWGFhdqMUW6DmS1VnKzU9d3NpS4GY5Fd2Rinx3q5kNO2Cb9syHzWsxqRn+9L5f+gNJpWOxTtaaR48NAJzU9f1aIKO4+P1Dvgmg=
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 1570468523925375.74476824324404;
Mon, 7 Oct 2019 10:15:23 -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 4280D87705;
Mon, 7 Oct 2019 17:15:22 +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 19D5660C4B;
Mon, 7 Oct 2019 17:15: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 B872CC592;
Mon, 7 Oct 2019 17:15:21 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com
[10.5.11.22])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id x97HEjP4030898 for ;
Mon, 7 Oct 2019 13:14:45 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 2CA431001B28; Mon, 7 Oct 2019 17:14:45 +0000 (UTC)
Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231])
by smtp.corp.redhat.com (Postfix) with ESMTP id 9AAF810018FF;
Mon, 7 Oct 2019 17:14:44 +0000 (UTC)
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?=
To: libvir-list@redhat.com
Date: Mon, 7 Oct 2019 18:14:20 +0100
Message-Id: <20191007171425.32362-19-berrange@redhat.com>
In-Reply-To: <20191007171425.32362-1-berrange@redhat.com>
References: <20191007171425.32362-1-berrange@redhat.com>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH v2 18/23] virsh: convert command line parsing to
use GOptionContext
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.6.2 (mx1.redhat.com [10.5.110.71]);
Mon, 07 Oct 2019 17:15:22 +0000 (UTC)
The GOptionContext API has the benefit over getopt_long that it will
automatically handle --help output formatting.
Signed-off-by: Daniel P. Berrang=C3=A9
---
tools/virsh.c | 304 +++++++++++++++++++++++---------------------------
1 file changed, 137 insertions(+), 167 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index ec20f35a77..49aca96a8d 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -23,7 +23,6 @@
=20
#include
#include
-#include
#include
#include
#include
@@ -445,53 +444,36 @@ virshDeinit(vshControl *ctl)
}
=20
/*
- * Print usage
+ * Build help description for commands
*/
-static void
-virshUsage(void)
+static char *
+virshBuildDescription(void)
{
const vshCmdGrp *grp;
const vshCmdDef *cmd;
-
- fprintf(stdout, _("\n%s [options]... []"
- "\n%s [options]... [args...]\n\n"
- " options:\n"
- " -c | --connect=3DURI hypervisor connection=
URI\n"
- " -d | --debug=3DNUM debug level [0-4]\n"
- " -e | --escape set escape sequence for=
console\n"
- " -h | --help this help\n"
- " -k | --keepalive-interval=3DNUM\n"
- " keepalive interval in s=
econds, 0 for disable\n"
- " -K | --keepalive-count=3DNUM\n"
- " number of possible miss=
ed keepalive messages\n"
- " -l | --log=3DFILE output logging to fil=
e\n"
- " -q | --quiet quiet mode\n"
- " -r | --readonly connect readonly\n"
- " -t | --timing print timing informatio=
n\n"
- " -v short version\n"
- " -V long version\n"
- " --version[=3DTYPE] version, TYPE is shor=
t or long (default short)\n"
- " commands (non interactive mode):\n\n"), progname,
- progname);
+ GString *str =3D g_string_new("Commands (non interactive mode):\n\n");
=20
for (grp =3D cmdGroups; grp->name; grp++) {
- fprintf(stdout, _(" %s (help keyword '%s')\n"),
- grp->name, grp->keyword);
+ g_string_append_printf(str,
+ _(" %s (help keyword '%s')\n"),
+ grp->name, grp->keyword);
for (cmd =3D grp->commands; cmd->name; cmd++) {
if (cmd->flags & VSH_CMD_FLAG_ALIAS)
continue;
- fprintf(stdout,
- " %-30s %s\n", cmd->name,
- _(vshCmddefGetInfo(cmd, "help")));
+ g_string_append_printf(str,
+ " %-30s %s\n",
+ cmd->name,
+ _(vshCmddefGetInfo(cmd, "help")));
}
- fprintf(stdout, "\n");
+ g_string_append_printf(str, "\n");
}
=20
- fprintf(stdout, "%s",
- _("\n (specify help for details about the commands in=
the group)\n"));
- fprintf(stdout, "%s",
- _("\n (specify help for details about the command)\=
n\n"));
- return;
+ g_string_append_printf(str,
+ _("Specify help