From nobody Thu May 2 14:25:38 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542633494297383.2758024252679; Mon, 19 Nov 2018 05:18:14 -0800 (PST) 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 B9B4E308428D; Mon, 19 Nov 2018 13:18:09 +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 754FD65F56; Mon, 19 Nov 2018 13:18:07 +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 312B912E30; Mon, 19 Nov 2018 13:18:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAJDG3MO021180 for ; Mon, 19 Nov 2018 08:16:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id B41363781; Mon, 19 Nov 2018 13:16:03 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FAC05D9CB for ; Mon, 19 Nov 2018 13:15:57 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 6558B120027 for ; Mon, 19 Nov 2018 14:15:56 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 19 Nov 2018 14:15:54 +0100 Message-Id: <00139cb04ce3339945ce2c00d49640f14ea5eac1.1542633354.git.mkletzan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util, qemu: Fix virDoes*Exist usage 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-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.40]); Mon, 19 Nov 2018 13:18:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Since the functions only return 0 or 1, they should return bool (missed the change in the first commit). That way it's clearer that the check for non-existing group should be either "=3D=3D 0" instead. Fix this by using = proper negation instead. Signed-off-by: Martin Kletzander --- src/qemu/qemu_conf.c | 4 ++-- src/util/virutil.c | 8 ++++---- src/util/virutil.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 32da9a735184..a946b05d5d47 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -193,10 +193,10 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) if (virAsprintf(&cfg->swtpmStorageDir, "%s/lib/libvirt/swtpm", LOCALSTATEDIR) < 0) goto error; - if (virDoesUserExist("tss") !=3D 0 || + if (!virDoesUserExist("tss") || virGetUserID("tss", &cfg->swtpm_user) < 0) cfg->swtpm_user =3D 0; /* fall back to root */ - if (virDoesGroupExist("tss") !=3D 0 || + if (!virDoesGroupExist("tss") || virGetGroupID("tss", &cfg->swtpm_group) < 0) cfg->swtpm_group =3D 0; /* fall back to root */ } else { diff --git a/src/util/virutil.c b/src/util/virutil.c index c0783ecb285b..1407c026e298 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1133,7 +1133,7 @@ virGetGroupID(const char *group, gid_t *gid) /* Silently checks if User @name exists. * Returns if the user exists and fallbacks to false on error. */ -int +bool virDoesUserExist(const char *name) { return virGetUserIDByName(name, NULL, true) =3D=3D 0; @@ -1142,7 +1142,7 @@ virDoesUserExist(const char *name) /* Silently checks if Group @name exists. * Returns if the group exists and fallbacks to false on error. */ -int +bool virDoesGroupExist(const char *name) { return virGetGroupIDByName(name, NULL, true) =3D=3D 0; @@ -1243,13 +1243,13 @@ virGetGroupList(uid_t uid ATTRIBUTE_UNUSED, gid_t g= id ATTRIBUTE_UNUSED, return 0; } =20 -int +bool virDoesUserExist(const char *name ATTRIBUTE_UNUSED) { return 0; } =20 -int +bool virDoesGroupExist(const char *name ATTRIBUTE_UNUSED) { return 0; diff --git a/src/util/virutil.h b/src/util/virutil.h index 2407f54efd47..e0ab0da0f2fc 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -152,8 +152,8 @@ int virGetUserID(const char *name, int virGetGroupID(const char *name, gid_t *gid) ATTRIBUTE_RETURN_CHECK; =20 -int virDoesUserExist(const char *name); -int virDoesGroupExist(const char *name); +bool virDoesUserExist(const char *name); +bool virDoesGroupExist(const char *name); =20 =20 bool virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1); --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list