From 3f58ef38ab7a9cec00af731a7e64d7676230196e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 25 Oct 2024 14:05:15 +0000 Subject: [PATCH] util: Remove the legacy logger Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 4 +-- src/libpakfire/include/pakfire/util.h | 9 +++--- src/libpakfire/jail.c | 2 +- src/libpakfire/pakfire.c | 2 +- src/libpakfire/parser.c | 4 +-- src/libpakfire/util.c | 45 +++++++++++++-------------- 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 37993821f..3ce25815a 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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; diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index dbbb7306d..59011cdd9 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -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 diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 5b26e73a9..7b77ac121 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -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; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index ecea815ab..5116d5344 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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; diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index 9f2d79928..6d2301832 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -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; diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 96a29aa75..072e49bf1 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -44,9 +44,6 @@ #define PCRE2_CODE_UNIT_WIDTH 8 #include -// Enable legacy logging -#define PAKFIRE_LEGACY_LOGGING - #include #include #include @@ -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; } } -- 2.47.2