]> git.ipfire.org Git - pakfire.git/commitdiff
util: Remove the legacy logger
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 14:05:15 +0000 (14:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 14:05:15 +0000 (14:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/include/pakfire/util.h
src/libpakfire/jail.c
src/libpakfire/pakfire.c
src/libpakfire/parser.c
src/libpakfire/util.c

index 37993821f6ab40ac80c24da7a9259a8b9ce37d6c..3ce25815abda6f186cda8a8b5b10e6ea25522618 100644 (file)
@@ -331,7 +331,7 @@ static int pakfire_build_make_filter(struct pakfire_build* build, pcre2_code** r
        CTX_DEBUG(build->ctx, "Found filter for %s: %s\n", filter, pattern);
 
        // Compile the regular expression
-       r = pakfire_compile_regex(build->pakfire, regex, pattern);
+       r = pakfire_compile_regex(build->ctx, regex, pattern);
        if (r)
                goto ERROR;
 
@@ -2421,7 +2421,7 @@ PAKFIRE_EXPORT int pakfire_build_mkimage(struct pakfire_build* build,
                goto ERROR;
 
        // Copy data to its destination
-       r = pakfire_copy(build->pakfire, t, f);
+       r = pakfire_copy(build->ctx, t, f);
        if (r)
                goto ERROR;
 
index dbbb7306dc9a2fdc2e95ce51606d9a54634893b9..59011cdd94f2173e7df61a708125f61305f8e091 100644 (file)
@@ -113,13 +113,12 @@ int pakfire_json_add_string_array(struct json_object* json, const char* name, ch
 
 #define PAKFIRE_RLIMIT_NOFILE_MAX (512 * 1024)
 
-int pakfire_rlimit_set(struct pakfire* pakfire, int limit);
-int pakfire_rlimit_reset_nofile(struct pakfire* pakfire);
+int pakfire_rlimit_set(struct pakfire_ctx* ctx, int limit);
+int pakfire_rlimit_reset_nofile(struct pakfire_ctx* ctx);
 
 // Regex
 
-int pakfire_compile_regex(struct pakfire* pakfire, pcre2_code** regex,
-       const char* pattern);
+int pakfire_compile_regex(struct pakfire_ctx* ctx, pcre2_code** regex, const char* pattern);
 
 // Base64
 
@@ -129,7 +128,7 @@ int pakfire_b64decode(struct pakfire_ctx* ctx, void** output, size_t* length,
        const char* buffer);
 
 // Copy
-int pakfire_copy(struct pakfire* pakfire, FILE* src, FILE* dst);
+int pakfire_copy(struct pakfire_ctx* ctx, FILE* src, FILE* dst);
 
 // Time
 
index 5b26e73a9267f69a5ad6b0e51ad36ab7d8f7b440..7b77ac12127cc0bbe66f038e96ed8982cf12c5c4 100644 (file)
@@ -1289,7 +1289,7 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
 #endif /* ENABLE_DEBUG */
 
        // Reset open file limit (http://0pointer.net/blog/file-descriptor-limits.html)
-       r = pakfire_rlimit_reset_nofile(jail->pakfire);
+       r = pakfire_rlimit_reset_nofile(jail->ctx);
        if (r)
                return r;
 
index ecea815ab6d5689fd9aa3f2449731fa625de691c..5116d53441ae63c9f9fc5a1d4e9ce604b82a90f6 100644 (file)
@@ -998,7 +998,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx*
        }
 
        // Bump RLIMIT_NOFILE to maximum
-       r = pakfire_rlimit_set(p, PAKFIRE_RLIMIT_NOFILE_MAX);
+       r = pakfire_rlimit_set(p->ctx, PAKFIRE_RLIMIT_NOFILE_MAX);
        if (r)
                goto ERROR;
 
index 9f2d799289dbd21dc6b677c1e57ada390a3836f4..6d2301832d35c67f44a1a92870fcb1970ae9b240 100644 (file)
@@ -65,7 +65,7 @@ static int pakfire_parser_compile_regexes(struct pakfire_parser* parser) {
 
        // Commands
        if (!parser->regex_command && (parser->flags & PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS)) {
-               r = pakfire_compile_regex(parser->pakfire, &parser->regex_command,
+               r = pakfire_compile_regex(parser->ctx, &parser->regex_command,
                        "%(\\(((?>[^()]|(?1))*)\\))");
                if (r)
                        return r;
@@ -73,7 +73,7 @@ static int pakfire_parser_compile_regexes(struct pakfire_parser* parser) {
 
        // Variables
        if (!parser->regex_variable) {
-               r = pakfire_compile_regex(parser->pakfire, &parser->regex_variable,
+               r = pakfire_compile_regex(parser->ctx, &parser->regex_variable,
                        "%\\{([A-Za-z0-9_\\-]+)\\}");
                if (r)
                        return r;
index 96a29aa751bd8c529dd4d6a3b66b0f0d0c290bb6..072e49bf15fd1e1a2f994c5b3c7fdf46e404d3b8 100644 (file)
@@ -44,9 +44,6 @@
 #define PCRE2_CODE_UNIT_WIDTH 8
 #include <pcre2.h>
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
 #include <pakfire/ctx.h>
 #include <pakfire/constants.h>
 #include <pakfire/logging.h>
@@ -775,19 +772,19 @@ int pakfire_json_add_double(struct json_object* json, const char* name, double v
 
 // Resource Limits
 
-int pakfire_rlimit_set(struct pakfire* pakfire, int limit) {
+int pakfire_rlimit_set(struct pakfire_ctx* ctx, int limit) {
        struct rlimit rl;
+       int r;
 
        // Sanity check
-       if (limit < 3) {
-               errno = EINVAL;
-               return 1;
-       }
+       if (limit < 3)
+               return -EINVAL;
 
        // Fetch current configuration
-       if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
-               ERROR(pakfire, "Could not read RLIMIT_NOFILE: %m\n");
-               return 1;
+       r = getrlimit(RLIMIT_NOFILE, &rl);
+       if (r < 0) {
+               CTX_ERROR(ctx, "Could not read RLIMIT_NOFILE: %m\n");
+               return -errno;
        }
 
        // Do not attempt to set higher than maximum
@@ -797,13 +794,13 @@ int pakfire_rlimit_set(struct pakfire* pakfire, int limit) {
        rl.rlim_cur = limit;
 
        // Set the new limit
-       if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
-               ERROR(pakfire, "Could not set RLIMIT_NOFILE to %lu: %m\n", rl.rlim_cur);
-               return 1;
+       r = setrlimit(RLIMIT_NOFILE, &rl);
+       if (r < 0) {
+               CTX_ERROR(ctx, "Could not set RLIMIT_NOFILE to %lu: %m\n", rl.rlim_cur);
+               return -errno;
        }
 
-       DEBUG(pakfire, "RLIMIT_NOFILE set to %d\n", limit);
-
+       CTX_DEBUG(ctx, "RLIMIT_NOFILE set to %d\n", limit);
        return 0;
 }
 
@@ -811,13 +808,13 @@ int pakfire_rlimit_set(struct pakfire* pakfire, int limit) {
        Resets RLIMIT_NOFILE to FD_SETSIZE (e.g. 1024)
        for compatibility with software that uses select()
 */
-int pakfire_rlimit_reset_nofile(struct pakfire* pakfire) {
-       return pakfire_rlimit_set(pakfire, FD_SETSIZE);
+int pakfire_rlimit_reset_nofile(struct pakfire_ctx* ctx) {
+       return pakfire_rlimit_set(ctx, FD_SETSIZE);
 }
 
 // Regex
 
-int pakfire_compile_regex(struct pakfire* pakfire, pcre2_code** regex, const char* pattern) {
+int pakfire_compile_regex(struct pakfire_ctx* ctx, pcre2_code** regex, const char* pattern) {
        int pcre2_errno;
        size_t pcre2_offset;
        PCRE2_UCHAR errmsg[256];
@@ -828,7 +825,7 @@ int pakfire_compile_regex(struct pakfire* pakfire, pcre2_code** regex, const cha
 
        if (!*regex) {
                pcre2_get_error_message(pcre2_errno, errmsg, sizeof(errmsg));
-               ERROR(pakfire, "PCRE2 compilation failed for '%s' at offset %zu: %s\n",
+               CTX_ERROR(ctx, "PCRE2 compilation failed for '%s' at offset %zu: %s\n",
                        pattern, pcre2_offset, errmsg);
                return 1;
        }
@@ -837,7 +834,7 @@ int pakfire_compile_regex(struct pakfire* pakfire, pcre2_code** regex, const cha
        pcre2_errno = pcre2_jit_compile(*regex, PCRE2_JIT_COMPLETE);
        if (pcre2_errno) {
                pcre2_get_error_message(pcre2_errno, errmsg, sizeof(errmsg));
-               ERROR(pakfire, "Enabling JIT on '%s' failed: %s\n", pattern, errmsg);
+               CTX_ERROR(ctx, "Enabling JIT on '%s' failed: %s\n", pattern, errmsg);
                return 1;
        }
 
@@ -1008,7 +1005,7 @@ CLEANUP:
 
 // Copy
 
-int pakfire_copy(struct pakfire* pakfire, FILE* src, FILE* dst) {
+int pakfire_copy(struct pakfire_ctx* ctx, FILE* src, FILE* dst) {
        char buffer[BUFFER_SIZE];
        size_t bytes_read;
        size_t bytes_written;
@@ -1019,14 +1016,14 @@ int pakfire_copy(struct pakfire* pakfire, FILE* src, FILE* dst) {
 
                // Check for any errors
                if (ferror(src)) {
-                       ERROR(pakfire, "Could not read data: %m\n");
+                       CTX_ERROR(ctx, "Could not read data: %m\n");
                        return 1;
                }
 
                // Write the data
                bytes_written = fwrite(buffer, 1, bytes_read, dst);
                if (bytes_written < bytes_read) {
-                       ERROR(pakfire, "Could not write data: %m\n");
+                       CTX_ERROR(ctx, "Could not write data: %m\n");
                        return 1;
                }
        }