]> git.ipfire.org Git - pakfire.git/commitdiff
pwd: Remove legacy logger
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Jan 2024 18:45:16 +0000 (18:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Jan 2024 18:45:16 +0000 (18:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pwd.c

index 4b40ad4308e6d690ace0b3a97a5202044b1148f0..6478e431eefe47b93c49d0bb7a9754b36fa08cec 100644 (file)
@@ -29,9 +29,7 @@
 #include <shadow/subid.h>
 #endif
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
+#include <pakfire/ctx.h>
 #include <pakfire/logging.h>
 #include <pakfire/pakfire.h>
 #include <pakfire/pwd.h>
@@ -173,14 +171,17 @@ static int pakfire_getsubid(struct pakfire* pakfire, const char* owner,
        int count;
        int r = -1;
 
-       if (!subid_init(PACKAGE_NAME, stderr)) {
-               ERROR(pakfire, "Could not setup subid: %m\n");
-               return 1;
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
+       r = subid_init(PACKAGE_NAME, stderr);
+       if (r) {
+               CTX_ERROR(ctx, "Could not setup subid: %m\n");
+               goto ERROR;
        }
 
        count = callback(owner, &ranges);
        if (count < 0) {
-               ERROR(pakfire, "Could not fetch subids for %s: %m\n", owner);
+               CTX_ERROR(ctx, "Could not fetch subids for %s: %m\n", owner);
                goto ERROR;
        }
 
@@ -195,6 +196,8 @@ static int pakfire_getsubid(struct pakfire* pakfire, const char* owner,
 ERROR:
        if (ranges)
                free(ranges);
+       if (ctx)
+               pakfire_ctx_unref(ctx);
 
        return r;
 }
@@ -216,6 +219,8 @@ static int pakfire_fgetsubid(struct pakfire* pakfire, struct pakfire_subid* subi
        size_t length = 0;
        char* p = NULL;
 
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
        // Read the next line
        while (1) {
                r = getline(&line, &length, f);
@@ -257,7 +262,7 @@ static int pakfire_fgetsubid(struct pakfire* pakfire, struct pakfire_subid* subi
 
        // Check if length is greater than zero
        if (subid->length == 0) {
-               DEBUG(pakfire, "Length equals zero: %s\n", line);
+               CTX_DEBUG(ctx, "Length equals zero: %s\n", line);
                r = 1;
                goto ERROR;
        }
@@ -270,9 +275,12 @@ ERROR:
                free(line);
 
        if (!r)
-               DEBUG(pakfire, "Parsed SUBID entry: name=%s, id=%u, length=%zu\n",
+               CTX_DEBUG(ctx, "Parsed SUBID entry: name=%s, id=%u, length=%zu\n",
                        subid->name, subid->id, subid->length);
 
+       if (ctx)
+               pakfire_ctx_unref(ctx);
+
        return r;
 }
 
@@ -292,7 +300,9 @@ static int pakfire_getsubid(struct pakfire* pakfire, const char* path, const cha
        if (!owner)
                return 1;
 
-       DEBUG(pakfire, "Fetching SUBID from %s for %s\n", path, owner);
+       struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
+       CTX_DEBUG(ctx, "Fetching SUBID from %s for %s\n", path, owner);
 
        // Open /etc/subuid
        FILE* f = fopen(path, "r");
@@ -302,7 +312,7 @@ static int pakfire_getsubid(struct pakfire* pakfire, const char* path, const cha
                                break;
 
                        default:
-                               ERROR(pakfire, "Could not open %s: %m\n", path);
+                               CTX_ERROR(ctx, "Could not open %s: %m\n", path);
                                break;
                }
 
@@ -337,12 +347,14 @@ static int pakfire_getsubid(struct pakfire* pakfire, const char* path, const cha
        }
 
        // No match found
-       DEBUG(pakfire, "No match found for %s\n", owner);
+       CTX_DEBUG(ctx, "No match found for %s\n", owner);
        r = 1;
 
 END:
        if (f)
                fclose(f);
+       if (ctx)
+               pakfire_ctx_unref(ctx);
 
        return r;
 }