// 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;
}
// 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;
}
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) {
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)
// 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)
#ifdef ENABLE_DEBUG
// Enable debug output
- //pool_setdebuglevel(pool, 3);
+ pool_setdebuglevel(pool, 3);
#endif
// Set architecture of the pool
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);
}
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);
// 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;
}
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);
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;
}
}
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;
}
}
// 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;
}
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);
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;
}
// 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;
}
// 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);
// 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;
}
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;
}
if (!pakfire->lock)
return;
- DEBUG(pakfire, "Releasing lock\n");
+ CTX_DEBUG(pakfire->ctx, "Releasing lock\n");
fclose(pakfire->lock);
pakfire->lock = NULL;
// 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;
}
// 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;
}
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;
}
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;
}
// 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;
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);
}
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);
}