Re: [PATCH v2 10/23] util: convert virIdentity implementation and test suite to g_autoptr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 07, 2019 at 06:14:12PM +0100, Daniel P. Berrangé wrote:
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é <berrange@xxxxxxxxxx>
---
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 = NULL;

    if (virIdentityInitialize() < 0)
        return -1;
@@ -120,8 +120,6 @@ int virIdentitySetCurrent(virIdentityPtr ident)
        return -1;
    }

-    virObjectUnref(old);
-
    return 0;
}

@@ -136,60 +134,54 @@ int virIdentitySetCurrent(virIdentityPtr ident)
 */
virIdentityPtr virIdentityGetSystem(void)
{
-    VIR_AUTOFREE(char *) username = NULL;
-    VIR_AUTOFREE(char *) groupname = NULL;
+    g_autofree char *username = NULL;
+    g_autofree char *groupname = NULL;
    unsigned long long startTime;
-    virIdentityPtr ret = NULL;

-#if WITH_SELINUX
-    security_context_t con;
-#endif

Unrelated change.

+    g_autoptr(virIdentity) ret = NULL;

    if (!(ret = virIdentityNew()))
-        goto error;
+        return NULL;

    if (virIdentitySetProcessID(ret, getpid()) < 0)
-        goto error;
+        return NULL;

    if (virProcessGetStartTime(getpid(), &startTime) < 0)
-        goto error;
+        return NULL;
    if (startTime != 0 &&
        virIdentitySetProcessTime(ret, startTime) < 0)
-        goto error;
+        return NULL;

    if (!(username = virGetUserName(geteuid())))
        return ret;
    if (virIdentitySetUserName(ret, username) < 0)
-        goto error;
+        return NULL;
    if (virIdentitySetUNIXUserID(ret, getuid()) < 0)
-        goto error;
+        return NULL;

    if (!(groupname = virGetGroupName(getegid())))
        return ret;
    if (virIdentitySetGroupName(ret, groupname) < 0)
-        goto error;
+        return NULL;
    if (virIdentitySetUNIXGroupID(ret, getgid()) < 0)
-        goto error;
+        return NULL;

#if WITH_SELINUX
    if (is_selinux_enabled() > 0) {
+        security_context_t con;
        if (getcon(&con) < 0) {
            virReportSystemError(errno, "%s",
                                 _("Unable to lookup SELinux process context"));
-            return ret;

Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx>

Jano

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux