#define BLOCKSIZE 1024 * 1024 // 1MB
typedef struct archive_checksum {
+ Pakfire pakfire;
char* filename;
char* checksum;
archive_checksum_algo_t algo;
};
struct _PakfireArchiveSignature {
+ Pakfire pakfire;
PakfireKey key;
char* sigdata;
int nrefs;
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);
}
}
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);
}
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);
}
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;
}
}
static void pakfire_archive_free(PakfireArchive archive) {
+ DEBUG(archive->pakfire, "Releasing archive at %p\n", archive);
+
if (archive->path)
pakfire_free(archive->path);
}
pakfire_unref(archive->pakfire);
-
- DEBUG("Released archive at %p\n", archive);
pakfire_free(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);
}
// 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
struct archive_entry* entry;
int r;
+#if 0
DEBUG("Extracting archive to %s\n", prefix);
+#endif
struct archive* ext = archive_write_disk_new();
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);
}
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);
}
// 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;
}
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;
}
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
// 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);
}
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);
#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,
#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
#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);
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>
#include <solv/pooltypes.h>
+Pakfire pakfire_problem_get_pakfire(PakfireProblem problem);
Id pakfire_problem_get_id(PakfireProblem problem);
#endif
#include <solv/solver.h>
+Pakfire pakfire_request_get_pakfire(PakfireRequest request);
Solver* pakfire_request_get_solver(PakfireRequest request);
#endif
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);
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);
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;
}
}
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;
gpgme_release(ctx);
error_string = gpgme_strerror(error);
- ERROR("%s\n", error_string);
+ ERROR(pakfire, "%s\n", error_string);
return NULL;
}
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;
}
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;
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;
}
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;
}
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;
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;
// 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;
}
# #
#############################################################################*/
-#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);
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;
}
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) {
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);
#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;
}
}
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) {
}
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;
# #
#############################################################################*/
+#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>
};
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;
}
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();
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);
pakfire_free(pakfire);
- DEBUG("Pakfire released at %p\n", pakfire);
-
return NULL;
}
}
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;
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);
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);
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);
}
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;
// 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;
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;
+}
#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>
#include <pakfire/util.h>
struct _PakfireProblem {
+ Pakfire pakfire;
PakfireRequest request;
Id id;
char* string;
}
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);
problem->string = to_string(problem);
}
+ pakfire_unref(pakfire);
+
return 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) {
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;
}
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);
}
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) {
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);
}
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) {
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);
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);
}
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) {
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);
}
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);
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) {
return NULL;
}
+Pakfire pakfire_request_get_pakfire(PakfireRequest request) {
+ return pakfire_ref(request->pakfire);
+}
+
Solver* pakfire_request_get_solver(PakfireRequest request) {
return request->solver;
}
// 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
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);
}
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) {
#include <pakfire/util.h>
struct _PakfireSolution {
+ Pakfire pakfire;
PakfireProblem problem;
Id id;
char** elements;
}
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);
import_elements(solution);
}
+ pakfire_unref(pakfire);
+
return 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);
pakfire_free(*solution->elements++);
pakfire_free(solution);
- DEBUG("Released Solution at %p\n", solution);
}
PAKFIRE_EXPORT PakfireSolution pakfire_solution_unref(PakfireSolution solution) {
}
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;
}
}
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) {
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);
}
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);
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);
}
void pakfire_transaction_free(PakfireTransaction transaction) {
+ DEBUG(transaction->pakfire, "Releasing Transaction at %p\n", transaction);
pakfire_unref(transaction->pakfire);
// Release all steps
transaction_free(transaction->transaction);
pakfire_free(transaction);
-
- DEBUG("Released Transaction at %p\n", transaction);
}
PAKFIRE_EXPORT PakfireTransaction pakfire_transaction_unref(PakfireTransaction transaction) {
}
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) {
if (l > 0 && string[l] == '\n')
string[l] = '\0';
- DEBUG("Transaction: %s\n", string);
+ DEBUG(transaction->pakfire, "Transaction: %s\n", string);
return string;
}
}
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;
if (r)
return r;
- DEBUG("Transaction %p has finished successfully\n", transaction);
+ DEBUG(transaction->pakfire, "Transaction %p has finished successfully\n", transaction);
return 0;
}
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);
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))
// 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);