]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Move loglevel into flags on create for Pakfire
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 Sep 2023 15:32:47 +0000 (15:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 Sep 2023 15:32:47 +0000 (15:32 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/cli/pakfire/main.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c
tests/parser/test.c
tests/testsuite.c

index 6a8dc55bf30d21ea418b928cdfd50fce3d445823..1e7ea60d5d908c304c9be44d2121ae7c86722a77 100644 (file)
@@ -221,7 +221,7 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
                        goto ERROR;
        }
 
-       int flags = 0;
+       int flags = PAKFIRE_FLAGS_DEBUG;
 
        // Enable offline mode
        if (offline)
@@ -235,7 +235,7 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
 
        // Create a new Pakfire instance
        r = pakfire_create(&self->pakfire, path, arch, fconf, flags,
-               LOG_DEBUG, Pakfire_log_callback, self->callbacks.log);
+               Pakfire_log_callback, self->callbacks.log);
 
        Py_END_ALLOW_THREADS
 
index 80e0db344c21be0279c303cab7d0dcf4353fcce5..6d0048a3ef49342fc6bacea83411ee0cc803f3d0 100644 (file)
@@ -22,7 +22,6 @@
 #include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/syslog.h>
 #include <unistd.h>
 
 #include <pakfire/pakfire.h>
@@ -48,7 +47,6 @@ struct config {
        char* arch;
        char* root;
        int flags;
-       int loglevel;
        int yes;
 
        // Repos
@@ -163,7 +161,7 @@ static int parse_argv(struct config* config, int argc, char* argv[]) {
                                break;
 
                        case ARG_DEBUG:
-                               config->loglevel = LOG_DEBUG;
+                               config->flags |= PAKFIRE_FLAGS_DEBUG;
                                break;
 
                        case ARG_OFFLINE:
@@ -228,7 +226,6 @@ int main(int argc, char* argv[]) {
                .arch     = NULL,
                .root     = "/",
                .flags    = 0,
-               .loglevel = LOG_INFO,
                .yes      = 0,
        };
 
@@ -247,7 +244,7 @@ int main(int argc, char* argv[]) {
 
        // Initialize Pakfire
        r = pakfire_create(&pakfire, config.root, config.arch, f,
-               config.flags, config.loglevel, NULL, NULL);
+               config.flags, NULL, NULL);
        if (r)
                goto ERROR;
 
index 975d9eba9efc8df3491ad75a4875f3a766f21c9a..9154cee4a92052b5c1cfeaf318e491af36b2b90a 100644 (file)
@@ -38,7 +38,8 @@ struct pakfire;
 #include <pakfire/transaction.h>
 
 enum pakfire_flags {
-       PAKFIRE_FLAGS_OFFLINE                   = (1 << 0),
+       PAKFIRE_FLAGS_DEBUG             = (1 << 0),
+       PAKFIRE_FLAGS_OFFLINE                   = (1 << 1),
 };
 
 // Callbacks
@@ -54,7 +55,7 @@ typedef void (*pakfire_status_callback)(struct pakfire* pakfire, void* data,
        int progress, const char* status);
 
 int pakfire_create(struct pakfire** pakfire, const char* path, const char* arch,
-       FILE* conf, int flags, int loglevel, pakfire_log_callback log_callback, void* log_data);
+       FILE* conf, int flags, pakfire_log_callback log_callback, void* log_data);
 
 struct pakfire* pakfire_ref(struct pakfire* pakfire);
 struct pakfire* pakfire_unref(struct pakfire* pakfire);
index a1a4d203e4d92bf25649f1f9f7ea2a27520c9ad7..45d725011ad7ab0bfd874ea7c24d27450b7d5787 100644 (file)
@@ -892,8 +892,7 @@ ERROR:
 }
 
 PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
-               const char* arch, FILE* conf, int flags,
-               int loglevel, pakfire_log_callback log_callback, void* log_data) {
+               const char* arch, FILE* conf, int flags, pakfire_log_callback log_callback, void* log_data) {
        char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
        char private_dir[PATH_MAX];
        int r = 1;
@@ -918,9 +917,11 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
        else
                pakfire_set_log_callback(p, pakfire_log_syslog, NULL);
 
-       // Set log level
-       if (loglevel) {
-               pakfire_log_set_priority(p, loglevel);
+       // Set log level to debug if in debug mode
+       if (pakfire_has_flag(p, PAKFIRE_FLAGS_DEBUG)) {
+               pakfire_log_set_priority(p, LOG_DEBUG);
+
+       // Otherwise take the log level from the environment
        } else {
                const char* env = secure_getenv("PAKFIRE_LOG");
                if (env)
index 9e83f30c388740e0d6dff9ddf64b2cda0f5cc204..36b61679f427d1890b0777965dbd99d3e6310167 100644 (file)
@@ -44,7 +44,7 @@ int main(int argc, const char* argv[]) {
 
        // Create a pakfire instance
        r = pakfire_create(&pakfire, root, NULL, NULL,
-               0, LOG_DEBUG, pakfire_log_stderr, NULL);
+               PAKFIRE_FLAGS_DEBUG, pakfire_log_stderr, NULL);
        if (r) {
                fprintf(stderr, "Could not create Pakfire: %m\n");
                goto ERROR;
index 06714d4ed47dd470bffad8ac935ecbdc4ae326eb..3980995754334e6caed031b70a23f316a240180c 100644 (file)
@@ -36,6 +36,7 @@ struct testsuite ts;
 static int test_run(int i, struct test* t) {
        struct pakfire* p = NULL;
        FILE* c = NULL;
+       const int flags = PAKFIRE_FLAGS_DEBUG;
 
        char root[PATH_MAX] = TEST_ROOTFS "/pakfire-test-XXXXXX";
        int r;
@@ -58,7 +59,7 @@ static int test_run(int i, struct test* t) {
        }
 
        // Create a pakfire instance
-       r = pakfire_create(&t->pakfire, root, NULL, c, 0, LOG_DEBUG, pakfire_log_stderr, NULL);
+       r = pakfire_create(&t->pakfire, root, NULL, c, flags, pakfire_log_stderr, NULL);
        if (r) {
                LOG("ERROR: Could not initialize pakfire: %m\n");
                goto ERROR;