From: Michael Tremer Date: Mon, 29 Jan 2024 16:49:22 +0000 (+0000) Subject: libpakfire: Move to new logging in pakfire.c X-Git-Tag: 0.9.30~1237 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01131e770744f5841f1ab2c8c1a9cf697c1e9f92;p=pakfire.git libpakfire: Move to new logging in pakfire.c Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 072ba8f93..2430c7897 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -183,7 +183,7 @@ static unsigned int pakfire_map_id(struct pakfire* pakfire, // Check if the ID is in range if (id > subid->length) { - ERROR(pakfire, "Mapped ID is out of range. Setting to %u\n", subid->id); + CTX_ERROR(pakfire->ctx, "Mapped ID is out of range. Setting to %u\n", subid->id); mapped_id = subid->id; } @@ -201,7 +201,7 @@ static unsigned int pakfire_unmap_id(struct pakfire* pakfire, // Check if the ID is in range if (unmapped_id < 0) { - ERROR(pakfire, "Mapped ID is out of range. Setting to %u\n", subid->id); + CTX_ERROR(pakfire->ctx, "Mapped ID is out of range. Setting to %u\n", subid->id); unmapped_id = subid->id; } @@ -211,7 +211,7 @@ static unsigned int pakfire_unmap_id(struct pakfire* pakfire, static void pool_log(Pool* pool, void* data, int type, const char* s) { struct pakfire* pakfire = (struct pakfire*)data; - DEBUG(pakfire, "pool: %s", s); + CTX_DEBUG(pakfire->ctx, "pool: %s", s); } static Id pakfire_handle_ns_pakfire(struct pakfire* pakfire, const char* name) { @@ -237,7 +237,7 @@ static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) { const char* namespace = pool_id2str(pool, ns); const char* name = pakfire_dep2str(pakfire, id); - DEBUG(pakfire, "Namespace callback called for %s(%s)\n", namespace, name); + CTX_DEBUG(pakfire->ctx, "Namespace callback called for %s(%s)\n", namespace, name); // Handle the pakfire() namespace if (strcmp(namespace, "pakfire") == 0) @@ -259,11 +259,11 @@ static int pakfire_lock_running_kernel(struct pakfire* pakfire) { // Call uname() int r = uname(&utsname); if (r) { - ERROR(pakfire, "uname() failed: %m\n"); + CTX_ERROR(pakfire->ctx, "uname() failed: %m\n"); return r; } - DEBUG(pakfire, "Locking running kernel %s\n", utsname.release); + CTX_DEBUG(pakfire->ctx, "Locking running kernel %s\n", utsname.release); r = pakfire_string_format(buffer, "kernel(%s)", utsname.release); if (r) @@ -292,7 +292,7 @@ static int pakfire_populate_pool(struct pakfire* pakfire) { #ifdef ENABLE_DEBUG // Enable debug output - //pool_setdebuglevel(pool, 3); + pool_setdebuglevel(pool, 3); #endif // Set architecture of the pool @@ -388,7 +388,7 @@ static void pakfire_free(struct pakfire* pakfire) { if (repo) { r = pakfire_repo_clean(repo, PAKFIRE_REPO_CLEAN_FLAGS_DESTROY); if (r) - ERROR(pakfire, "Could not cleanup %s repository: %m\n", PAKFIRE_REPO_COMMANDLINE); + CTX_ERROR(pakfire->ctx, "Could not cleanup %s repository: %m\n", PAKFIRE_REPO_COMMANDLINE); pakfire_repo_unref(repo); } @@ -401,12 +401,12 @@ static void pakfire_free(struct pakfire* pakfire) { pakfire_release_lock(pakfire); if (pakfire->destroy_on_free && *pakfire->path) { - DEBUG(pakfire, "Destroying %s\n", pakfire->path); + CTX_DEBUG(pakfire->ctx, "Destroying %s\n", pakfire->path); // Umount the ramdisk r = umount2(pakfire->path, MNT_DETACH); if (r) - ERROR(pakfire, "Could not umount ramdisk at %s: %m\n", pakfire->path); + CTX_ERROR(pakfire->ctx, "Could not umount ramdisk at %s: %m\n", pakfire->path); // Destroy the temporary directory pakfire_rmtree(pakfire->path, 0); @@ -434,13 +434,13 @@ static int pakfire_safety_checks(struct pakfire* pakfire) { // We must be root in order to operate in / if (pakfire->user.uid) { - ERROR(pakfire, "Must be running as root on /\n"); + CTX_ERROR(pakfire->ctx, "Must be running as root on /\n"); errno = EPERM; return 1; } if (strcmp(pakfire->distro.id, "ipfire") != 0) { - ERROR(pakfire, "Not an IPFire system\n"); + CTX_ERROR(pakfire->ctx, "Not an IPFire system\n"); errno = EPERM; return 1; } @@ -482,7 +482,7 @@ static int pakfire_read_repo_config(struct pakfire* pakfire) { if (r) return r; - DEBUG(pakfire, "Reading repository configuration from %s\n", path); + CTX_DEBUG(pakfire->ctx, "Reading repository configuration from %s\n", path); // Open path DIR* dir = opendir(path); @@ -492,7 +492,7 @@ static int pakfire_read_repo_config(struct pakfire* pakfire) { return 0; default: - ERROR(pakfire, "Could not open %s: %m\n", path); + CTX_ERROR(pakfire->ctx, "Could not open %s: %m\n", path); return -errno; } } @@ -637,13 +637,13 @@ static int pakfire_config_import_distro(struct pakfire* pakfire) { static int pakfire_read_config(struct pakfire* pakfire, FILE* f) { int r; - DEBUG(pakfire, "Reading configuration\n"); + CTX_DEBUG(pakfire->ctx, "Reading configuration\n"); // Read configuration from file if (f) { r = pakfire_config_read(pakfire->config, f); if (r) { - ERROR(pakfire, "Could not parse configuration: %m\n"); + CTX_ERROR(pakfire->ctx, "Could not parse configuration: %m\n"); return r; } } @@ -800,14 +800,14 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* // Determine the effective architecture p->arches.effective = pakfire_arch_is_supported_by_host(arch); if (!p->arches.effective) { - ERROR(p, "Unsupported architecture: %s\n", arch); + CTX_ERROR(p->ctx, "Unsupported architecture: %s\n", arch); r = errno; goto ERROR; } // Path must be absolute if (path && !pakfire_string_startswith(path, "/")) { - ERROR(p, "Invalid path: %s\n", path); + CTX_ERROR(p->ctx, "Invalid path: %s\n", path); r = -EINVAL; goto ERROR; } @@ -848,15 +848,15 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* if (r) goto ERROR; - DEBUG(p, "Pakfire initialized at %p\n", p); - DEBUG(p, " user = %s (%u)\n", p->user.name, p->user.uid); - DEBUG(p, " group = %s (%u)\n", p->group.name, p->group.gid); - DEBUG(p, " arch = %s (%s)\n", pakfire_get_arch(p), pakfire_get_effective_arch(p)); - DEBUG(p, " path = %s\n", pakfire_get_path(p)); + CTX_DEBUG(p->ctx, "Pakfire initialized at %p\n", p); + CTX_DEBUG(p->ctx, " user = %s (%u)\n", p->user.name, p->user.uid); + CTX_DEBUG(p->ctx, " group = %s (%u)\n", p->group.name, p->group.gid); + CTX_DEBUG(p->ctx, " arch = %s (%s)\n", pakfire_get_arch(p), pakfire_get_effective_arch(p)); + CTX_DEBUG(p->ctx, " path = %s\n", pakfire_get_path(p)); if (p->user.subuids.id) - DEBUG(p, " subuid = %u (%zu)\n", p->user.subuids.id, p->user.subuids.length); + CTX_DEBUG(p->ctx, " subuid = %u (%zu)\n", p->user.subuids.id, p->user.subuids.length); if (p->group.subgids.id) - DEBUG(p, " subgid = %u (%zu)\n", p->group.subgids.id, p->group.subgids.length); + CTX_DEBUG(p->ctx, " subgid = %u (%zu)\n", p->group.subgids.id, p->group.subgids.length); // Perform some safety checks r = pakfire_safety_checks(p); @@ -869,29 +869,29 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* goto ERROR; // Dump distribution configuration - DEBUG(p, " Distribution: %s\n", p->distro.pretty_name); - DEBUG(p, " name = %s\n", p->distro.name); - DEBUG(p, " id = %s\n", p->distro.id); - DEBUG(p, " version = %s\n", p->distro.version); - DEBUG(p, " version_id = %s\n", p->distro.version_id); + CTX_DEBUG(p->ctx, " Distribution: %s\n", p->distro.pretty_name); + CTX_DEBUG(p->ctx, " name = %s\n", p->distro.name); + CTX_DEBUG(p->ctx, " id = %s\n", p->distro.id); + CTX_DEBUG(p->ctx, " version = %s\n", p->distro.version); + CTX_DEBUG(p->ctx, " version_id = %s\n", p->distro.version_id); if (*p->distro.version_codename) - DEBUG(p, " codename = %s\n", p->distro.version_codename); + CTX_DEBUG(p->ctx, " codename = %s\n", p->distro.version_codename); if (*p->distro.vendor) - DEBUG(p, " vendor = %s\n", p->distro.vendor); + CTX_DEBUG(p->ctx, " vendor = %s\n", p->distro.vendor); if (*p->distro.slogan) - DEBUG(p, " slogan = %s\n", p->distro.slogan); + CTX_DEBUG(p->ctx, " slogan = %s\n", p->distro.slogan); // Set lock path r = pakfire_path(p, p->lock_path, "%s", LOCK_PATH); if (r) { - ERROR(p, "Could not set lock path: %m\n"); + CTX_ERROR(p->ctx, "Could not set lock path: %m\n"); goto ERROR; } // Set cache path r = pakfire_set_cache_path(p); if (r) { - ERROR(p, "Could not set cache path: %m\n"); + CTX_ERROR(p->ctx, "Could not set cache path: %m\n"); goto ERROR; } @@ -903,7 +903,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* // Make sure that our private directory exists r = pakfire_mkdir(private_dir, 0755); if (r) { - ERROR(p, "Could not create private directory %s: %m\n", private_dir); + CTX_ERROR(p->ctx, "Could not create private directory %s: %m\n", private_dir); goto ERROR; } @@ -966,11 +966,11 @@ int pakfire_acquire_lock(struct pakfire* pakfire) { // Check if the lock is already held if (pakfire->lock) { - ERROR(pakfire, "Lock is already been acquired by this process\n"); + CTX_ERROR(pakfire->ctx, "Lock is already been acquired by this process\n"); return -ENOLCK; } - DEBUG(pakfire, "Acquire lock...\n"); + CTX_DEBUG(pakfire->ctx, "Acquire lock...\n"); // Ensure the parent directory exists pakfire_mkparentdir(pakfire->lock_path, 0755); @@ -978,7 +978,7 @@ int pakfire_acquire_lock(struct pakfire* pakfire) { // Open the lock file pakfire->lock = fopen(pakfire->lock_path, "w"); if (!pakfire->lock) { - ERROR(pakfire, "Could not open lock file %s: %m\n", pakfire->lock_path); + CTX_ERROR(pakfire->ctx, "Could not open lock file %s: %m\n", pakfire->lock_path); return -errno; } @@ -990,14 +990,14 @@ int pakfire_acquire_lock(struct pakfire* pakfire) { if (r == 0) goto SUCCESS; - DEBUG(pakfire, "Could not acquire lock %s: %m\n", pakfire->lock_path); + CTX_DEBUG(pakfire->ctx, "Could not acquire lock %s: %m\n", pakfire->lock_path); // Wait 500ms until the next attempt usleep(500000); } SUCCESS: - DEBUG(pakfire, "Lock acquired\n"); + CTX_DEBUG(pakfire->ctx, "Lock acquired\n"); return 0; } @@ -1006,7 +1006,7 @@ void pakfire_release_lock(struct pakfire* pakfire) { if (!pakfire->lock) return; - DEBUG(pakfire, "Releasing lock\n"); + CTX_DEBUG(pakfire->ctx, "Releasing lock\n"); fclose(pakfire->lock); pakfire->lock = NULL; @@ -1065,14 +1065,14 @@ magic_t pakfire_get_magic(struct pakfire* pakfire) { // Allocate a new context pakfire->magic = magic_open(MAGIC_MIME_TYPE | MAGIC_ERROR | MAGIC_NO_CHECK_TOKENS); if (!pakfire->magic) { - ERROR(pakfire, "Could not allocate magic context: %m\n"); + CTX_ERROR(pakfire->ctx, "Could not allocate magic context: %m\n"); return NULL; } // Load the database r = magic_load(pakfire->magic, NULL); if (r) { - ERROR(pakfire, "Could not open the magic database: %s\n", + CTX_ERROR(pakfire->ctx, "Could not open the magic database: %s\n", magic_error(pakfire->magic)); goto ERROR; } @@ -1297,7 +1297,7 @@ int pakfire_commandline_add(struct pakfire* pakfire, const char* path, // Find the commandline repository repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_COMMANDLINE); if (!repo) { - ERROR(pakfire, "Could not find the commandline repository: %m\n"); + CTX_ERROR(pakfire->ctx, "Could not find the commandline repository: %m\n"); return 1; } @@ -1522,16 +1522,16 @@ static const char* pakfire_user_lookup(void* data, la_int64_t uid) { if (uid == 0) return "root"; - DEBUG(pakfire, "Looking up name for UID %ld\n", uid); + CTX_DEBUG(pakfire->ctx, "Looking up name for UID %ld\n", uid); // Find a matching entry in /etc/passwd struct passwd* entry = pakfire_getpwuid(pakfire, uid); if (!entry) { - ERROR(pakfire, "Could not retrieve uname for %ld: %m\n", uid); + CTX_ERROR(pakfire->ctx, "Could not retrieve uname for %ld: %m\n", uid); return 0; } - DEBUG(pakfire, "Mapping UID %ld to %s\n", uid, entry->pw_name); + CTX_DEBUG(pakfire->ctx, "Mapping UID %ld to %s\n", uid, entry->pw_name); return entry->pw_name; } @@ -1546,16 +1546,16 @@ static const char* pakfire_group_lookup(void* data, la_int64_t gid) { if (gid == 0) return "root"; - DEBUG(pakfire, "Looking up name for GID %ld\n", gid); + CTX_DEBUG(pakfire->ctx, "Looking up name for GID %ld\n", gid); // Find a matching entry in /etc/group struct group* entry = pakfire_getgrgid(pakfire, gid); if (!entry) { - ERROR(pakfire, "Could not retrieve gname for %ld: %m\n", gid); + CTX_ERROR(pakfire->ctx, "Could not retrieve gname for %ld: %m\n", gid); return 0; } - DEBUG(pakfire, "Mapping GID %ld to %s\n", gid, entry->gr_name); + CTX_DEBUG(pakfire->ctx, "Mapping GID %ld to %s\n", gid, entry->gr_name); return entry->gr_name; } @@ -1568,7 +1568,7 @@ struct archive* pakfire_make_archive_disk_reader(struct pakfire* pakfire, int in // Do not read fflags int r = archive_read_disk_set_behavior(archive, ARCHIVE_READDISK_NO_FFLAGS); if (r) { - ERROR(pakfire, "Could not change behavior of reader: %s\n", + CTX_ERROR(pakfire->ctx, "Could not change behavior of reader: %s\n", archive_error_string(archive)); archive_read_free(archive); return NULL; @@ -1592,16 +1592,16 @@ static la_int64_t pakfire_uid_lookup(void* data, const char* name, la_int64_t ui if (strcmp(name, "root") == 0) return pakfire_map_id(pakfire, &pakfire->user.subuids, 0); - DEBUG(pakfire, "Looking up UID for '%s' (%ld)\n", name, uid); + CTX_DEBUG(pakfire->ctx, "Looking up UID for '%s' (%ld)\n", name, uid); // Find a matching entry in /etc/passwd struct passwd* entry = pakfire_getpwnam(pakfire, name); if (!entry) { - ERROR(pakfire, "Could not retrieve UID for '%s': %m\n", name); + CTX_ERROR(pakfire->ctx, "Could not retrieve UID for '%s': %m\n", name); return pakfire_map_id(pakfire, &pakfire->user.subuids, 0); } - DEBUG(pakfire, "Mapping %s to UID %u\n", name, entry->pw_uid); + CTX_DEBUG(pakfire->ctx, "Mapping %s to UID %u\n", name, entry->pw_uid); return pakfire_map_id(pakfire, &pakfire->user.subuids, entry->pw_uid); } @@ -1613,16 +1613,16 @@ static la_int64_t pakfire_gid_lookup(void* data, const char* name, la_int64_t gi if (strcmp(name, "root") == 0) return pakfire_map_id(pakfire, &pakfire->group.subgids, 0); - DEBUG(pakfire, "Looking up GID for '%s' (%ld)\n", name, gid); + CTX_DEBUG(pakfire->ctx, "Looking up GID for '%s' (%ld)\n", name, gid); // Find a matching entry in /etc/group struct group* entry = pakfire_getgrnam(pakfire, name); if (!entry) { - ERROR(pakfire, "Could not retrieve GID for '%s': %m\n", name); + CTX_ERROR(pakfire->ctx, "Could not retrieve GID for '%s': %m\n", name); return pakfire_map_id(pakfire, &pakfire->group.subgids, 0); } - DEBUG(pakfire, "Mapping %s to GID %u\n", name, entry->gr_gid); + CTX_DEBUG(pakfire->ctx, "Mapping %s to GID %u\n", name, entry->gr_gid); return pakfire_map_id(pakfire, &pakfire->group.subgids, entry->gr_gid); }