]> git.ipfire.org Git - pakfire.git/commitdiff
Move logging into Pakfire context
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Feb 2018 17:24:25 +0000 (18:24 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Feb 2018 17:24:25 +0000 (18:24 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
22 files changed:
src/libpakfire/archive.c
src/libpakfire/include/pakfire/logging.h
src/libpakfire/include/pakfire/packagelist.h
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/include/pakfire/problem.h
src/libpakfire/include/pakfire/request.h
src/libpakfire/include/pakfire/util.h
src/libpakfire/key.c
src/libpakfire/logging.c
src/libpakfire/package.c
src/libpakfire/packagelist.c
src/libpakfire/pakfire.c
src/libpakfire/problem.c
src/libpakfire/relation.c
src/libpakfire/relationlist.c
src/libpakfire/repo.c
src/libpakfire/request.c
src/libpakfire/selector.c
src/libpakfire/solution.c
src/libpakfire/step.c
src/libpakfire/transaction.c
src/libpakfire/util.c

index b1a0b181311c1ead5f6454d65f36a11e8c6f6e44..e47284fd6a96eff4499715498fe9eb51b2a4e295 100644 (file)
@@ -47,6 +47,7 @@
 #define BLOCKSIZE      1024 * 1024 // 1MB
 
 typedef struct archive_checksum {
+       Pakfire pakfire;
        char* filename;
        char* checksum;
        archive_checksum_algo_t algo;
@@ -70,6 +71,7 @@ struct _PakfireArchive {
 };
 
 struct _PakfireArchiveSignature {
+       Pakfire pakfire;
        PakfireKey key;
        char* sigdata;
        int nrefs;
@@ -184,14 +186,15 @@ static const char* checksum_algo_string(archive_checksum_algo_t algo) {
        return NULL;
 }
 
-static archive_checksum_t* pakfire_archive_checksum_create(const char* filename, const char* checksum, archive_checksum_algo_t algo) {
+static archive_checksum_t* pakfire_archive_checksum_create(Pakfire pakfire, const char* filename, const char* checksum, archive_checksum_algo_t algo) {
        archive_checksum_t* c = pakfire_calloc(1, sizeof(*c));
        if (c) {
+               c->pakfire = pakfire_ref(pakfire);
                c->filename = pakfire_strdup(filename);
                c->checksum = pakfire_strdup(checksum);
                c->algo = algo;
 
-               DEBUG("Allocated archive checksum for %s (%s:%s)\n",
+               DEBUG(c->pakfire, "Allocated archive checksum for %s (%s:%s)\n",
                        c->filename, checksum_algo_string(c->algo), c->checksum);
        }
 
@@ -199,10 +202,11 @@ static archive_checksum_t* pakfire_archive_checksum_create(const char* filename,
 }
 
 static void pakfire_archive_checksum_free(archive_checksum_t* c) {
+       DEBUG(c->pakfire, "Releasing archive checksum at %p\n", c);
+
+       pakfire_unref(c->pakfire);
        pakfire_free(c->filename);
        pakfire_free(c->checksum);
-
-       DEBUG("Released archive checksum at %p\n", c);
        pakfire_free(c);
 }
 
@@ -223,22 +227,25 @@ static archive_checksum_t* pakfire_archive_checksum_find(PakfireArchive archive,
 static PakfireArchiveSignature pakfire_archive_signature_create(PakfireArchive archive, const char* sigdata) {
        PakfireArchiveSignature signature = pakfire_calloc(1, sizeof(*signature));
        if (signature) {
+               signature->pakfire = pakfire_ref(archive->pakfire);
                signature->nrefs = 1;
                signature->sigdata = pakfire_strdup(sigdata);
 
-               DEBUG("Allocated archive signature at %p\n%s\n", signature, signature->sigdata);
+               DEBUG(signature->pakfire, "Allocated archive signature at %p\n%s\n",
+                       signature, signature->sigdata);
        }
 
        return signature;
 }
 
 static void pakfire_archive_signature_free(PakfireArchiveSignature signature) {
+       DEBUG(signature->pakfire, "Releasing archive signature at %p\n", signature);
+       pakfire_unref(signature->pakfire);
+
        if (signature->key)
                pakfire_key_unref(signature->key);
 
        pakfire_free(signature->sigdata);
-
-       DEBUG("Released archive signature at %p\n", signature);
        pakfire_free(signature);
 }
 
@@ -274,12 +281,11 @@ PAKFIRE_EXPORT size_t pakfire_archive_count_signatures(PakfireArchive archive) {
 PAKFIRE_EXPORT PakfireArchive pakfire_archive_create(Pakfire pakfire) {
        PakfireArchive archive = pakfire_calloc(1, sizeof(*archive));
        if (archive) {
-               DEBUG("Allocated new archive at %p\n", archive);
-
-               archive->nrefs = 1;
+               DEBUG(pakfire, "Allocated new archive at %p\n", archive);
                archive->pakfire = pakfire_ref(pakfire);
-               archive->format = -1;
+               archive->nrefs = 1;
 
+               archive->format = -1;
                archive->signatures = NULL;
        }
 
@@ -293,6 +299,8 @@ PAKFIRE_EXPORT PakfireArchive pakfire_archive_ref(PakfireArchive archive) {
 }
 
 static void pakfire_archive_free(PakfireArchive archive) {
+       DEBUG(archive->pakfire, "Releasing archive at %p\n", archive);
+
        if (archive->path)
                pakfire_free(archive->path);
 
@@ -311,8 +319,6 @@ static void pakfire_archive_free(PakfireArchive archive) {
        }
 
        pakfire_unref(archive->pakfire);
-
-       DEBUG("Released archive at %p\n", archive);
        pakfire_free(archive);
 }
 
@@ -335,7 +341,8 @@ static int pakfire_archive_parse_entry_format(PakfireArchive archive,
        archive_read_data(a, &format, sizeof(*format));
        archive->format = atoi(format);
 
-       DEBUG("Archive at %p format is %d\n", archive, archive->format);
+       DEBUG(archive->pakfire, "Archive at %p format is %d\n",
+               archive, archive->format);
 
        return (archive->format < 0);
 }
@@ -430,7 +437,7 @@ static int pakfire_archive_parse_entry_checksums(PakfireArchive archive,
 
                // Add new checksum object
                if (filename && checksum) {
-                       *checksums++ = pakfire_archive_checksum_create(filename, checksum, algo);
+                       *checksums++ = pakfire_archive_checksum_create(archive->pakfire, filename, checksum, algo);
                }
 
                // Eat up any space before next thing starts
@@ -547,7 +554,9 @@ static int archive_extract(struct archive* a, const char* prefix) {
        struct archive_entry* entry;
        int r;
 
+#if 0
        DEBUG("Extracting archive to %s\n", prefix);
+#endif
 
        struct archive* ext = archive_write_disk_new();
 
@@ -581,7 +590,9 @@ static int archive_extract(struct archive* a, const char* prefix) {
                char* pathname = pakfire_path_join(prefix, archive_pathname);
                archive_entry_set_pathname(entry, pathname);
 
+#if 0
                DEBUG("Extracting /%s (%zu bytes)\n", pathname, size);
+#endif
                pakfire_free(pathname);
 
                r = archive_write_header(ext, entry);
@@ -799,7 +810,7 @@ static int pakfire_archive_read_signature_entry(PakfireArchive archive, struct a
 }
 
 static int pakfire_archive_load_signatures(PakfireArchive archive) {
-       DEBUG("Loading all signatures for archive at %p\n", archive);
+       DEBUG(archive->pakfire, "Loading all signatures for archive at %p\n", archive);
 
        return pakfire_archive_walk(archive, pakfire_archive_read_signature_entry);
 }
@@ -817,7 +828,7 @@ static pakfire_archive_verify_status_t pakfire_archive_verify_checksums(PakfireA
        // Cannot validate anything if no signatures are available
        PakfireArchiveSignature* signatures = pakfire_archive_get_signatures(archive);
        if (!signatures) {
-               DEBUG("Archive %p does not have any signatures\n", archive);
+               DEBUG(archive->pakfire, "Archive %p does not have any signatures\n", archive);
                return PAKFIRE_ARCHIVE_VERIFY_OK;
        }
 
@@ -899,7 +910,8 @@ CLEANUP:
        gpgme_data_release(signed_text);
        gpgme_release(gpgctx);
 
-       DEBUG("Checksum verification status: %s\n", pakfire_archive_verify_strerror(status));
+       DEBUG(archive->pakfire, "Checksum verification status: %s\n",
+               pakfire_archive_verify_strerror(status));
 
        return status;
 }
@@ -916,7 +928,7 @@ static char* digest_to_hexdigest(const unsigned char* digest, unsigned int len)
        return hexdigest;
 }
 
-static pakfire_archive_verify_status_t pakfire_archive_verify_file(struct archive* a, const archive_checksum_t* checksum) {
+static pakfire_archive_verify_status_t pakfire_archive_verify_file(Pakfire pakfire, struct archive* a, const archive_checksum_t* checksum) {
        pakfire_archive_verify_status_t status = PAKFIRE_ARCHIVE_VERIFY_INVALID;
 
        // Make sure libgcrypt is initialized
@@ -969,11 +981,11 @@ static pakfire_archive_verify_status_t pakfire_archive_verify_file(struct archiv
 
        // Compare digests
        if (strcmp(checksum->checksum, hexdigest) == 0) {
-               DEBUG("Checksum of %s is OK\n", checksum->filename);
+               DEBUG(pakfire, "Checksum of %s is OK\n", checksum->filename);
                status = PAKFIRE_ARCHIVE_VERIFY_OK;
        } else {
-               DEBUG("Checksum of %s did not match\n", checksum->filename);
-               DEBUG("Expected %s:%s, got %s\n",
+               DEBUG(pakfire, "Checksum of %s did not match\n", checksum->filename);
+               DEBUG(pakfire, "Expected %s:%s, got %s\n",
                        checksum_algo_string(checksum->algo), checksum->checksum, hexdigest);
        }
 
@@ -1009,13 +1021,13 @@ PAKFIRE_EXPORT pakfire_archive_verify_status_t pakfire_archive_verify(PakfireArc
                        continue;
 
                // Compare the checksums
-               status = pakfire_archive_verify_file(a, checksum);
+               status = pakfire_archive_verify_file(archive->pakfire, a, checksum);
                if (status)
                        goto END;
        }
 
        status = PAKFIRE_ARCHIVE_VERIFY_OK;
-       DEBUG("Archive %p has been successfully verified\n", archive);
+       DEBUG(archive->pakfire, "Archive %p has been successfully verified\n", archive);
 
 END:
        archive_close(a);
index 96b93d9c2720a87bec6c1be98780d437ab3590c8..662e6eff9043ff3eded789ece20466c6904fcf2e 100644 (file)
 
 #include <syslog.h>
 
+#include <pakfire/pakfire.h>
 #include <pakfire/types.h>
 
-void pakfire_log_stderr(int priority, const char* file,
-               int line, const char* fn, const char* format, va_list args);
-void pakfire_log_syslog(int priority, const char* file,
-               int line, const char* fn, const char* format, va_list args);
-
-pakfire_log_function_t pakfire_log_get_function();
-void pakfire_log_set_function(pakfire_log_function_t func);
-int pakfire_log_get_priority();
-void pakfire_log_set_priority(int priority);
-
 void pakfire_log_stderr(int priority, const char* file,
        int line, const char* fn, const char* format, va_list args);
 void pakfire_log_syslog(int priority, const char* file,
@@ -42,31 +33,25 @@ void pakfire_log_syslog(int priority, const char* file,
 
 #ifdef PAKFIRE_PRIVATE
 
-typedef struct pakfire_logging_config {
-       pakfire_log_function_t function;
-       int priority;
-} pakfire_logging_config_t;
-
-void pakfire_setup_logging();
-void pakfire_log(int priority, const char *file,
+void pakfire_log(Pakfire pakfire, int priority, const char *file,
        int line, const char *fn, const char *format, ...)
-       __attribute__((format(printf, 5, 6)));
+       __attribute__((format(printf, 6, 7)));
 
 // This function does absolutely nothing
-static inline void __attribute__((always_inline, format(printf, 1, 2)))
-       pakfire_log_null(const char *format, ...) {}
+static inline void __attribute__((always_inline, format(printf, 2, 3)))
+       pakfire_log_null(Pakfire pakfire, const char *format, ...) {}
 
-#define pakfire_log_condition(prio, arg...) \
+#define pakfire_log_condition(pakfire, prio, arg...) \
        do { \
-               if (pakfire_log_get_priority() >= prio) \
-                       pakfire_log(prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
+               if (pakfire_log_get_priority(pakfire) >= prio) \
+                       pakfire_log(pakfire, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
        } while (0)
 
-#define INFO(arg...) pakfire_log_condition(LOG_INFO, ## arg)
-#define ERROR(arg...) pakfire_log_condition(LOG_ERR, ## arg)
+#define INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, ## arg)
+#define ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, ## arg)
 
 #ifdef ENABLE_DEBUG
-#      define DEBUG(arg...) pakfire_log_condition(LOG_DEBUG, ## arg)
+#      define DEBUG(pakfire, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, ## arg)
 #else
 #      define DEBUG pakfire_log_null
 #endif
index 5ce7a0eeaa420f5cca5c54faea0aa2a7defb4380..955fe1488b7b3a5ccc337ab683ed14f146f88302 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <pakfire/types.h>
 
-PakfirePackageList pakfire_packagelist_create(void);
+PakfirePackageList pakfire_packagelist_create(Pakfire pakfire);
 PakfirePackageList pakfire_packagelist_ref(PakfirePackageList list);
 PakfirePackageList pakfire_packagelist_unref(PakfirePackageList list);
 
index 0da17661c9b08012d1ebfddc119be19ebabc2522..9e10ca375a3d855f1d621c45a928b4845b131009 100644 (file)
@@ -63,6 +63,13 @@ int pakfire_cache_stat(Pakfire pakfire, const char* path, struct stat* buffer);
 time_t pakfire_cache_age(Pakfire pakfire, const char* path);
 FILE* pakfire_cache_open(Pakfire pakfire, const char* path, const char* flags);
 
+// Logging
+
+pakfire_log_function_t pakfire_log_get_function(Pakfire pakfire);
+void pakfire_log_set_function(Pakfire pakfire, pakfire_log_function_t log_function);
+int pakfire_log_get_priority(Pakfire pakfire);
+void pakfire_log_set_priority(Pakfire pakfire, int priority);
+
 #ifdef PAKFIRE_PRIVATE
 
 #include <solv/pool.h>
index cecb056bb6c8785e7a54185fe4c570e38060a635..d801ee06b35b2d154a9827cfeca2fc8411cc0dd1 100644 (file)
@@ -39,6 +39,7 @@ PakfireSolution pakfire_problem_get_solutions(PakfireProblem problem);
 
 #include <solv/pooltypes.h>
 
+Pakfire pakfire_problem_get_pakfire(PakfireProblem problem);
 Id pakfire_problem_get_id(PakfireProblem problem);
 
 #endif
index eda17deb5a660e15d39dbbb0c1519d2285146061..963043e0b3f275e00829700cce87a56bd7ba297a 100644 (file)
@@ -74,6 +74,7 @@ int pakfire_request_verify(PakfireRequest request);
 
 #include <solv/solver.h>
 
+Pakfire pakfire_request_get_pakfire(PakfireRequest request);
 Solver* pakfire_request_get_solver(PakfireRequest request);
 
 #endif
index df32e5bd18cffad8235194659b664e557510aba5..bc2a36aa317a1157aa9220be4bbb8c52c1e012b0 100644 (file)
@@ -45,8 +45,8 @@ char* pakfire_path_join(const char* first, const char* second);
 
 char* pakfire_basename(const char* path);
 char* pakfire_dirname(const char* path);
-int pakfire_access(const char* dir, const char* file, int mode);
-int pakfire_mkdir(const char* path, mode_t mode);
+int pakfire_access(Pakfire pakfire, const char* dir, const char* file, int mode);
+int pakfire_mkdir(Pakfire pakfire, const char* path, mode_t mode);
 
 char* pakfire_sgets(char* str, int num, char** input);
 char* pakfire_remove_trailing_newline(char* str);
index db9b050f3d0a4f23f6cfd66853238e1dfdeba01b..690b4fa8223d054abcb7fc2a07bb923c3a010efa 100644 (file)
@@ -43,7 +43,7 @@ gpgme_ctx_t pakfire_get_gpgctx(Pakfire pakfire) {
        if (!gpg_initialized) {
                // Initialise gpgme
                const char* version = gpgme_check_version(NULL);
-               DEBUG("Loaded gpgme %s\n", version);
+               DEBUG(pakfire, "Loaded gpgme %s\n", version);
 
                // Check if we support GPG
                error = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
@@ -68,12 +68,12 @@ gpgme_ctx_t pakfire_get_gpgctx(Pakfire pakfire) {
        char* home = pakfire_path_join(path, "etc/pakfire/gnupg");
 
        // Check if gpg directories exist
-       if (pakfire_access(home, NULL, R_OK) != 0) {
-               DEBUG("Creating GPG database at %s\n", home);
+       if (pakfire_access(pakfire, home, NULL, R_OK) != 0) {
+               DEBUG(pakfire, "Creating GPG database at %s\n", home);
 
-               int r = pakfire_mkdir(home, S_IRUSR|S_IWUSR|S_IXUSR);
+               int r = pakfire_mkdir(pakfire, home, S_IRUSR|S_IWUSR|S_IXUSR);
                if (r) {
-                       ERROR("Could not initialize the GPG database at %s\n", home);
+                       ERROR(pakfire, "Could not initialize the GPG database at %s\n", home);
                        goto FAIL;
                }
        }
@@ -85,7 +85,7 @@ gpgme_ctx_t pakfire_get_gpgctx(Pakfire pakfire) {
                goto FAIL;
 
        gpgme_engine_info_t engine_info = gpgme_ctx_get_engine_info(ctx);
-       DEBUG("GPGME engine info: %s, home = %s\n",
+       DEBUG(pakfire, "GPGME engine info: %s, home = %s\n",
                engine_info->file_name, engine_info->home_dir);
 
        return ctx;
@@ -94,7 +94,7 @@ FAIL:
        gpgme_release(ctx);
 
        error_string = gpgme_strerror(error);
-       ERROR("%s\n", error_string);
+       ERROR(pakfire, "%s\n", error_string);
 
        return NULL;
 }
@@ -116,7 +116,7 @@ static size_t pakfire_count_keys(Pakfire pakfire) {
                gpgme_key_release(key);
        }
 
-       DEBUG("%zu key(s) in keystore\n", count);
+       DEBUG(pakfire, "%zu key(s) in keystore\n", count);
        gpgme_release(gpgctx);
 
        return count;
@@ -188,7 +188,7 @@ PAKFIRE_EXPORT void pakfire_key_unref(PakfireKey key) {
 }
 
 static PakfireKey __pakfire_get_key(Pakfire pakfire, gpgme_ctx_t gpgctx, const char* fingerprint) {
-       DEBUG("Seaching for key with fingerprint %s\n", fingerprint);
+       DEBUG(pakfire, "Seaching for key with fingerprint %s\n", fingerprint);
 
        PakfireKey key = NULL;
        gpgme_key_t gpgkey = NULL;
@@ -201,11 +201,11 @@ static PakfireKey __pakfire_get_key(Pakfire pakfire, gpgme_ctx_t gpgctx, const c
                        break;
 
                case GPG_ERR_EOF:
-                       DEBUG("Nothing found\n");
+                       DEBUG(pakfire, "Nothing found\n");
                        break;
 
                default:
-                       DEBUG("Could not find key: %s\n", gpgme_strerror(error));
+                       DEBUG(pakfire, "Could not find key: %s\n", gpgme_strerror(error));
                        break;
        }
 
@@ -315,7 +315,7 @@ PAKFIRE_EXPORT PakfireKey pakfire_key_generate(Pakfire pakfire, const char* user
                DEFAULT_KEY_SIZE, 0, 0, NULL, flags);
 
        if (error != GPG_ERR_NO_ERROR) {
-               printf("ERROR: %s\n", gpgme_strerror(error));
+               ERROR(pakfire, "%s\n", gpgme_strerror(error));
                return NULL;
        }
 
@@ -401,9 +401,9 @@ PAKFIRE_EXPORT PakfireKey* pakfire_key_import(Pakfire pakfire, const char* data)
                case GPG_ERR_NO_ERROR:
                        result = gpgme_op_import_result(gpgctx);
 
-                       DEBUG("Keys considered   = %d\n", result->considered);
-                       DEBUG("Keys imported     = %d\n", result->imported);
-                       DEBUG("Keys not imported = %d\n", result->not_imported);
+                       DEBUG(pakfire, "Keys considered   = %d\n", result->considered);
+                       DEBUG(pakfire, "Keys imported     = %d\n", result->imported);
+                       DEBUG(pakfire, "Keys not imported = %d\n", result->not_imported);
 
                        // Did we import any keys?
                        gpgme_import_status_t status = result->imports;
@@ -418,7 +418,7 @@ PAKFIRE_EXPORT PakfireKey* pakfire_key_import(Pakfire pakfire, const char* data)
                                PakfireKey key = __pakfire_get_key(pakfire, gpgctx, status->fpr);
                                if (key) {
                                        const char* fingerprint = pakfire_key_get_fingerprint(key);
-                                       INFO("Imported key %s\n", fingerprint);
+                                       INFO(pakfire, "Imported key %s\n", fingerprint);
 
                                        // Append key to list
                                        *list++ = key;
@@ -442,7 +442,7 @@ PAKFIRE_EXPORT PakfireKey* pakfire_key_import(Pakfire pakfire, const char* data)
 
                // Fall through for any other errors
                default:
-                       ERROR("Failed with gpgme error: %s\n", gpgme_strerror(error));
+                       ERROR(pakfire, "Failed with gpgme error: %s\n", gpgme_strerror(error));
                        break;
        }
 
index d83ee2f3000f2b55a5ee0a30be4e4d17732b6284..13cc716937ad8ea696d27930d3da53fe8a9e07fb 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#include <ctype.h>
-#include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <syslog.h>
 
-#include <pakfire/logging.h>
-#include <pakfire/pakfire.h>
 #include <pakfire/private.h>
 
-static pakfire_logging_config_t conf = {
-       .function = pakfire_log_syslog,
-       .priority = LOG_ERR,
-};
-
-static int log_priority(const char* priority) {
-       char* end;
-
-       int prio = strtol(priority, &end, 10);
-       if (*end == '\0' || isspace(*end))
-               return prio;
-
-       if (strncmp(priority, "error", strlen("error")) == 0)
-               return LOG_ERR;
-
-       if (strncmp(priority, "info", strlen("info")) == 0)
-               return LOG_INFO;
-
-       if (strncmp(priority, "debug", strlen("debug")) == 0)
-               return LOG_DEBUG;
-
-       return 0;
-}
-
-void pakfire_setup_logging() {
-       const char* priority = secure_getenv("PAKFIRE_LOG");
-       if (priority)
-               pakfire_log_set_priority(log_priority(priority));
-}
-
-PAKFIRE_EXPORT pakfire_log_function_t pakfire_log_get_function() {
-       return conf.function;
-}
-
-PAKFIRE_EXPORT void pakfire_log_set_function(pakfire_log_function_t func) {
-       conf.function = func;
-}
-
-PAKFIRE_EXPORT int pakfire_log_get_priority() {
-       return conf.priority;
-}
-
-PAKFIRE_EXPORT void pakfire_log_set_priority(int priority) {
-       conf.priority = priority;
-}
-
-PAKFIRE_EXPORT void pakfire_log(int priority, const char* file, int line,
-               const char* fn, const char* format, ...) {
-       va_list args;
-
-       // Save errno
-       int saved_errno = errno;
-
-       va_start(args, format);
-       conf.function(priority, file, line, fn, format, args);
-       va_end(args);
-
-       // Restore errno
-       errno = saved_errno;
-}
-
 PAKFIRE_EXPORT void pakfire_log_stderr(int priority, const char* file,
                int line, const char* fn, const char* format, va_list args) {
        fprintf(stderr, "pakfire: %s: ", fn);
index 9f3ea6e5226c689d749bd367686eb9b55e7c73de..6e882d101e916422371e27eb0a36e1868a32821c 100644 (file)
@@ -65,7 +65,7 @@ static void pakfire_package_add_self_provides(Pakfire pakfire, PakfirePackage pk
 PAKFIRE_EXPORT PakfirePackage pakfire_package_create(Pakfire pakfire, Id id) {
        PakfirePackage pkg = pakfire_calloc(1, sizeof(*pkg));
        if (pkg) {
-               DEBUG("Allocated Package at %p\n", pkg);
+               DEBUG(pakfire, "Allocated Package at %p\n", pkg);
 
                pkg->pakfire = pakfire_ref(pakfire);
                pkg->id = id;
@@ -90,12 +90,12 @@ PAKFIRE_EXPORT PakfirePackage pakfire_package_create2(Pakfire pakfire, PakfireRe
 }
 
 static void pakfire_package_free(PakfirePackage pkg) {
+       DEBUG(pkg->pakfire, "Releasing Package at %p\n", pkg);
+       pakfire_unref(pkg->pakfire);
+
        pakfire_archive_unref(pkg->archive);
        pakfire_package_filelist_remove(pkg);
-       pakfire_unref(pkg->pakfire);
        pakfire_free(pkg);
-
-       DEBUG("Released Package at %p\n", pkg);
 }
 
 PAKFIRE_EXPORT PakfirePackage pakfire_package_ref(PakfirePackage pkg) {
@@ -862,7 +862,7 @@ PAKFIRE_EXPORT int pakfire_package_is_cached(PakfirePackage pkg) {
        char* path = pakfire_package_get_cache_path(pkg);
 
        // Check if the file is readable
-       int r = pakfire_access(path, NULL, R_OK);
+       int r = pakfire_access(pkg->pakfire, path, NULL, R_OK);
        pakfire_free(path);
 
        return (r == 0);
index 75d9186b3d27bb85fd646287deb060a076e558d1..da8ec69145058b2df69018a72b12057f2eed82cf 100644 (file)
 #define BLOCK_SIZE 31
 
 struct _PakfirePackageList {
+       Pakfire pakfire;
        PakfirePackage* elements;
        size_t count;
        int nrefs;
 };
 
-PAKFIRE_EXPORT PakfirePackageList pakfire_packagelist_create(void) {
+PAKFIRE_EXPORT PakfirePackageList pakfire_packagelist_create(Pakfire pakfire) {
        PakfirePackageList list = pakfire_calloc(1, sizeof(*list));
        if (list) {
-               DEBUG("Allocated PackageList at %p\n", list);
+               DEBUG(pakfire, "Allocated PackageList at %p\n", list);
+               list->pakfire = pakfire_ref(pakfire);
                list->nrefs = 1;
        }
 
@@ -58,14 +60,15 @@ PAKFIRE_EXPORT PakfirePackageList pakfire_packagelist_ref(PakfirePackageList lis
 }
 
 static void pakfire_packagelist_free(PakfirePackageList list) {
+       DEBUG(list->pakfire, "Releasing PackageList at %p\n", list);
+       pakfire_unref(list->pakfire);
+
        for (unsigned int i = 0; i < list->count; i++) {
                pakfire_package_unref(list->elements[i]);
        }
 
        pakfire_free(list->elements);
        pakfire_free(list);
-
-       DEBUG("Released PackageList at %p\n", list);
 }
 
 PAKFIRE_EXPORT PakfirePackageList pakfire_packagelist_unref(PakfirePackageList list) {
@@ -122,7 +125,7 @@ PAKFIRE_EXPORT void pakfire_packagelist_push_if_not_exists(PakfirePackageList li
 }
 
 PAKFIRE_EXPORT PakfirePackageList pakfire_packagelist_from_queue(Pakfire pakfire, Queue* q) {
-       PakfirePackageList list = pakfire_packagelist_create();
+       PakfirePackageList list = pakfire_packagelist_create(pakfire);
 
        Pool* pool = pakfire_get_solv_pool(pakfire);
        Id p, pp;
index 9859bb251205d0c42cf34a04aac048cd73c93ea8..3a14029b87fbf1f6148e995b5aa3d501b2d69708 100644 (file)
 #                                                                             #
 #############################################################################*/
 
+#include <ctype.h>
 #include <errno.h>
 #include <ftw.h>
 #include <stddef.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include <solv/evr.h>
@@ -60,8 +63,24 @@ struct _Pakfire {
 };
 
 PAKFIRE_EXPORT int pakfire_init() {
-       // Setup logging
-       pakfire_setup_logging();
+       return 0;
+}
+
+static int log_priority(const char* priority) {
+       char* end;
+
+       int prio = strtol(priority, &end, 10);
+       if (*end == '\0' || isspace(*end))
+               return prio;
+
+       if (strncmp(priority, "error", strlen("error")) == 0)
+               return LOG_ERR;
+
+       if (strncmp(priority, "info", strlen("info")) == 0)
+               return LOG_INFO;
+
+       if (strncmp(priority, "debug", strlen("debug")) == 0)
+               return LOG_DEBUG;
 
        return 0;
 }
@@ -76,9 +95,16 @@ PAKFIRE_EXPORT Pakfire pakfire_create(const char* path, const char* arch) {
                        arch = system_machine();
                pakfire->arch = pakfire_strdup(arch);
 
-               DEBUG("Pakfire initialized at %p\n", pakfire);
-               DEBUG("  arch = %s\n", pakfire_get_arch(pakfire));
-               DEBUG("  path = %s\n", pakfire_get_path(pakfire));
+               // Setup loggiing
+               pakfire->log_function = pakfire_log_syslog;
+
+               const char* env = secure_getenv("PAKFIRE_LOG");
+               if (env)
+                       pakfire_log_set_priority(pakfire, log_priority(env));
+
+               DEBUG(pakfire, "Pakfire initialized at %p\n", pakfire);
+               DEBUG(pakfire, "  arch = %s\n", pakfire_get_arch(pakfire));
+               DEBUG(pakfire, "  path = %s\n", pakfire_get_path(pakfire));
 
                // Initialize the pool
                pakfire->pool = pool_create();
@@ -106,6 +132,8 @@ PAKFIRE_EXPORT Pakfire pakfire_unref(Pakfire pakfire) {
        if (--pakfire->nrefs > 0)
                return pakfire;
 
+       DEBUG(pakfire, "Releasing Pakfire at %p\n", pakfire);
+
        pakfire_repo_free_all(pakfire);
        pool_free(pakfire->pool);
        queue_free(&pakfire->installonly);
@@ -116,8 +144,6 @@ PAKFIRE_EXPORT Pakfire pakfire_unref(Pakfire pakfire) {
 
        pakfire_free(pakfire);
 
-       DEBUG("Pakfire released at %p\n", pakfire);
-
        return NULL;
 }
 
@@ -225,7 +251,7 @@ PAKFIRE_EXPORT void pakfire_set_installonly(Pakfire pakfire, const char** instal
 }
 
 static PakfirePackageList pakfire_pool_dataiterator(Pakfire pakfire, const char* what, int key, int flags) {
-       PakfirePackageList list = pakfire_packagelist_create();
+       PakfirePackageList list = pakfire_packagelist_create(pakfire);
        pakfire_pool_apply_changes(pakfire);
 
        int di_flags = 0;
@@ -252,7 +278,7 @@ static PakfirePackageList pakfire_pool_dataiterator(Pakfire pakfire, const char*
 
 static PakfirePackageList pakfire_search_name(Pakfire pakfire, const char* name, int flags) {
        if (!flags) {
-               PakfirePackageList list = pakfire_packagelist_create();
+               PakfirePackageList list = pakfire_packagelist_create(pakfire);
                pakfire_pool_apply_changes(pakfire);
 
                Id id = pool_str2id(pakfire->pool, name, 0);
@@ -278,7 +304,7 @@ static PakfirePackageList pakfire_search_name(Pakfire pakfire, const char* name,
 
 static PakfirePackageList pakfire_search_provides(Pakfire pakfire, const char* provides, int flags) {
        if (!flags) {
-               PakfirePackageList list = pakfire_packagelist_create();
+               PakfirePackageList list = pakfire_packagelist_create(pakfire);
                pakfire_pool_apply_changes(pakfire);
 
                Id id = pool_str2id(pakfire->pool, provides, 0);
@@ -325,12 +351,10 @@ PAKFIRE_EXPORT void pakfire_set_cache_path(Pakfire pakfire, const char* path) {
 
        pakfire->cache_path = pakfire_strdup(path);
 
-       DEBUG("Set cache path to %s\n", pakfire->cache_path);
+       DEBUG(pakfire, "Set cache path to %s\n", pakfire->cache_path);
 }
 
 static int _unlink(const char* path, const struct stat* stat, int typeflag, struct FTW* ftwbuf) {
-       DEBUG("Deleting %s...\n", path);
-
        return remove(path);
 }
 
@@ -360,7 +384,7 @@ PAKFIRE_EXPORT int pakfire_cache_stat(Pakfire pakfire, const char* path, struct
 PAKFIRE_EXPORT int pakfire_cache_access(Pakfire pakfire, const char* path, int mode) {
        char* cache_path = pakfire_get_cache_path(pakfire, path);
 
-       int r = pakfire_access(cache_path, NULL, mode);
+       int r = pakfire_access(pakfire, cache_path, NULL, mode);
        pakfire_free(cache_path);
 
        return r;
@@ -388,7 +412,7 @@ PAKFIRE_EXPORT FILE* pakfire_cache_open(Pakfire pakfire, const char* path, const
        // Ensure that the parent directory exists
        char* cache_dirname = pakfire_dirname(cache_path);
 
-       int r = pakfire_mkdir(cache_dirname, S_IRUSR|S_IWUSR|S_IXUSR);
+       int r = pakfire_mkdir(pakfire, cache_dirname, S_IRUSR|S_IWUSR|S_IXUSR);
        if (r)
                goto FAIL;
 
@@ -401,3 +425,34 @@ FAIL:
 
        return f;
 }
+
+PAKFIRE_EXPORT pakfire_log_function_t pakfire_log_get_function(Pakfire pakfire) {
+       return pakfire->log_function;
+}
+
+PAKFIRE_EXPORT void pakfire_log_set_function(Pakfire pakfire, pakfire_log_function_t log_function) {
+       pakfire->log_function = log_function;
+}
+
+PAKFIRE_EXPORT int pakfire_log_get_priority(Pakfire pakfire) {
+       return pakfire->log_priority;
+}
+
+PAKFIRE_EXPORT void pakfire_log_set_priority(Pakfire pakfire, int priority) {
+       pakfire->log_priority = priority;
+}
+
+PAKFIRE_EXPORT void pakfire_log(Pakfire pakfire, int priority, const char* file, int line,
+               const char* fn, const char* format, ...) {
+       va_list args;
+
+       // Save errno
+       int saved_errno = errno;
+
+       va_start(args, format);
+       pakfire->log_function(priority, file, line, fn, format, args);
+       va_end(args);
+
+       // Restore errno
+       errno = saved_errno;
+}
index e38385913ea71c79044544883035fc32c3290632..8776569577d5f6721bbcf8b4557589996b076c79 100644 (file)
@@ -21,6 +21,7 @@
 #include <pakfire/constants.h>
 #include <pakfire/i18n.h>
 #include <pakfire/logging.h>
+#include <pakfire/pakfire.h>
 #include <pakfire/private.h>
 #include <pakfire/problem.h>
 #include <pakfire/request.h>
@@ -28,6 +29,7 @@
 #include <pakfire/util.h>
 
 struct _PakfireProblem {
+       Pakfire pakfire;
        PakfireRequest request;
        Id id;
        char* string;
@@ -200,9 +202,12 @@ static char* to_string(PakfireProblem problem) {
 }
 
 PAKFIRE_EXPORT PakfireProblem pakfire_problem_create(PakfireRequest request, Id id) {
+       Pakfire pakfire = pakfire_request_get_pakfire(request);
+
        PakfireProblem problem = pakfire_calloc(1, sizeof(*problem));
        if (problem) {
-               DEBUG("Allocated Problem at %p\n", problem);
+               DEBUG(pakfire, "Allocated Problem at %p\n", problem);
+               problem->pakfire = pakfire_ref(pakfire);
                problem->nrefs = 1;
 
                problem->request = pakfire_request_ref(request);
@@ -212,6 +217,8 @@ PAKFIRE_EXPORT PakfireProblem pakfire_problem_create(PakfireRequest request, Id
                problem->string = to_string(problem);
        }
 
+       pakfire_unref(pakfire);
+
        return problem;
 }
 
@@ -222,14 +229,16 @@ PAKFIRE_EXPORT PakfireProblem pakfire_problem_ref(PakfireProblem problem) {
 }
 
 static void pakfire_problem_free(PakfireProblem problem) {
+       DEBUG(problem->pakfire, "Releasing Problem at %p\n", problem);
+
        pakfire_problem_unref(problem->next);
        pakfire_request_unref(problem->request);
 
        if (problem->string)
                pakfire_free(problem->string);
 
+       pakfire_unref(problem->pakfire);
        pakfire_free(problem);
-       DEBUG("Released Problem at %p\n", problem);
 }
 
 PAKFIRE_EXPORT PakfireProblem pakfire_problem_unref(PakfireProblem problem) {
@@ -243,6 +252,10 @@ PAKFIRE_EXPORT PakfireProblem pakfire_problem_unref(PakfireProblem problem) {
        return NULL;
 }
 
+Pakfire pakfire_problem_get_pakfire(PakfireProblem problem) {
+       return pakfire_ref(problem->pakfire);
+}
+
 PAKFIRE_EXPORT PakfireProblem pakfire_problem_next(PakfireProblem problem) {
        return problem->next;
 }
index 49dda85c572c9268bdbf01db07479ace067f0fd5..7b71c2113ddca2b3ca89875ac0ba846b72d29d6f 100644 (file)
@@ -73,7 +73,7 @@ PAKFIRE_EXPORT PakfireRelation pakfire_relation_create(Pakfire pakfire, const ch
 PAKFIRE_EXPORT PakfireRelation pakfire_relation_create_from_id(Pakfire pakfire, Id id) {
        PakfireRelation relation = pakfire_calloc(1, sizeof(*relation));
        if (relation) {
-               DEBUG("Allocated Relation at %p\n", relation);
+               DEBUG(pakfire, "Allocated Relation at %p\n", relation);
                relation->nrefs = 1;
 
                relation->pakfire = pakfire_ref(pakfire);
@@ -90,10 +90,10 @@ PAKFIRE_EXPORT PakfireRelation pakfire_relation_ref(PakfireRelation relation) {
 }
 
 static void pakfire_relation_free(PakfireRelation relation) {
+       DEBUG(relation->pakfire, "Releasing Relation at %p\n", relation);
+
        pakfire_unref(relation->pakfire);
        pakfire_free(relation);
-
-       DEBUG("Released Relation at %p\n", relation);
 }
 
 PAKFIRE_EXPORT PakfireRelation pakfire_relation_unref(PakfireRelation relation) {
index 0f2d944a216b922a471088671e76e2300e874699..1a43d4e47e3169e1a21fd68e6d773bc91aa09c15 100644 (file)
@@ -38,7 +38,7 @@ struct _PakfireRelationList {
 PAKFIRE_EXPORT PakfireRelationList pakfire_relationlist_create(Pakfire pakfire) {
        PakfireRelationList relationlist = pakfire_calloc(1, sizeof(*relationlist));
        if (relationlist) {
-               DEBUG("Allocated RelationList at %p\n", relationlist);
+               DEBUG(pakfire, "Allocated RelationList at %p\n", relationlist);
                relationlist->nrefs = 1;
 
                relationlist->pakfire = pakfire_ref(pakfire);
@@ -55,12 +55,11 @@ PAKFIRE_EXPORT PakfireRelationList pakfire_relationlist_ref(PakfireRelationList
 }
 
 static void pakfire_relationlist_free(PakfireRelationList relationlist) {
-       queue_free(&relationlist->queue);
-
+       DEBUG(relationlist->pakfire, "Releasing RelationList at %p\n", relationlist);
        pakfire_unref(relationlist->pakfire);
-       pakfire_free(relationlist);
 
-       DEBUG("Released RelationList at %p\n", relationlist);
+       queue_free(&relationlist->queue);
+       pakfire_free(relationlist);
 }
 
 PAKFIRE_EXPORT PakfireRelationList pakfire_relationlist_unref(PakfireRelationList relationlist) {
index 63697d7c74f5b0cb4b0d21357a5b4a780222370b..329e2d531583831219b6a04debc53d0e9cdeec41 100644 (file)
@@ -91,7 +91,7 @@ void pakfire_repo_free_all(Pakfire pakfire) {
 PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name) {
        PakfireRepo repo = pakfire_calloc(1, sizeof(*repo));
        if (repo) {
-               DEBUG("Allocated Repo at %p\n", repo);
+               DEBUG(pakfire, "Allocated Repo at %p\n", repo);
                repo->nrefs = 1;
 
                repo->pakfire = pakfire_ref(pakfire);
@@ -114,7 +114,7 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name
 PakfireRepo pakfire_repo_create_from_repo(Pakfire pakfire, Repo* r) {
        PakfireRepo repo = pakfire_calloc(1, sizeof(*repo));
        if (repo) {
-               DEBUG("Allocated Repo at %p\n", repo);
+               DEBUG(pakfire, "Allocated Repo at %p\n", repo);
                repo->nrefs = 1;
 
                repo->pakfire = pakfire_ref(pakfire);
@@ -134,10 +134,10 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_ref(PakfireRepo repo) {
 }
 
 static void pakfire_repo_free(PakfireRepo repo) {
+       DEBUG(repo->pakfire, "Releasing Repo at %p\n", repo);
        pakfire_unref(repo->pakfire);
 
        pakfire_free(repo);
-       DEBUG("Released Repo at %p\n", repo);
 }
 
 PAKFIRE_EXPORT PakfireRepo pakfire_repo_unref(PakfireRepo repo) {
index ac1024b57d1ed7275591cf12b1330b5ff88d6116..df9853e5e51059c4007f775d090f2235f0bda0c0 100644 (file)
@@ -48,7 +48,7 @@ struct _PakfireRequest {
 PAKFIRE_EXPORT PakfireRequest pakfire_request_create(Pakfire pakfire) {
        PakfireRequest request = pakfire_calloc(1, sizeof(*request));
        if (request) {
-               DEBUG("Allocated Request at %p\n", request);
+               DEBUG(pakfire, "Allocated Request at %p\n", request);
                request->nrefs = 1;
 
                request->pakfire = pakfire_ref(pakfire);
@@ -65,7 +65,7 @@ PAKFIRE_EXPORT PakfireRequest pakfire_request_ref(PakfireRequest request) {
 }
 
 static void pakfire_request_free(PakfireRequest request) {
-       pakfire_unref(request->pakfire);
+       DEBUG(request->pakfire, "Releasing Request at %p\n", request);
 
        if (request->transaction)
                transaction_free(request->transaction);
@@ -74,9 +74,9 @@ static void pakfire_request_free(PakfireRequest request) {
                solver_free(request->solver);
 
        queue_free(&request->queue);
-       pakfire_free(request);
 
-       DEBUG("Released Request at %p\n", request);
+       pakfire_unref(request->pakfire);
+       pakfire_free(request);
 }
 
 PAKFIRE_EXPORT PakfireRequest pakfire_request_unref(PakfireRequest request) {
@@ -90,6 +90,10 @@ PAKFIRE_EXPORT PakfireRequest pakfire_request_unref(PakfireRequest request) {
        return NULL;
 }
 
+Pakfire pakfire_request_get_pakfire(PakfireRequest request) {
+       return pakfire_ref(request->pakfire);
+}
+
 Solver* pakfire_request_get_solver(PakfireRequest request) {
        return request->solver;
 }
@@ -149,7 +153,7 @@ static int solve(PakfireRequest request, Queue* queue) {
        // Save time when we finished solving
        clock_t solving_end = clock();
 
-       DEBUG("Solved request in %.4fms\n",
+       DEBUG(request->pakfire, "Solved request in %.4fms\n",
                (double)(solving_end - solving_start) * 1000 / CLOCKS_PER_SEC);
 
        /* If the solving process was successful, we get the transaction
index d185b250b6b36843af47688510739ce9683e1e40..91450aac5372bbfdf1ecfd1e41ad02631731804a 100644 (file)
@@ -47,7 +47,7 @@ struct _PakfireSelector {
 PAKFIRE_EXPORT PakfireSelector pakfire_selector_create(Pakfire pakfire) {
        PakfireSelector selector = pakfire_calloc(1, sizeof(*selector));
        if (selector) {
-               DEBUG("Allocated Selector at %p\n", selector);
+               DEBUG(pakfire, "Allocated Selector at %p\n", selector);
                selector->nrefs = 1;
 
                selector->pakfire = pakfire_ref(pakfire);
@@ -68,10 +68,10 @@ PAKFIRE_EXPORT PakfireSelector pakfire_selector_ref(PakfireSelector selector) {
 }
 
 static void pakfire_selector_free(PakfireSelector selector) {
+       DEBUG(selector->pakfire, "Releasing Selector at %p\n", selector);
+
        pakfire_unref(selector->pakfire);
        pakfire_free(selector);
-
-       DEBUG("Released Selector at %p\n", selector);
 }
 
 PAKFIRE_EXPORT PakfireSelector pakfire_selector_unref(PakfireSelector selector) {
index 403fc60ddcc3eda515caa3eaee4b06ba6bb8b574..d659eee2c803f5b00748076fff3f0399068ee764 100644 (file)
@@ -32,6 +32,7 @@
 #include <pakfire/util.h>
 
 struct _PakfireSolution {
+       Pakfire pakfire;
        PakfireProblem problem;
        Id id;
        char** elements;
@@ -119,9 +120,12 @@ static void import_elements(PakfireSolution solution) {
 }
 
 PAKFIRE_EXPORT PakfireSolution pakfire_solution_create(PakfireProblem problem, Id id) {
+       Pakfire pakfire = pakfire_problem_get_pakfire(problem);
+
        PakfireSolution solution = pakfire_calloc(1, sizeof(*solution));
        if (solution) {
-               DEBUG("Allocated Solution at %p\n", solution);
+               DEBUG(pakfire, "Allocated Solution at %p\n", solution);
+               solution->pakfire = pakfire_ref(pakfire);
                solution->nrefs = 1;
 
                solution->problem = pakfire_problem_ref(problem);
@@ -131,6 +135,8 @@ PAKFIRE_EXPORT PakfireSolution pakfire_solution_create(PakfireProblem problem, I
                import_elements(solution);
        }
 
+       pakfire_unref(pakfire);
+
        return solution;
 }
 
@@ -141,6 +147,9 @@ PAKFIRE_EXPORT PakfireSolution pakfire_solution_ref(PakfireSolution solution) {
 }
 
 static void pakfire_solution_free(PakfireSolution solution) {
+       DEBUG(solution->pakfire, "Releasing Solution at %p\n", solution);
+       pakfire_unref(solution->pakfire);
+
        if (solution->next)
                pakfire_solution_unref(solution->next);
 
@@ -151,7 +160,6 @@ static void pakfire_solution_free(PakfireSolution solution) {
                        pakfire_free(*solution->elements++);
 
        pakfire_free(solution);
-       DEBUG("Released Solution at %p\n", solution);
 }
 
 PAKFIRE_EXPORT PakfireSolution pakfire_solution_unref(PakfireSolution solution) {
index f3df4b9b9d665d211496471910fe12e71864d855..d1c6eafd99742ad06e8b74ffa2fecfaa7e6e3df3 100644 (file)
@@ -78,20 +78,23 @@ static pakfire_step_type_t get_type(Transaction* transaction, Id id) {
 }
 
 PAKFIRE_EXPORT PakfireStep pakfire_step_create(PakfireTransaction transaction, Id id) {
+       Pakfire pakfire = pakfire_transaction_get_pakfire(transaction);
        Transaction* t = pakfire_transaction_get_transaction(transaction);
 
        PakfireStep step = pakfire_calloc(1, sizeof(*step));
        if (step) {
-               DEBUG("Allocated Step at %p\n", step);
+               DEBUG(pakfire, "Allocated Step at %p\n", step);
+               step->pakfire = pakfire_ref(pakfire);
                step->nrefs = 1;
 
-               step->pakfire = pakfire_transaction_get_pakfire(transaction);
                step->type = get_type(t, id);
 
                // Get the package
                step->package = pakfire_package_create(step->pakfire, id);
        }
 
+       pakfire_unref(pakfire);
+
        return step;
 }
 
@@ -102,11 +105,11 @@ PAKFIRE_EXPORT PakfireStep pakfire_step_ref(PakfireStep step) {
 }
 
 static void pakfire_step_free(PakfireStep step) {
+       DEBUG(step->pakfire, "Releasing Step at %p\n", step);
+
        pakfire_package_unref(step->package);
        pakfire_unref(step->pakfire);
        pakfire_free(step);
-
-       DEBUG("Released Step at %p\n", step);
 }
 
 PAKFIRE_EXPORT PakfireStep pakfire_step_unref(PakfireStep step) {
@@ -224,7 +227,8 @@ static int pakfire_step_verify(PakfireStep step) {
                char* nevra = pakfire_package_get_nevra(step->package);
                char* cache_path = pakfire_package_get_cache_path(step->package);
 
-               ERROR("Could not open package archive for %s: %s\n", nevra, cache_path);
+               ERROR(step->pakfire, "Could not open package archive for %s: %s\n",
+                       nevra, cache_path);
 
                pakfire_free(nevra);
                pakfire_free(cache_path);
@@ -253,7 +257,7 @@ static int pakfire_step_erase(PakfireStep step) {
 }
 
 PAKFIRE_EXPORT int pakfire_step_run(PakfireStep step, const pakfire_action_type_t action) {
-       DEBUG("Running Step %p (%s)\n", step, pakfire_action_type_string(action));
+       DEBUG(step->pakfire, "Running Step %p (%s)\n", step, pakfire_action_type_string(action));
 
        pakfire_step_type_t type = pakfire_step_get_type(step);
 
index 249e6d6067a4a87706c5805587ecc80477038600..751ceba1a72731fceed4dd629a3d9ccb8c80f7ae 100644 (file)
@@ -44,7 +44,7 @@ struct _PakfireTransaction {
 PAKFIRE_EXPORT PakfireTransaction pakfire_transaction_create(Pakfire pakfire, Transaction* trans) {
        PakfireTransaction transaction = pakfire_calloc(1, sizeof(*transaction));
        if (transaction) {
-               DEBUG("Allocated Transaction at %p\n", transaction);
+               DEBUG(pakfire, "Allocated Transaction at %p\n", transaction);
                transaction->nrefs = 1;
 
                transaction->pakfire = pakfire_ref(pakfire);
@@ -78,6 +78,7 @@ PAKFIRE_EXPORT PakfireTransaction pakfire_transaction_ref(PakfireTransaction tra
 }
 
 void pakfire_transaction_free(PakfireTransaction transaction) {
+       DEBUG(transaction->pakfire, "Releasing Transaction at %p\n", transaction);
        pakfire_unref(transaction->pakfire);
 
        // Release all steps
@@ -86,8 +87,6 @@ void pakfire_transaction_free(PakfireTransaction transaction) {
 
        transaction_free(transaction->transaction);
        pakfire_free(transaction);
-
-       DEBUG("Released Transaction at %p\n", transaction);
 }
 
 PAKFIRE_EXPORT PakfireTransaction pakfire_transaction_unref(PakfireTransaction transaction) {
@@ -146,7 +145,7 @@ PAKFIRE_EXPORT PakfireStep pakfire_transaction_get_step(PakfireTransaction trans
 }
 
 PAKFIRE_EXPORT PakfirePackageList pakfire_transaction_get_packages(PakfireTransaction transaction, pakfire_step_type_t type) {
-       PakfirePackageList packagelist = pakfire_packagelist_create();
+       PakfirePackageList packagelist = pakfire_packagelist_create(transaction->pakfire);
 
        PakfireStep* steps = transaction->steps;
        while (*steps) {
@@ -306,7 +305,7 @@ PAKFIRE_EXPORT char* pakfire_transaction_dump(PakfireTransaction transaction, si
        if (l > 0 && string[l] == '\n')
                string[l] = '\0';
 
-       DEBUG("Transaction: %s\n", string);
+       DEBUG(transaction->pakfire, "Transaction: %s\n", string);
 
        return string;
 }
@@ -331,7 +330,7 @@ static int pakfire_transaction_run_steps(PakfireTransaction transaction, const p
 }
 
 PAKFIRE_EXPORT int pakfire_transaction_run(PakfireTransaction transaction) {
-       DEBUG("Running Transaction %p\n", transaction);
+       DEBUG(transaction->pakfire, "Running Transaction %p\n", transaction);
 
        int r = 0;
 
@@ -354,7 +353,7 @@ PAKFIRE_EXPORT int pakfire_transaction_run(PakfireTransaction transaction) {
        if (r)
                return r;
 
-       DEBUG("Transaction %p has finished successfully\n", transaction);
+       DEBUG(transaction->pakfire, "Transaction %p has finished successfully\n", transaction);
 
        return 0;
 }
index da7d93e4652c109e9b196ec08195aac1d1da9aa2..50d252d176aae5cf040102737a747c5a81bbb611 100644 (file)
@@ -156,23 +156,23 @@ char* pakfire_dirname(const char* path) {
        return dirname(parent);
 }
 
-PAKFIRE_EXPORT int pakfire_access(const char* dir, const char* file, int mode) {
+PAKFIRE_EXPORT int pakfire_access(Pakfire pakfire, const char* dir, const char* file, int mode) {
        char* path = pakfire_path_join(dir, file);
 
        int r = access(path, mode);
 
        if (r) {
                if (mode & R_OK)
-                       DEBUG("%s is not readable\n", path);
+                       DEBUG(pakfire, "%s is not readable\n", path);
 
                if (mode & W_OK)
-                       DEBUG("%s is not writable\n", path);
+                       DEBUG(pakfire, "%s is not writable\n", path);
 
                if (mode & X_OK)
-                       DEBUG("%s is not executable\n", path);
+                       DEBUG(pakfire, "%s is not executable\n", path);
 
                if (mode & F_OK)
-                       DEBUG("%s does not exist\n", path);
+                       DEBUG(pakfire, "%s does not exist\n", path);
        }
 
        pakfire_free(path);
@@ -180,7 +180,7 @@ PAKFIRE_EXPORT int pakfire_access(const char* dir, const char* file, int mode) {
        return r;
 }
 
-int pakfire_mkdir(const char* path, mode_t mode) {
+int pakfire_mkdir(Pakfire pakfire, const char* path, mode_t mode) {
        int r = 0;
 
        if ((strcmp(path, "/") == 0) || (strcmp(path, ".") == 0))
@@ -188,9 +188,9 @@ int pakfire_mkdir(const char* path, mode_t mode) {
 
        // If parent does not exists, we try to create it.
        char* parent = pakfire_dirname(path);
-       r = pakfire_access(parent, NULL, F_OK);
+       r = pakfire_access(pakfire, parent, NULL, F_OK);
        if (r)
-               r = pakfire_mkdir(parent, 0);
+               r = pakfire_mkdir(pakfire, parent, 0);
 
        pakfire_free(parent);