goto ERROR;
default:
- CTX_ERROR(archive->ctx, "Could not open archive %s: %s\n",
+ ERROR(archive->ctx, "Could not open archive %s: %s\n",
archive->path, archive_error_string(a));
goto ERROR;
}
r = pakfire_digests_compute_from_file(archive->ctx, &archive->digests,
PAKFIRE_ARCHIVE_CHECKSUM, archive->f);
if (r)
- CTX_ERROR(archive->ctx, "Could not calculate digest of %s: %m\n", archive->path);
+ ERROR(archive->ctx, "Could not calculate digest of %s: %m\n", archive->path);
return r;
}
break;
case PAKFIRE_WALK_END:
- CTX_DEBUG(archive->ctx, "Filter callback sent END\n");
+ DEBUG(archive->ctx, "Filter callback sent END\n");
return 0;
case PAKFIRE_WALK_SKIP:
- CTX_DEBUG(archive->ctx, "Filter callback sent SKIP\n");
+ DEBUG(archive->ctx, "Filter callback sent SKIP\n");
continue;
case PAKFIRE_WALK_DONE:
- CTX_DEBUG(archive->ctx, "Filter callback sent DONE\n");
+ DEBUG(archive->ctx, "Filter callback sent DONE\n");
// Clear the callback function
filter_callback = NULL;
break;
case PAKFIRE_WALK_AGAIN:
- CTX_DEBUG(archive->ctx, "Filter callback sent AGAIN\n");
+ DEBUG(archive->ctx, "Filter callback sent AGAIN\n");
return -EAGAIN;
// Raise any other errors
default:
- CTX_DEBUG(archive->ctx, "Filter callback returned an error: %d\n", r);
+ DEBUG(archive->ctx, "Filter callback returned an error: %d\n", r);
return r;
}
}
break;
case PAKFIRE_WALK_DONE:
- CTX_DEBUG(archive->ctx, "Callback sent DONE\n");
+ DEBUG(archive->ctx, "Callback sent DONE\n");
return 0;
// Raise any other errors
// Create tokener
struct json_tokener* tokener = json_tokener_new();
if (!tokener) {
- CTX_ERROR(archive->ctx, "Could not allocate JSON tokener: %m\n");
+ ERROR(archive->ctx, "Could not allocate JSON tokener: %m\n");
goto ERROR;
}
if (!archive->metadata) {
enum json_tokener_error error = json_tokener_get_error(tokener);
- CTX_ERROR(archive->ctx, "JSON parsing error: %s\n",
+ ERROR(archive->ctx, "JSON parsing error: %s\n",
json_tokener_error_desc(error));
goto ERROR;
}
- CTX_DEBUG(archive->ctx, "Successfully parsed package metadata:\n%s\n",
+ DEBUG(archive->ctx, "Successfully parsed package metadata:\n%s\n",
json_object_to_json_string_ext(archive->metadata,
JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_PRETTY_TAB));
const char* data, const size_t length) {
// Check if format has already been set
if (archive->format) {
- CTX_ERROR(archive->ctx, "Archive format has already been parsed\n");
+ ERROR(archive->ctx, "Archive format has already been parsed\n");
return -EINVAL;
}
// Break on anything else
default:
- CTX_ERROR(archive->ctx, "This version of Pakfire does not support "
+ ERROR(archive->ctx, "This version of Pakfire does not support "
"archive format %u\n", archive->format);
return -ENOTSUP;
}
// Check for any available space
if (archive->num_scriptlets >= MAX_SCRIPTLETS) {
- CTX_ERROR(archive->ctx, "Too many scriptlets\n");
+ ERROR(archive->ctx, "Too many scriptlets\n");
return -ENOBUFS;
}
// Determine type
type = pakfire_path_relpath(".scriptlets/", path);
if (!type) {
- CTX_ERROR(archive->ctx, "Could not determine the scriptlet type from '%s'\n", path);
+ ERROR(archive->ctx, "Could not determine the scriptlet type from '%s'\n", path);
return -EINVAL;
}
// Read the data into the buffer
bytes_read = archive_read_data(a, buffer, required_size);
if (bytes_read < required_size) {
- CTX_ERROR(archive->ctx, "Could not read from archive: %s\n", archive_error_string(a));
+ ERROR(archive->ctx, "Could not read from archive: %s\n", archive_error_string(a));
r = -errno;
goto ERROR;
}
const char* path = archive_entry_pathname(entry);
- CTX_DEBUG(archive->ctx, "Reading metadata file: %s\n", path);
+ DEBUG(archive->ctx, "Reading metadata file: %s\n", path);
// Load the file into memory
r = pakfire_archive_copy_data_to_buffer(archive, a, entry, &data, &length);
if (r) {
- CTX_ERROR(archive->ctx, "Could not read data from archive: %s\n", archive_error_string(a));
+ ERROR(archive->ctx, "Could not read data from archive: %s\n", archive_error_string(a));
goto ERROR;
}
if (r)
goto ERROR;
- CTX_DEBUG(archive->ctx, "Archive format is %u (%s using %s)\n",
+ DEBUG(archive->ctx, "Archive format is %u (%s using %s)\n",
archive->format, archive_format_name(a), archive_filter_name(a, 0));
}
static int pakfire_archive_read_metadata(struct pakfire_archive* archive) {
int r;
- CTX_DEBUG(archive->ctx, "Reading archive metadata...\n");
+ DEBUG(archive->ctx, "Reading archive metadata...\n");
// Check if the archive file actually has any contect
if (!archive->stat.st_size) {
- CTX_ERROR(archive->ctx, "Trying to open an empty archive file\n");
+ ERROR(archive->ctx, "Trying to open an empty archive file\n");
return -EINVAL;
}
// Check if we could successfully read something
if (!archive->format) {
- CTX_DEBUG(archive->ctx, "Archive has an unknown format\n");
+ DEBUG(archive->ctx, "Archive has an unknown format\n");
return -ENOMSG;
}
// Check if we have read some metadata
if (!archive->metadata) {
- CTX_DEBUG(archive->ctx, "Archive has no metadata\n");
+ DEBUG(archive->ctx, "Archive has no metadata\n");
return -ENOMSG;
}
if (r < 0)
goto ERROR;
- CTX_DEBUG(a->ctx, "Opening archive %s\n", a->path);
+ DEBUG(a->ctx, "Opening archive %s\n", a->path);
// Open the file (and keep the file descriptor open)
a->f = fopen(a->path, "r");
if (!a->f) {
- CTX_ERROR(a->ctx, "Could not open archive %s: %m\n", a->path);
+ ERROR(a->ctx, "Could not open archive %s: %m\n", a->path);
r = -errno;
goto ERROR;
}
// Call stat() on f
r = fstat(fileno(a->f), &a->stat);
if (r < 0) {
- CTX_ERROR(a->ctx, "Could not stat archive %s: %m\n", a->path);
+ ERROR(a->ctx, "Could not stat archive %s: %m\n", a->path);
r = -errno;
goto ERROR;
}
// Try finding a matching JSON object
r = json_object_object_get_ex(object, *key, &object);
if (!r) {
- CTX_DEBUG(archive->ctx, "Could not find JSON object at '%s': %m\n", *key);
+ DEBUG(archive->ctx, "Could not find JSON object at '%s': %m\n", *key);
break;
}
}
// Increment counter
if (++cookie->followed_symlinks >= MAX_FOLLOW_SYMLINKS) {
- CTX_ERROR(archive->ctx, "Reached maximum number of symlinks to follow\n");
+ ERROR(archive->ctx, "Reached maximum number of symlinks to follow\n");
return PAKFIRE_WALK_ERROR;
}
// Create a file descriptor
cookie->f = fopencookie(cookie, "r", pakfire_archive_read_functions);
if (!cookie->f) {
- CTX_ERROR(archive->ctx, "Could not open /%s: %m\n", cookie->path);
+ ERROR(archive->ctx, "Could not open /%s: %m\n", cookie->path);
return PAKFIRE_WALK_ERROR;
}
// Allocate a cookie
cookie = calloc(1, sizeof(*cookie));
if (!cookie) {
- CTX_ERROR(archive->ctx, "Could not allocate a cookie: %m\n");
+ ERROR(archive->ctx, "Could not allocate a cookie: %m\n");
goto ERROR;
}
// Store the path
r = pakfire_string_set(cookie->path, path);
if (r) {
- CTX_ERROR(archive->ctx, "Could not set path: %m\n");
+ ERROR(archive->ctx, "Could not set path: %m\n");
goto ERROR;
}
// Nothing found
if (!cookie->f) {
- CTX_ERROR(archive->ctx, "Could not find /%s\n", path);
+ ERROR(archive->ctx, "Could not find /%s\n", path);
// No such file or directory
errno = ENOENT;
if (size < 0)
return -EINVAL;
- CTX_DEBUG(archive->ctx, "Copying %s to %s...\n", archive->path, path);
+ DEBUG(archive->ctx, "Copying %s to %s...\n", archive->path, path);
// Ensure we copy from the very beginning
rewind(archive->f);
// Copy everything
ssize_t bytes_written = sendfile(fileno(f), fileno(archive->f), NULL, size);
if (bytes_written < size) {
- CTX_ERROR(archive->ctx, "Could not copy archive (%zd byte(s) written): %m\n",
+ ERROR(archive->ctx, "Could not copy archive (%zd byte(s) written): %m\n",
bytes_written);
goto ERROR;
}
if (!path)
return -EINVAL;
- CTX_DEBUG(archive->ctx, "Linking %s to %s...\n", archive->path, path);
+ DEBUG(archive->ctx, "Linking %s to %s...\n", archive->path, path);
// Delete the destination file (if it exists)
unlink(path);
// Create the new link
r = link(archive->path, path);
if (r) {
- CTX_DEBUG(archive->ctx, "Could not create hardlink %s: %m\n", path);
+ DEBUG(archive->ctx, "Could not create hardlink %s: %m\n", path);
return r;
}
// Compose file path
r = pakfire_path_append(buffer, state->prefix, path);
if (r < 0) {
- CTX_ERROR(archive->ctx, "Could not compose file path: %m\n");
+ ERROR(archive->ctx, "Could not compose file path: %m\n");
goto ERROR;
}
if (link) {
r = pakfire_path_append(buffer, state->prefix, link);
if (r < 0) {
- CTX_ERROR(archive->ctx, "Could not compose hardlink path: %m\n");
+ ERROR(archive->ctx, "Could not compose hardlink path: %m\n");
goto ERROR;
}
path = archive_entry_pathname(entry);
if (pakfire_path_exists(path)) {
- CTX_DEBUG(archive->ctx, "The configuration file %s exists\n",
+ DEBUG(archive->ctx, "The configuration file %s exists\n",
pakfire_file_get_path(file));
r = pakfire_string_format(buffer, "%s.paknew", path);
if (r < 0) {
- CTX_ERROR(archive->ctx, "Could not compose path for configuration file: %m\n");
+ ERROR(archive->ctx, "Could not compose path for configuration file: %m\n");
goto ERROR;
}
// Fetch path again since we changed it
path = archive_entry_pathname(entry);
- CTX_DEBUG(archive->ctx, "Extracting %s\n", path);
+ DEBUG(archive->ctx, "Extracting %s\n", path);
// Remove any extended attributes which we never write to disk
archive_entry_xattr_clear(entry);
break;
case ARCHIVE_WARN:
- CTX_ERROR(archive->ctx, "%s\n", archive_error_string(state->writer));
+ ERROR(archive->ctx, "%s\n", archive_error_string(state->writer));
// Pretend everything has been okay
r = 0;
break;
case ARCHIVE_FATAL:
- CTX_ERROR(archive->ctx, "%s\n", archive_error_string(state->writer));
+ ERROR(archive->ctx, "%s\n", archive_error_string(state->writer));
r = 1;
break;
}
struct archive* a = NULL;
int r;
- CTX_DEBUG(archive->ctx, "Extracting %s\n", archive->path);
+ DEBUG(archive->ctx, "Extracting %s\n", archive->path);
int progress_flags = PAKFIRE_PROGRESS_SHOW_PERCENTAGE;
char* expected_hexdigest = __pakfire_hexlify(digest, length);
char* computed_hexdigest = __pakfire_hexlify(computed_digest, computed_length);
- CTX_ERROR(archive->ctx, "Archive digest does not match for %s:\n", archive->path);
- CTX_ERROR(archive->ctx, " Expected: %s\n", expected_hexdigest);
- CTX_ERROR(archive->ctx, " Computed: %s\n", computed_hexdigest);
+ ERROR(archive->ctx, "Archive digest does not match for %s:\n", archive->path);
+ ERROR(archive->ctx, " Expected: %s\n", expected_hexdigest);
+ ERROR(archive->ctx, " Computed: %s\n", computed_hexdigest);
if (expected_hexdigest)
free(expected_hexdigest);
// Fetch the array with the filelist
array = pakfire_archive_metadata_get_object(archive, "filelist", NULL);
if (!array) {
- CTX_ERROR(archive->ctx, "Archive has no filelist: %m\n");
+ ERROR(archive->ctx, "Archive has no filelist: %m\n");
return 1;
}
#ifdef ENABLE_DEBUG
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
- CTX_DEBUG(archive->ctx, "Created package %s (%p) from archive %p\n",
+ DEBUG(archive->ctx, "Created package %s (%p) from archive %p\n",
nevra, pkg, archive);
#endif
// Fill the buffer with data from the archive
bytes_read = archive_read_data(a, buffer, length);
if (bytes_read < 0)
- CTX_ERROR(ctx, "Could not read from archive: %s\n", archive_error_string(a));
+ ERROR(ctx, "Could not read from archive: %s\n", archive_error_string(a));
return bytes_read;
}
const unsigned int ms = (unsigned int)(t * 1000.0) % 1000;
if (h)
- CTX_INFO(ctx, "[%02u:%02u:%02u.%04u] %.*s", h, m, s, ms, (int)length, buffer);
+ INFO(ctx, "[%02u:%02u:%02u.%04u] %.*s", h, m, s, ms, (int)length, buffer);
else if (m)
- CTX_INFO(ctx, "[ %02u:%02u.%04u] %.*s", m, s, ms, (int)length, buffer);
+ INFO(ctx, "[ %02u:%02u.%04u] %.*s", m, s, ms, (int)length, buffer);
else
- CTX_INFO(ctx, "[ %02u.%04u] %.*s", s, ms, (int)length, buffer);
+ INFO(ctx, "[ %02u.%04u] %.*s", s, ms, (int)length, buffer);
return length;
}
const char* name = pakfire_repo_get_name(repo);
- CTX_DEBUG(build->ctx, "Exporting repository configuration for '%s'\n", name);
+ DEBUG(build->ctx, "Exporting repository configuration for '%s'\n", name);
// Make path for configuration file
r = pakfire_path(build->pakfire, path, PAKFIRE_CONFIG_DIR "/repos/%s.repo", name);
if (r) {
- CTX_ERROR(build->ctx, "Could not make repository configuration path for %s: %m\n", name);
+ ERROR(build->ctx, "Could not make repository configuration path for %s: %m\n", name);
goto ERROR;
}
// Open the repository configuration
f = fopen(path, "w");
if (!f) {
- CTX_ERROR(build->ctx, "Could not open %s for writing: %m\n", path);
+ ERROR(build->ctx, "Could not open %s for writing: %m\n", path);
goto ERROR;
}
// Write repository configuration
r = pakfire_repo_write_config(repo, f);
if (r) {
- CTX_ERROR(build->ctx, "Could not write repository configuration for %s: %m\n", name);
+ ERROR(build->ctx, "Could not write repository configuration for %s: %m\n", name);
goto ERROR;
}
if (pakfire_path_exists(_path)) {
r = pakfire_jail_bind(build->jail, _path, _path, MS_RDONLY);
if (r) {
- CTX_ERROR(build->ctx, "Could not bind-mount the repository at %s: %m\n", _path);
+ ERROR(build->ctx, "Could not bind-mount the repository at %s: %m\n", _path);
goto ERROR;
}
}
// Compose the source path
r = pakfire_path_append(path, PAKFIRE_SCRIPTS_DIR, filename);
if (r) {
- CTX_ERROR(build->ctx, "Could not compose path for script '%s': %m\n", filename);
+ ERROR(build->ctx, "Could not compose path for script '%s': %m\n", filename);
goto ERROR;
}
- CTX_DEBUG(build->ctx, "Reading script from %s...\n", path);
+ DEBUG(build->ctx, "Reading script from %s...\n", path);
// Open the file
f = fopen(path, "r");
if (!f) {
- CTX_ERROR(build->ctx, "Could not open script %s: %m\n", path);
+ ERROR(build->ctx, "Could not open script %s: %m\n", path);
goto ERROR;
}
// Read the file into a the buffer
r = pakfire_read_file_into_buffer(f, buffer, length);
if (r) {
- CTX_ERROR(build->ctx, "Could not read script: %m\n");
+ ERROR(build->ctx, "Could not read script: %m\n");
goto ERROR;
}
char* script = NULL;
size_t length = 0;
- CTX_DEBUG(build->ctx, "Running build script '%s'...\n", filename);
+ DEBUG(build->ctx, "Running build script '%s'...\n", filename);
// Read the script
r = pakfire_build_read_script(build, filename, &script, &length);
if (r) {
- CTX_ERROR(build->ctx, "Could not read script %s: %m\n", filename);
+ ERROR(build->ctx, "Could not read script %s: %m\n", filename);
return r;
}
r = pakfire_jail_exec_script(build->jail, script, length, args,
stdin_callback, stdin_data, stdout_callback, stdout_data);
if (r)
- CTX_ERROR(build->ctx, "Script '%s' failed with status %d\n", filename, r);
+ ERROR(build->ctx, "Script '%s' failed with status %d\n", filename, r);
if (script)
free(script);
if (!pattern || !*pattern)
goto ERROR;
- CTX_DEBUG(build->ctx, "Found filter for %s: %s\n", filter, pattern);
+ DEBUG(build->ctx, "Found filter for %s: %s\n", filter, pattern);
// Compile the regular expression
r = pakfire_compile_regex(build->ctx, regex, pattern);
// Fetch the next file
file = pakfire_filelist_get(p->filelist, p->i);
if (!file) {
- CTX_DEBUG(ctx, "Could not fetch file %u: %m\n", p->i);
+ DEBUG(ctx, "Could not fetch file %u: %m\n", p->i);
r = -errno;
goto ERROR;
}
// Fetch the path of the file
const char* path = pakfire_file_get_path(file);
if (!path) {
- CTX_ERROR(ctx, "Received a file with an empty path\n");
+ ERROR(ctx, "Received a file with an empty path\n");
r = -errno;
goto ERROR;
}
if (r)
return r;
- CTX_DEBUG(ctx, "Processing dependency: %s\n", dep);
+ DEBUG(ctx, "Processing dependency: %s\n", dep);
// Filter out any dependencies that are provided by this package
if (p->dep == PAKFIRE_PKG_REQUIRES) {
if (p->filter) {
match = pcre2_match_data_create_from_pattern(p->filter, NULL);
if (!match) {
- CTX_ERROR(ctx, "Could not allocate PCRE match data: %m\n");
+ ERROR(ctx, "Could not allocate PCRE match data: %m\n");
goto ERROR;
}
// Fetch the error message
r = pcre2_get_error_message(r, (PCRE2_UCHAR*)error, sizeof(error));
if (r < 0) {
- CTX_ERROR(ctx, "Could not fetch PCRE error message: %m\n");
+ ERROR(ctx, "Could not fetch PCRE error message: %m\n");
r = 1;
goto ERROR;
}
- CTX_ERROR(ctx, "Could not match the filter: %s\n", error);
+ ERROR(ctx, "Could not match the filter: %s\n", error);
r = 1;
goto ERROR;
// Match!
} else {
- CTX_DEBUG(ctx, "Skipping dependency that has been filtered: %s\n", dep);
+ DEBUG(ctx, "Skipping dependency that has been filtered: %s\n", dep);
r = 0;
goto ERROR;
}
// Add dependency
r = pakfire_package_add_dep(p->pkg, p->dep, buffer);
if (r) {
- CTX_ERROR(ctx, "Could not process dependency '%s': %m\n", buffer);
+ ERROR(ctx, "Could not process dependency '%s': %m\n", buffer);
return r;
}
goto ERROR;
SKIP:
- CTX_DEBUG(ctx, "Skipping dependency that is provided by the package itself: %s\n", dep);
+ DEBUG(ctx, "Skipping dependency that is provided by the package itself: %s\n", dep);
// Return how many bytes we have consumed
r = length;
// Skip calling the script if class doesn't match
if (class && !pakfire_filelist_matches_class(filelist, class)) {
- CTX_DEBUG(build->ctx, "Skipping calling %s as class does not match\n", script);
+ DEBUG(build->ctx, "Skipping calling %s as class does not match\n", script);
return 0;
}
r = pakfire_build_run_script(build, script, args,
pakfire_build_send_filelist, &ctx, pakfire_build_process_deps, &ctx);
if (r)
- CTX_ERROR(build->ctx, "%s returned with error %d\n", script, r);
+ ERROR(build->ctx, "%s returned with error %d\n", script, r);
return r;
}
r = pakfire_build_make_filter(build, &filter_provides,
makefile, namespace, "filter_provides");
if (r) {
- CTX_ERROR(build->ctx, "Provides filter is broken: %m\n");
+ ERROR(build->ctx, "Provides filter is broken: %m\n");
goto ERROR;
}
r = pakfire_build_make_filter(build, &filter_requires,
makefile, namespace, "filter_requires");
if (r) {
- CTX_ERROR(build->ctx, "Requires filter is broken: %m\n");
+ ERROR(build->ctx, "Requires filter is broken: %m\n");
goto ERROR;
}
if (r < 0)
goto ERROR;
- CTX_DEBUG(build->ctx, "%zu file(s) found\n", pakfire_filelist_length(filelist));
+ DEBUG(build->ctx, "%zu file(s) found\n", pakfire_filelist_length(filelist));
// Nothing to do if the filelist is empty
if (pakfire_filelist_is_empty(filelist))
// Find dependencies
r = pakfire_build_find_dependencies(build, makefile, namespace, pkg, filelist);
if (r) {
- CTX_ERROR(build->ctx, "Finding dependencies failed: %m\n");
+ ERROR(build->ctx, "Finding dependencies failed: %m\n");
goto ERROR;
}
if (!state->p) {
state->p = pakfire_scriptlet_get_data(state->scriptlet, &state->l);
if (!state->p) {
- CTX_ERROR(ctx, "Could not fetch scriptlet: %m\n");
+ ERROR(ctx, "Could not fetch scriptlet: %m\n");
return -errno;
}
}
// Add it to the package
r = pakfire_packager_add_scriptlet(packager, scriptlet);
if (r) {
- CTX_ERROR(build->ctx, "Could not add scriptlet %s\n", type);
+ ERROR(build->ctx, "Could not add scriptlet %s\n", type);
goto ERROR;
}
// Add scriptlet requirements
r = pakfire_build_add_scriptlet_requires(build, pkg, scriptlet);
if (r) {
- CTX_ERROR(build->ctx, "Could not add scriptlet requirements: %m\n");
+ ERROR(build->ctx, "Could not add scriptlet requirements: %m\n");
goto ERROR;
}
// Expand the handle into the package name
char* name = pakfire_parser_expand(makefile, "packages", namespace);
if (!name) {
- CTX_ERROR(build->ctx, "Could not get package name: %m\n");
+ ERROR(build->ctx, "Could not get package name: %m\n");
goto ERROR;
}
- CTX_INFO(build->ctx, "Building package '%s'...\n", name);
- CTX_DEBUG(build->ctx, " buildroot = %s\n", buildroot);
+ INFO(build->ctx, "Building package '%s'...\n", name);
+ DEBUG(build->ctx, " buildroot = %s\n", buildroot);
// Fetch build architecture
const char* arch = pakfire_get_arch(build->pakfire);
// Fetch package from makefile
r = pakfire_parser_create_package(makefile, &pkg, NULL, namespace, arch);
if (r) {
- CTX_ERROR(build->ctx, "Could not create package from makefile: %m\n");
+ ERROR(build->ctx, "Could not create package from makefile: %m\n");
goto ERROR;
}
// Write the finished package
r = pakfire_packager_finish_to_directory(packager, path, NULL);
if (r) {
- CTX_ERROR(build->ctx, "pakfire_packager_finish() failed: %m\n");
+ ERROR(build->ctx, "pakfire_packager_finish() failed: %m\n");
goto ERROR;
}
if (!dump)
return 1;
- CTX_INFO(build->ctx, "%s\n", dump);
+ INFO(build->ctx, "%s\n", dump);
free(dump);
return 0;
static int pakfire_build_packages(struct pakfire_build* build,
struct pakfire_parser* makefile) {
- CTX_INFO(build->ctx, "Creating packages...");
+ INFO(build->ctx, "Creating packages...");
int r = 1;
const char* buildroot = pakfire_relpath(build->pakfire, build->buildroot);
// Fetch a list all all packages
char** packages = pakfire_parser_list_namespaces(makefile, "packages.package:*");
if (!packages) {
- CTX_ERROR(build->ctx, "Could not find any packages: %m\n");
+ ERROR(build->ctx, "Could not find any packages: %m\n");
goto ERROR;
}
for (char** package = packages; *package; package++)
num_packages++;
- CTX_DEBUG(build->ctx, "Found %u package(s)\n", num_packages);
+ DEBUG(build->ctx, "Found %u package(s)\n", num_packages);
// Build packages in reverse order
for (int i = num_packages - 1; i >= 0; i--) {
// Create the build script
char* script = pakfire_parser_expand(makefile, "build", template);
if (!script) {
- CTX_ERROR(build->ctx, "Could not generate the build script for stage '%s': %m\n", stage);
+ ERROR(build->ctx, "Could not generate the build script for stage '%s': %m\n", stage);
goto ERROR;
}
- CTX_INFO(build->ctx, "Running build stage '%s'\n", stage);
+ INFO(build->ctx, "Running build stage '%s'\n", stage);
// Import environment
// XXX is this a good idea?
r = pakfire_jail_import_env(build->jail, (const char**)envp);
if (r) {
- CTX_ERROR(build->ctx, "Could not import environment: %m\n");
+ ERROR(build->ctx, "Could not import environment: %m\n");
goto ERROR;
}
r = pakfire_jail_exec_script(build->jail, script, strlen(script), NULL,
NULL, NULL, pakfire_build_output_callback, build);
if (r)
- CTX_ERROR(build->ctx, "Build stage '%s' failed with status %d\n", stage, r);
+ ERROR(build->ctx, "Build stage '%s' failed with status %d\n", stage, r);
ERROR:
if (envp) {
if (!pakfire_filelist_is_empty(removees)) {
if (description)
- CTX_INFO(build->ctx, "%s\n", description);
+ INFO(build->ctx, "%s\n", description);
// Show all files which will be removed
pakfire_filelist_dump(removees, PAKFIRE_FILE_DUMP_FULL|PAKFIRE_FILE_DUMP_ISSUES);
// Create a filelist of all files in the build
r = pakfire_filelist_create(&filelist, build->pakfire);
if (r) {
- CTX_ERROR(build->ctx, "Could not create filelist: %m\n");
+ ERROR(build->ctx, "Could not create filelist: %m\n");
goto ERROR;
}
// If the filelist is empty, we can are done
if (pakfire_filelist_is_empty(filelist)) {
- CTX_DEBUG(build->ctx, "Empty BUILDROOT. Skipping post build checks...\n");
+ DEBUG(build->ctx, "Empty BUILDROOT. Skipping post build checks...\n");
r = 0;
goto ERROR;
}
if (id) {
r = uuid_parse(id, build->id);
if (r) {
- CTX_ERROR(build->ctx, "Could not parse build ID '%s'\n", id);
+ ERROR(build->ctx, "Could not parse build ID '%s'\n", id);
return -EINVAL;
}
// Compose path
r = pakfire_string_format(path, "pakfire/build-%s", build->_id);
if (r) {
- CTX_ERROR(build->ctx, "Could not compose path for cgroup: %m\n");
+ ERROR(build->ctx, "Could not compose path for cgroup: %m\n");
goto ERROR;
}
r = pakfire_cgroup_open(&build->cgroup, build->ctx, path,
PAKFIRE_CGROUP_ENABLE_ACCOUNTING);
if (r) {
- CTX_ERROR(build->ctx, "Could not create cgroup for build %s: %m\n", build->_id);
+ ERROR(build->ctx, "Could not create cgroup for build %s: %m\n", build->_id);
goto ERROR;
}
// Create a new jail
r = pakfire_jail_create(&build->jail, build->pakfire);
if (r) {
- CTX_ERROR(build->ctx, "Could not create jail for build %s: %m\n", build->_id);
+ ERROR(build->ctx, "Could not create jail for build %s: %m\n", build->_id);
return r;
}
// Connect the jail to our cgroup
r = pakfire_jail_set_cgroup(build->jail, build->cgroup);
if (r) {
- CTX_ERROR(build->ctx, "Could not set cgroup for jail: %m\n");
+ ERROR(build->ctx, "Could not set cgroup for jail: %m\n");
return r;
}
// Build everything with a slightly lower priority
r = pakfire_jail_nice(build->jail, 5);
if (r) {
- CTX_ERROR(build->ctx, "Could not set nice level: %m\n");
+ ERROR(build->ctx, "Could not set nice level: %m\n");
return r;
}
// Make sure the path exists
r = pakfire_mkdir(build->ccache_path, 0755);
if (r) {
- CTX_ERROR(build->ctx, "Could not create %s: %m\n", build->ccache_path);
+ ERROR(build->ctx, "Could not create %s: %m\n", build->ccache_path);
return r;
}
// Check if we want a ccache
if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_CCACHE)) {
- CTX_DEBUG(build->ctx, "ccache usage has been disabled for this build\n");
+ DEBUG(build->ctx, "ccache usage has been disabled for this build\n");
// Set CCACHE_DISABLE=1 so that if ccache is installed, it will disable itself
r = pakfire_jail_set_env(build->jail, "CCACHE_DISABLE", "1");
if (r) {
- CTX_ERROR(build->ctx, "Could not disable ccache: %m\n");
+ ERROR(build->ctx, "Could not disable ccache: %m\n");
return r;
}
// Set CCACHE_DIR
r = pakfire_jail_set_env(build->jail, "CCACHE_DIR", CCACHE_DIR);
if (r) {
- CTX_ERROR(build->ctx, "Could not set ccache directory: %m\n");
+ ERROR(build->ctx, "Could not set ccache directory: %m\n");
return r;
}
// Set CCACHE_TEMPDIR
r = pakfire_jail_set_env(build->jail, "CCACHE_TEMPDIR", "/tmp");
if (r) {
- CTX_ERROR(build->ctx, "Could not set ccache tempdir: %m\n");
+ ERROR(build->ctx, "Could not set ccache tempdir: %m\n");
return r;
}
// Create a new repository
r = pakfire_repo_create(&build->repo, build->pakfire, PAKFIRE_REPO_RESULT);
if (r) {
- CTX_ERROR(build->ctx, "Could not create repository %s: %m", PAKFIRE_REPO_RESULT);
+ ERROR(build->ctx, "Could not create repository %s: %m", PAKFIRE_REPO_RESULT);
return r;
}
// Create a temporary directory
const char* p = pakfire_mkdtemp(path);
if (!p) {
- CTX_ERROR(build->ctx, "Could not create a the build repository: %m\n");
+ ERROR(build->ctx, "Could not create a the build repository: %m\n");
return 1;
}
// Fetch current time
r = clock_gettime(CLOCK_MONOTONIC, &build->time_start);
if (r < 0)
- CTX_ERROR(build->ctx, "Could not fetch start time: %m\n");
+ ERROR(build->ctx, "Could not fetch start time: %m\n");
return r;
}
// Solve the transaction
r = pakfire_transaction_solve(transaction, 0, &problems);
if (r) {
- CTX_ERROR(build->ctx, "Could not install build dependencies:\n%s\n", problems);
+ ERROR(build->ctx, "Could not install build dependencies:\n%s\n", problems);
goto ERROR;
}
// Don't do it again
if (build->state != PAKFIRE_BUILD_INIT) {
- CTX_DEBUG(build->ctx, "Build environment has already been initialized\n");
+ DEBUG(build->ctx, "Build environment has already been initialized\n");
return 0;
}
r = pakfire_read_makefile(parser, build->pakfire, path, &error);
if (r) {
if (error) {
- CTX_ERROR(build->ctx, "Could not parse makefile %s: %s\n", path,
+ ERROR(build->ctx, "Could not parse makefile %s: %s\n", path,
pakfire_parser_error_get_message(error));
} else {
- CTX_ERROR(build->ctx, "Could not parse makefile %s: %m\n", path);
+ ERROR(build->ctx, "Could not parse makefile %s: %m\n", path);
}
goto ERROR;
// Run post build checks
r = pakfire_build_run_post_build_checks(build);
if (r) {
- CTX_ERROR(build->ctx, "Post build checks failed\n");
+ ERROR(build->ctx, "Post build checks failed\n");
goto ERROR;
}
struct pakfire_ctx* ctx, struct pakfire_file* file, void* p) {
char* s = pakfire_file_dump(file, PAKFIRE_FILE_DUMP_FULL);
if (s) {
- CTX_ERROR(ctx, "%s\n", s);
+ ERROR(ctx, "%s\n", s);
free(s);
}
goto ERROR;
if (!pakfire_filelist_is_empty(filelist)) {
- CTX_ERROR(build->ctx, "Unpackaged files found:\n");
+ ERROR(build->ctx, "Unpackaged files found:\n");
r = pakfire_filelist_walk(filelist, __pakfire_build_unpackaged_file, NULL, 0);
if (r)
// Dependency Error
case 2:
- CTX_ERROR(build->ctx, "Install test failed:\n%s\n", problems);
+ ERROR(build->ctx, "Install test failed:\n%s\n", problems);
break;
// Any other errors
default:
- CTX_ERROR(build->ctx, "Install test failed: %m\n");
+ ERROR(build->ctx, "Install test failed: %m\n");
goto ERROR;
}
struct pakfire_repo* local = NULL;
int r = 0;
- CTX_DEBUG(build->ctx, "Copying built packages\n");
+ DEBUG(build->ctx, "Copying built packages\n");
// Fetch local repository
local = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL);
r = pakfire_transaction_solve(transaction, 0, &problems);
if (r) {
if (problems)
- CTX_ERROR(build->ctx, "Could not install the source package:\n%s\n", problems);
+ ERROR(build->ctx, "Could not install the source package:\n%s\n", problems);
goto ERROR;
}
// Sanity check to see if we actually try to install anything
if (!changes) {
- CTX_ERROR(build->ctx, "The source package did not get installed\n");
+ ERROR(build->ctx, "The source package did not get installed\n");
r = 1;
goto ERROR;
}
const char* nevra = pakfire_package_get_string(package, PAKFIRE_PKG_NEVRA);
const char* uuid = pakfire_package_get_string(package, PAKFIRE_PKG_UUID);
- CTX_INFO(build->ctx, "Building %s (%s)...\n", nevra, uuid);
+ INFO(build->ctx, "Building %s (%s)...\n", nevra, uuid);
// Check if this package can be build in this environment
if (!pakfire_package_supports_build_arch(package, arch)) {
- CTX_ERROR(build->ctx, "%s does not support being built on %s\n", nevra, arch);
+ ERROR(build->ctx, "%s does not support being built on %s\n", nevra, arch);
r = -ENOTSUP;
goto ERROR;
}
// Perform an install check to see whether we can build this at all
r = pakfire_package_installcheck(package, &problems, 0);
if (r) {
- CTX_ERROR(build->ctx, "Cannot build %s:\n%s\n", nevra, problems);
+ ERROR(build->ctx, "Cannot build %s:\n%s\n", nevra, problems);
goto ERROR;
}
// Install the source package
r = pakfire_build_install_source_package(build, package);
if (r) {
- CTX_ERROR(build->ctx, "Could not install the source package: %m\n");
+ ERROR(build->ctx, "Could not install the source package: %m\n");
goto ERROR;
}
// Mount the ccache
r = pakfire_build_mount_ccache(build);
if (r) {
- CTX_ERROR(build->ctx, "Could not mount the ccache: %m\n");
+ ERROR(build->ctx, "Could not mount the ccache: %m\n");
goto ERROR;
}
// Create BUILDROOT
buildroot = pakfire_mkdtemp(build->buildroot);
if (!buildroot) {
- CTX_ERROR(build->ctx, "Could not create BUILDROOT: %m\n");
+ ERROR(build->ctx, "Could not create BUILDROOT: %m\n");
goto ERROR;
}
// Create the packages
r = pakfire_build_packages(build, makefile);
if (r) {
- CTX_ERROR(build->ctx, "Could not create packages: %m\n");
+ ERROR(build->ctx, "Could not create packages: %m\n");
goto ERROR;
}
if (r)
goto ERROR;
- CTX_INFO(build->ctx, "Build successfully completed in %s\n", duration);
+ INFO(build->ctx, "Build successfully completed in %s\n", duration);
ERROR:
if (makefile)
// Create a new transaction
r = pakfire_transaction_create(&transaction, build->pakfire, 0);
if (r) {
- CTX_ERROR(build->ctx, "Could not create transaction: %m\n");
+ ERROR(build->ctx, "Could not create transaction: %m\n");
goto ERROR;
}
r = pakfire_transaction_request(transaction,
PAKFIRE_JOB_INSTALL, requires, PAKFIRE_JOB_ESSENTIAL);
if (r) {
- CTX_ERROR(build->ctx, "Could not add '%s' to the transaction: %m\n", requires);
+ ERROR(build->ctx, "Could not add '%s' to the transaction: %m\n", requires);
goto ERROR;
}
// Solve the request
r = pakfire_transaction_solve(transaction, 0, &problems);
if (r) {
- CTX_ERROR(build->ctx, "Could not solve the request:\n%s\n", problems);
+ ERROR(build->ctx, "Could not solve the request:\n%s\n", problems);
goto ERROR;
}
// Create a new transaction
r = pakfire_transaction_create(&transaction, build->pakfire, 0);
if (r) {
- CTX_ERROR(build->ctx, "Could not create transaction: %m\n");
+ ERROR(build->ctx, "Could not create transaction: %m\n");
goto ERROR;
}
r = pakfire_transaction_request(transaction,
PAKFIRE_JOB_INSTALL, "ipfire-release", PAKFIRE_JOB_ESSENTIAL);
if (r) {
- CTX_ERROR(build->ctx, "Could not install 'ipfire-release': %m\n");
+ ERROR(build->ctx, "Could not install 'ipfire-release': %m\n");
goto ERROR;
}
// Solve the transaction
r = pakfire_transaction_solve(transaction, 0, &problems);
if (r) {
- CTX_ERROR(build->ctx, "Could not solve request:\n%s\n", problems);
+ ERROR(build->ctx, "Could not solve request:\n%s\n", problems);
goto ERROR;
}
// Empty transaction?
if (!pakfire_transaction_count(transaction)) {
- CTX_ERROR(build->ctx, "The transaction is unexpectedly empty\n");
+ ERROR(build->ctx, "The transaction is unexpectedly empty\n");
r = 1;
goto ERROR;
}
// Dump the transaction
p = pakfire_transaction_dump(transaction, 80);
if (!p) {
- CTX_ERROR(build->ctx, "Could not dump the transaction: %m\n");
+ ERROR(build->ctx, "Could not dump the transaction: %m\n");
r = 1;
goto ERROR;
}
// Log the dump
- CTX_INFO(build->ctx, "%s\n", p);
+ INFO(build->ctx, "%s\n", p);
// Download all packages
r = pakfire_transaction_download(transaction);
if (r) {
- CTX_ERROR(build->ctx, "Could not download the transaction: %m\n");
+ ERROR(build->ctx, "Could not download the transaction: %m\n");
goto ERROR;
}
// Create a repository with all packages in this transaction
r = pakfire_transaction_compose_repo(transaction, NULL, path);
if (r) {
- CTX_ERROR(build->ctx, "Could not create repository: %m\n");
+ ERROR(build->ctx, "Could not create repository: %m\n");
goto ERROR;
}
// Allocate a temporary file
t = pakfire_mktemp(path, 0600);
if (!t) {
- CTX_ERROR(build->ctx, "Could not allocate a temporary file: %m\n");
+ ERROR(build->ctx, "Could not allocate a temporary file: %m\n");
r = 1;
goto ERROR;
}
// Fetch local repository
local = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
if (!local) {
- CTX_ERROR(ctx, "Could not find repository %s: %m\n", PAKFIRE_REPO_LOCAL);
+ ERROR(ctx, "Could not find repository %s: %m\n", PAKFIRE_REPO_LOCAL);
goto ERROR;
}
// Solve the transaction
r = pakfire_transaction_solve(transaction, 0, &problems);
if (r) {
- CTX_ERROR(build->ctx, "Could not install packages:\n%s\n", problems);
+ ERROR(build->ctx, "Could not install packages:\n%s\n", problems);
goto ERROR;
}
if (r) {
error = krb5_get_error_message(service->krb5_ctx, r);
- CTX_ERROR(service->ctx, "Could not initialize Kerberos: %s\n", error);
+ ERROR(service->ctx, "Could not initialize Kerberos: %s\n", error);
krb5_free_error_message(service->krb5_ctx, error);
goto ERROR;
// Fetch the URL
url = pakfire_config_get(config, "client", "url", NULL);
if (!url) {
- CTX_ERROR(service->ctx, "Build Service URL is not configured\n");
+ ERROR(service->ctx, "Build Service URL is not configured\n");
r = 1;
goto ERROR;
}
if (r)
goto ERROR;
- CTX_DEBUG(s->ctx,
+ DEBUG(s->ctx,
"Pakfire Build Service initialized for %s\n", pakfire_buildservice_get_url(s));
// Return the pointer
// Stat the file
r = fstat(fd, &stat);
if (r) {
- CTX_ERROR(service->ctx, "Could not stat %s: %s\n", path, strerror(errno));
+ ERROR(service->ctx, "Could not stat %s: %s\n", path, strerror(errno));
goto ERROR;
}
// Compute the digest
r = pakfire_digests_compute_from_file(service->ctx, &digests, PAKFIRE_DIGEST_BLAKE2B512, f);
if (r) {
- CTX_ERROR(service->ctx, "Could not compute the digest of %s: %s\n",
+ ERROR(service->ctx, "Could not compute the digest of %s: %s\n",
path, strerror(-r));
goto ERROR;
}
// Fetch the ID
r = json_object_object_get_ex(response, "id", &id);
if (r == 0) {
- CTX_ERROR(service->ctx, "Could not fetch ID from response\n");
+ ERROR(service->ctx, "Could not fetch ID from response\n");
r = -EBADMSG;
goto ERROR;
}
// Extract the UUID
__id = json_object_get_string(id);
if (!__id) {
- CTX_ERROR(service->ctx, "Could not fetch ID from response\n");
+ ERROR(service->ctx, "Could not fetch ID from response\n");
r = -EBADMSG;
goto ERROR;
}
// Open the source file
f = fopen(path, "r");
if (!f) {
- CTX_ERROR(service->ctx, "Could not open file for upload %s: %m\n", path);
+ ERROR(service->ctx, "Could not open file for upload %s: %m\n", path);
return -errno;
}
if (r)
goto ERROR;
- CTX_DEBUG(service->ctx, "Created a new download (%s)\n", *uuid);
+ DEBUG(service->ctx, "Created a new download (%s)\n", *uuid);
// Send the payload
r = pakfire_buildservice_upload_payload(service, filename, *uuid, f);
// Fetch the uploads
uploads = json_object_object_get(response, "uploads");
if (!uploads) {
- CTX_ERROR(service->ctx, "Malformed response\n");
+ ERROR(service->ctx, "Malformed response\n");
r = -EBADMSG;
goto ERROR;
}
// Fetch the repos
if (!json_object_object_get_ex(response, "repos", &repos)) {
- CTX_ERROR(service->ctx, "Malformed response\n");
+ ERROR(service->ctx, "Malformed response\n");
r = -EBADMSG;
goto ERROR;
}
}
if (r)
- CTX_ERROR(cgroup->ctx, "Could not determine cgroup root: %m\n");
+ ERROR(cgroup->ctx, "Could not determine cgroup root: %m\n");
return r;
}
// Determine the path of the parent
r = pakfire_path_dirname(path, cgroup->path);
if (r) {
- CTX_ERROR(cgroup->ctx, "Could not determine path for parent cgroup: %m\n");
+ ERROR(cgroup->ctx, "Could not determine path for parent cgroup: %m\n");
return NULL;
}
// Open the cgroup
r = pakfire_cgroup_open(&parent, cgroup->ctx, path, 0);
if (r) {
- CTX_ERROR(cgroup->ctx, "Could not open parent cgroup: %m\n");
+ ERROR(cgroup->ctx, "Could not open parent cgroup: %m\n");
parent = NULL;
}
}
static void pakfire_cgroup_free(struct pakfire_cgroup* cgroup) {
- CTX_DEBUG(cgroup->ctx, "Releasing cgroup %s at %p\n",
+ DEBUG(cgroup->ctx, "Releasing cgroup %s at %p\n",
pakfire_cgroup_name(cgroup), cgroup);
// Close the file descriptors
r = bpf_prog_load(BPF_PROG_TYPE_CGROUP_DEVICE, NULL, "GPL",
program, sizeof(program) / sizeof(*program), &opts);
if (r < 0) {
- CTX_ERROR(cgroup->ctx, "Could not load BPF program: %m\n");
+ ERROR(cgroup->ctx, "Could not load BPF program: %m\n");
return r;
}
r = bpf_prog_attach(cgroup->devicesfd, cgroup->fd,
BPF_CGROUP_DEVICE, BPF_F_ALLOW_MULTI);
if (r) {
- CTX_ERROR(cgroup->ctx, "Could not attach BPF program to cgroup: %m\n");
+ ERROR(cgroup->ctx, "Could not attach BPF program to cgroup: %m\n");
return r;
}
static int pakfire_cgroup_open_root(struct pakfire_cgroup* cgroup) {
int fd = open(cgroup->root, O_DIRECTORY|O_PATH|O_CLOEXEC);
if (fd < 0) {
- CTX_ERROR(cgroup->ctx, "Could not open %s: %m\n", cgroup->root);
+ ERROR(cgroup->ctx, "Could not open %s: %m\n", cgroup->root);
return -1;
}
char path[PATH_MAX];
int r;
- CTX_DEBUG(cgroup->ctx, "Trying to create cgroup %s\n", pakfire_cgroup_name(cgroup));
+ DEBUG(cgroup->ctx, "Trying to create cgroup %s\n", pakfire_cgroup_name(cgroup));
// Compose the absolute path
r = pakfire_path_append(path, cgroup->root, cgroup->path);
// Exit on all other errors
default:
- CTX_ERROR(cgroup->ctx, "Could not open cgroup %s: %m\n",
+ ERROR(cgroup->ctx, "Could not open cgroup %s: %m\n",
pakfire_cgroup_name(cgroup));
goto ERROR;
}
// Open cgroup.procs
int fd = openat(cgroup->fd, "cgroup.procs", O_CLOEXEC);
if (fd < 0) {
- CTX_ERROR(cgroup->ctx, "%s: Could not open %s: %m\n",
+ ERROR(cgroup->ctx, "%s: Could not open %s: %m\n",
pakfire_cgroup_name(cgroup), path);
goto ERROR;
}
// Check if this cgroup has been destroyed already
if (cgroup->fd < 0) {
- CTX_ERROR(cgroup->ctx, "Trying to read from destroyed cgroup\n");
+ ERROR(cgroup->ctx, "Trying to read from destroyed cgroup\n");
return -1;
}
// Open the file
int fd = openat(cgroup->fd, path, O_CLOEXEC);
if (fd < 0) {
- CTX_DEBUG(cgroup->ctx, "Could not open %s/%s: %m\n",
+ DEBUG(cgroup->ctx, "Could not open %s/%s: %m\n",
pakfire_cgroup_name(cgroup), path);
goto ERROR;
}
// Read file content into buffer
bytes_read = read(fd, buffer, length);
if (bytes_read < 0) {
- CTX_DEBUG(cgroup->ctx, "Could not read from %s/%s: %m\n",
+ DEBUG(cgroup->ctx, "Could not read from %s/%s: %m\n",
pakfire_cgroup_name(cgroup), path);
goto ERROR;
}
// Check if this cgroup has been destroyed already
if (cgroup->fd < 0) {
- CTX_ERROR(cgroup->ctx, "Trying to write to destroyed cgroup\n");
+ ERROR(cgroup->ctx, "Trying to write to destroyed cgroup\n");
errno = EPERM;
return 1;
}
// Open the file
int fd = openat(cgroup->fd, path, O_WRONLY|O_CLOEXEC);
if (fd < 0) {
- CTX_DEBUG(cgroup->ctx, "Could not open %s/%s for writing: %m\n",
+ DEBUG(cgroup->ctx, "Could not open %s/%s for writing: %m\n",
pakfire_cgroup_name(cgroup), path);
return 1;
}
// Check if content was written okay
if (bytes_written < 0) {
- CTX_DEBUG(cgroup->ctx, "Could not write to %s/%s: %m\n",
+ DEBUG(cgroup->ctx, "Could not write to %s/%s: %m\n",
pakfire_cgroup_name(cgroup), path);
r = 1;
}
char* token = strtok_r(buffer, " \n", &p);
while (token) {
- CTX_DEBUG(cgroup->ctx, "Found controller '%s'\n", token);
+ DEBUG(cgroup->ctx, "Found controller '%s'\n", token);
// Try finding this controller
int controller = pakfire_cgroup_find_controller_by_name(token);
// Find all enabled controllers
const int enabled_controllers = pakfire_cgroup_enabled_controllers(cgroup);
if (enabled_controllers < 0) {
- CTX_ERROR(cgroup->ctx, "Could not fetch enabled controllers: %m\n");
+ ERROR(cgroup->ctx, "Could not fetch enabled controllers: %m\n");
goto ERROR;
}
// Exit if everything is already enabled
if (!controllers) {
- CTX_DEBUG(cgroup->ctx, "All controllers are already enabled\n");
+ DEBUG(cgroup->ctx, "All controllers are already enabled\n");
return 0;
}
// Find all available controllers
const int available_controllers = pakfire_cgroup_available_controllers(cgroup);
if (available_controllers < 0) {
- CTX_ERROR(cgroup->ctx, "Could not fetch available controllers: %m\n");
+ ERROR(cgroup->ctx, "Could not fetch available controllers: %m\n");
goto ERROR;
}
// Are all controllers we need available, yet?
if (controllers & ~available_controllers) {
- CTX_DEBUG(cgroup->ctx, "Not all controllers are available, yet\n");
+ DEBUG(cgroup->ctx, "Not all controllers are available, yet\n");
parent = pakfire_cgroup_parent(cgroup);
// Fetch name
const char* name = pakfire_cgroup_controller_name(controller);
- CTX_DEBUG(cgroup->ctx, "Enabling controller %s in cgroup %s\n",
+ DEBUG(cgroup->ctx, "Enabling controller %s in cgroup %s\n",
name, pakfire_cgroup_name(cgroup));
// Try enabling the controller (this will succeed if it already is enabled)
r = pakfire_cgroup_write(cgroup, "cgroup.subtree_control", "+%s\n", name);
if (r) {
- CTX_ERROR(cgroup->ctx, "Could not enable controller %s in cgroup %s\n",
+ ERROR(cgroup->ctx, "Could not enable controller %s in cgroup %s\n",
name, pakfire_cgroup_name(cgroup));
goto ERROR;
}
if (!c)
return 1;
- CTX_DEBUG(ctx, "Allocated cgroup %s at %p\n", path, c);
+ DEBUG(ctx, "Allocated cgroup %s at %p\n", path, c);
// Store a reference to the context
c->ctx = pakfire_ctx_ref(ctx);
}
static int send_sigkill(struct pakfire_cgroup* cgroup, const pid_t pid, void* data) {
- CTX_DEBUG(cgroup->ctx, "Sending signal SIGKILL to PID %d\n", pid);
+ DEBUG(cgroup->ctx, "Sending signal SIGKILL to PID %d\n", pid);
int r = kill(pid, SIGKILL);
if (r < 0 && errno != ESRCH) {
- CTX_ERROR(cgroup->ctx, "Could not send signal SIGKILL to PID %d: %m\n", pid);
+ ERROR(cgroup->ctx, "Could not send signal SIGKILL to PID %d: %m\n", pid);
return r;
}
Immediately kills all processes in this cgroup
*/
static int pakfire_cgroup_killall(struct pakfire_cgroup* cgroup) {
- CTX_DEBUG(cgroup->ctx, "%s: Killing all processes\n", pakfire_cgroup_name(cgroup));
+ DEBUG(cgroup->ctx, "%s: Killing all processes\n", pakfire_cgroup_name(cgroup));
// Do we have support for cgroup.kill?
int r = pakfire_cgroup_access(cgroup, "cgroup.kill", F_OK, 0);
return 1;
}
- CTX_DEBUG(cgroup->ctx, "Destroying cgroup %s\n", pakfire_cgroup_name(cgroup));
+ DEBUG(cgroup->ctx, "Destroying cgroup %s\n", pakfire_cgroup_name(cgroup));
// Kill everything in this group
r = pakfire_cgroup_killall(cgroup);
// Delete the directory
r = unlinkat(fd, cgroup->path, AT_REMOVEDIR);
if (r)
- CTX_ERROR(cgroup->ctx, "Could not destroy cgroup: %m\n");
+ ERROR(cgroup->ctx, "Could not destroy cgroup: %m\n");
// Close fd
close(fd);
if (r)
return r;
- CTX_DEBUG(cgroup->ctx, "%s: Setting guaranteed memory to %zu byte(s)\n",
+ DEBUG(cgroup->ctx, "%s: Setting guaranteed memory to %zu byte(s)\n",
pakfire_cgroup_name(cgroup), mem);
// Set value
r = pakfire_cgroup_write(cgroup, "memory.min", "%zu\n", mem);
if (r)
- CTX_ERROR(cgroup->ctx, "%s: Could not set guaranteed memory: %m\n",
+ ERROR(cgroup->ctx, "%s: Could not set guaranteed memory: %m\n",
pakfire_cgroup_name(cgroup));
return r;
if (r)
return r;
- CTX_DEBUG(cgroup->ctx, "%s: Setting memory limit to %zu byte(s)\n",
+ DEBUG(cgroup->ctx, "%s: Setting memory limit to %zu byte(s)\n",
pakfire_cgroup_name(cgroup), mem);
// Set value
r = pakfire_cgroup_write(cgroup, "memory.max", "%zu\n", mem);
if (r)
- CTX_ERROR(cgroup->ctx, "%s: Could not set memory limit: %m\n",
+ ERROR(cgroup->ctx, "%s: Could not set memory limit: %m\n",
pakfire_cgroup_name(cgroup));
return r;
if (r)
return r;
- CTX_DEBUG(cgroup->ctx, "%s: Setting PID limit to %zu\n",
+ DEBUG(cgroup->ctx, "%s: Setting PID limit to %zu\n",
pakfire_cgroup_name(cgroup), limit);
// Set value
r = pakfire_cgroup_write(cgroup, "pids.max", "%zu\n", limit);
if (r)
- CTX_ERROR(cgroup->ctx, "%s: Could not set PID limit: %m\n",
+ ERROR(cgroup->ctx, "%s: Could not set PID limit: %m\n",
pakfire_cgroup_name(cgroup));
return r;
// Ignore the rest
default:
- CTX_DEBUG(cgroup->ctx, "%s: Unknown value in cgroup stats (%d): %s\n",
+ DEBUG(cgroup->ctx, "%s: Unknown value in cgroup stats (%d): %s\n",
pakfire_cgroup_name(cgroup), i, elem);
break;
}
// Check if we parsed both fields
if (i < 2) {
- CTX_ERROR(cgroup->ctx, "Could not parse line\n");
+ ERROR(cgroup->ctx, "Could not parse line\n");
return 1;
}
char buffer[BUFFER_SIZE];
- CTX_DEBUG(cgroup->ctx, "%s: Reading stats from %s\n", pakfire_cgroup_name(cgroup), path);
+ DEBUG(cgroup->ctx, "%s: Reading stats from %s\n", pakfire_cgroup_name(cgroup), path);
// Open the file
r = pakfire_cgroup_read(cgroup, path, buffer, sizeof(buffer));
}
}
- CTX_DEBUG(cgroup->ctx, "Unknown key for CPU stats: %s = %lu\n", key, val);
+ DEBUG(cgroup->ctx, "Unknown key for CPU stats: %s = %lu\n", key, val);
return 0;
}
}
// Log any unknown keys
- CTX_DEBUG(cgroup->ctx, "Unknown key for memory stats: %s = %lu\n", key, val);
+ DEBUG(cgroup->ctx, "Unknown key for memory stats: %s = %lu\n", key, val);
return 0;
}
ERROR:
if (r)
- CTX_ERROR(cgroup->ctx, "%s: Could not read cgroup stats: %m\n",
+ ERROR(cgroup->ctx, "%s: Could not read cgroup stats: %m\n",
pakfire_cgroup_name(cgroup));
return r;
return 1;
}
- CTX_DEBUG(cgroup->ctx, "%s: Total CPU time usage: %lu\n",
+ DEBUG(cgroup->ctx, "%s: Total CPU time usage: %lu\n",
pakfire_cgroup_name(cgroup), stats->cpu.usage_usec);
return 0;
// Check if any error occured
if (ferror(f)) {
- CTX_ERROR(ctx, "Read error: %m\n");
+ ERROR(ctx, "Read error: %m\n");
return -errno;
}
// Write the block to the archive
bytes_written = archive_write_data(archive, buffer, bytes_read);
if (bytes_written < bytes_read) {
- CTX_ERROR(ctx, "Write error: %s\n", archive_error_string(archive));
+ ERROR(ctx, "Write error: %s\n", archive_error_string(archive));
return -errno;
}
}
// Write the header
r = archive_write_header(data->archive, entry);
if (r) {
- CTX_ERROR(data->ctx, "Error writing file header: %s\n",
+ ERROR(data->ctx, "Error writing file header: %s\n",
archive_error_string(data->archive));
goto ERROR;
}
// Setup the link resolver
data.linkresolver = archive_entry_linkresolver_new();
if (!data.linkresolver) {
- CTX_ERROR(ctx, "Could not setup link resolver: m\n");
+ ERROR(ctx, "Could not setup link resolver: m\n");
goto ERROR;
}
// Open a new archive
a = archive_write_new();
if (!a) {
- CTX_ERROR(ctx, "archive_write_new() failed\n");
+ ERROR(ctx, "archive_write_new() failed\n");
r = 1;
goto ERROR;
}
// Use the PAX format
r = archive_write_set_format_pax(a);
if (r) {
- CTX_ERROR(ctx, "Could not set format to PAX: %s\n", archive_error_string(a));
+ ERROR(ctx, "Could not set format to PAX: %s\n", archive_error_string(a));
goto ERROR;
}
// Store any extended attributes in the SCHILY headers
r = archive_write_set_format_option(a, "pax", "xattrheader", "SCHILY");
if (r) {
- CTX_ERROR(ctx, "Could not set xattrheader option: %s\n", archive_error_string(a));
+ ERROR(ctx, "Could not set xattrheader option: %s\n", archive_error_string(a));
goto ERROR;
}
// Enable Zstd
r = archive_write_add_filter_zstd(a);
if (r) {
- CTX_ERROR(ctx, "Could not enable Zstandard compression: %s\n",
+ ERROR(ctx, "Could not enable Zstandard compression: %s\n",
archive_error_string(a));
goto ERROR;
}
r = archive_write_set_filter_option(a, NULL, "compression-level", value);
if (r) {
- CTX_ERROR(ctx, "Could not set Zstandard compression level: %s\n",
+ ERROR(ctx, "Could not set Zstandard compression level: %s\n",
archive_error_string(a));
goto ERROR;
}
if (processors > 1) {
r = pakfire_string_format(value, "%ld", processors);
if (r) {
- CTX_ERROR(ctx, "Could not format threads: %m\n");
+ ERROR(ctx, "Could not format threads: %m\n");
goto ERROR;
}
// Try using multiple threads
r = archive_write_set_filter_option(a, NULL, "threads", value);
if (r) {
- CTX_ERROR(ctx, "Could not enable %ld threads for compression: %s\n",
+ ERROR(ctx, "Could not enable %ld threads for compression: %s\n",
processors, archive_error_string(a));
goto ERROR;
}
if (f) {
r = archive_write_open_FILE(a, f);
if (r) {
- CTX_ERROR(ctx, "archive_write_open_FILE() failed: %s\n", archive_error_string(a));
+ ERROR(ctx, "archive_write_open_FILE() failed: %s\n", archive_error_string(a));
goto ERROR;
}
}
static int pakfire_ctx_default_confirm_callback(struct pakfire_ctx* ctx,
struct pakfire* pakfire, void* data, const char* message, const char* question) {
// Just log the message
- CTX_INFO(ctx, "%s\n", message);
+ INFO(ctx, "%s\n", message);
return 0;
}
if (!ctx->share) {
ctx->share = curl_share_init();
if (!ctx->share) {
- CTX_ERROR(ctx, "Could not setup cURL share handle\n");
+ ERROR(ctx, "Could not setup cURL share handle\n");
goto ERROR;
}
// Share connections between handles
r = curl_share_setopt(ctx->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
if (r) {
- CTX_ERROR(ctx, "Could not configure the share handle: %s\n", curl_share_strerror(r));
+ ERROR(ctx, "Could not configure the share handle: %s\n", curl_share_strerror(r));
goto ERROR;
}
}
// Allocate a new context
ctx->magic = magic_open(MAGIC_MIME_TYPE | MAGIC_ERROR | MAGIC_NO_CHECK_TOKENS);
if (!ctx->magic) {
- CTX_ERROR(ctx, "Could not allocate magic context: %m\n");
+ ERROR(ctx, "Could not allocate magic context: %m\n");
return NULL;
}
// Load the database
r = magic_load(ctx->magic, NULL);
if (r) {
- CTX_ERROR(ctx, "Could not open the magic database: %s\n", magic_error(ctx->magic));
+ ERROR(ctx, "Could not open the magic database: %s\n", magic_error(ctx->magic));
goto ERROR;
}
}
const struct signalfd_siginfo* si, void* data) {
struct pakfire_daemon* daemon = data;
- CTX_DEBUG(daemon->ctx, "Received signal to terminate...\n");
+ DEBUG(daemon->ctx, "Received signal to terminate...\n");
// Terminate all jobs
pakfire_daemon_terminate_jobs(daemon);
// Reset the timer
r = sd_event_source_set_time_relative(daemon->stats_timer, next);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not set the stat timer: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not set the stat timer: %s\n", strerror(-r));
return r;
}
// Don't do anything if we don't have a control connection
if (!daemon->control) {
- CTX_DEBUG(daemon->ctx, "Won't send stats without a control connection\n");
+ DEBUG(daemon->ctx, "Won't send stats without a control connection\n");
return 0;
}
- CTX_DEBUG(daemon->ctx, "Submitting stats...\n");
+ DEBUG(daemon->ctx, "Submitting stats...\n");
// Fetch the distro
const struct pakfire_distro* distro = pakfire_ctx_get_distro(daemon->ctx);
// Fetch CPU info
r = pakfire_cpuinfo(&cpuinfo);
if (r) {
- CTX_ERROR(daemon->ctx, "Failed to fetch CPU info: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Failed to fetch CPU info: %s\n", strerror(-r));
goto ERROR;
}
// Fetch CPU stats
r = pakfire_cpustat(&cpustat);
if (r) {
- CTX_ERROR(daemon->ctx, "Failed to fetch CPU stats: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Failed to fetch CPU stats: %s\n", strerror(-r));
goto ERROR;
}
// Fetch load average
r = pakfire_loadavg(&loadavg);
if (r) {
- CTX_ERROR(daemon->ctx, "Failed to fetch load average: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Failed to fetch load average: %s\n", strerror(-r));
goto ERROR;
}
// Fetch meminfo
r = pakfire_meminfo(&meminfo);
if (r) {
- CTX_ERROR(daemon->ctx, "Failed to fetch meminfo: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Failed to fetch meminfo: %s\n", strerror(-r));
goto ERROR;
}
// Fetch native arch
arch = pakfire_arch_native();
if (!arch) {
- CTX_ERROR(daemon->ctx, "Failed to fetch native arch: %s\n", strerror(errno));
+ ERROR(daemon->ctx, "Failed to fetch native arch: %s\n", strerror(errno));
r = -errno;
goto ERROR;
}
// Fetch the data from the message
if (!json_object_object_get_ex(m, "data", &data)) {
- CTX_ERROR(daemon->ctx, "Job does not have any data\n");
+ ERROR(daemon->ctx, "Job does not have any data\n");
return -EINVAL;
}
// Create a new job
r = pakfire_job_create(&job, daemon->ctx, daemon, data);
if (r) {
- CTX_ERROR(daemon->ctx, "Could not create a new job: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not create a new job: %s\n", strerror(-r));
goto ERROR;
}
// Fetch the message type
if (!json_object_object_get_ex(m, "type", &type)) {
- CTX_ERROR(daemon->ctx, "Invalid message with missing type\n");
+ ERROR(daemon->ctx, "Invalid message with missing type\n");
return -EINVAL;
}
r = pakfire_daemon_job(daemon, m);
} else {
- CTX_ERROR(daemon->ctx, "Unknown message. Ignoring:\n%s\n",
+ ERROR(daemon->ctx, "Unknown message. Ignoring:\n%s\n",
json_object_to_json_string_ext(m, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY));
r = 0;
daemon->control = NULL;
}
- CTX_INFO(daemon->ctx, "Will attempt to reconnect in %u second(s)\n",
+ INFO(daemon->ctx, "Will attempt to reconnect in %u second(s)\n",
daemon->reconnect_holdoff / 1000000);
// Set the reconnection timer
r = sd_event_source_set_time_relative(daemon->connect_timer, daemon->reconnect_holdoff);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not set the reconnection timer: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not set the reconnection timer: %s\n", strerror(-r));
return r;
}
// Activate the timer
r = sd_event_source_set_enabled(daemon->connect_timer, SD_EVENT_ONESHOT);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not activate the connect timer: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not activate the connect timer: %s\n", strerror(-r));
return r;
}
struct pakfire_daemon* daemon = data;
int r;
- CTX_DEBUG(daemon->ctx, "Connected!\n");
+ DEBUG(daemon->ctx, "Connected!\n");
// Store a reference to the control connection
daemon->control = pakfire_xfer_ref(xfer);
r = sd_event_add_time_relative(daemon->loop, &daemon->stats_timer,
CLOCK_MONOTONIC, 0, 0, pakfire_daemon_submit_stats, daemon);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not register the stat timer: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not register the stat timer: %s\n", strerror(-r));
return r;
}
// Submit stats continuously
r = sd_event_source_set_enabled(daemon->stats_timer, SD_EVENT_ON);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not activate the stat timer: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not activate the stat timer: %s\n", strerror(-r));
return r;
}
struct pakfire_xfer* xfer = NULL;
int r;
- CTX_INFO(daemon->ctx, "Connecting...\n");
+ INFO(daemon->ctx, "Connecting...\n");
// Create a new xfer
r = pakfire_daemon_xfer_create(&xfer, daemon, "/api/v1/builders/control");
// Fetch a reference to the default event loop
r = sd_event_default(&daemon->loop);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not setup event loop: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not setup event loop: %s\n", strerror(-r));
return r;
}
// Enable the watchdog
r = sd_event_set_watchdog(daemon->loop, 1);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not activate watchdog: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not activate watchdog: %s\n", strerror(-r));
return r;
}
r = sd_event_add_signal(daemon->loop, NULL, SIGTERM|SD_EVENT_SIGNAL_PROCMASK,
pakfire_daemon_terminate, daemon);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not register handling SIGTERM: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not register handling SIGTERM: %s\n", strerror(-r));
return r;
}
r = sd_event_add_signal(daemon->loop, NULL, SIGINT|SD_EVENT_SIGNAL_PROCMASK,
pakfire_daemon_terminate, daemon);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not register handling SIGINT: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not register handling SIGINT: %s\n", strerror(-r));
return r;
}
r = sd_event_add_signal(daemon->loop, NULL, SIGCHLD|SD_EVENT_SIGNAL_PROCMASK,
pakfire_daemon_SIGCHLD, daemon);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not register handling SIGCHLD: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not register handling SIGCHLD: %s\n", strerror(-r));
return r;
}
r = sd_event_add_time_relative(daemon->loop, &daemon->connect_timer,
CLOCK_MONOTONIC, 0, 0, pakfire_daemon_connect, daemon);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not register the connection timer: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not register the connection timer: %s\n", strerror(-r));
return r;
}
// Fetch the configuration
config = pakfire_ctx_get_config(daemon->ctx);
if (!config) {
- CTX_ERROR(daemon->ctx, "Could not fetch configuration: %m\n");
+ ERROR(daemon->ctx, "Could not fetch configuration: %m\n");
r = -errno;
goto ERROR;
}
// Launch the event loop
r = sd_event_loop(daemon->loop);
if (r < 0) {
- CTX_ERROR(daemon->ctx, "Could not run the event loop: %s\n", strerror(-r));
+ ERROR(daemon->ctx, "Could not run the event loop: %s\n", strerror(-r));
goto ERROR;
}
Called after a job has exited
*/
int pakfire_daemon_job_finished(struct pakfire_daemon* daemon, struct pakfire_job* job) {
- CTX_DEBUG(daemon->ctx, "Removing job %p\n", job);
+ DEBUG(daemon->ctx, "Removing job %p\n", job);
for (unsigned int i = 0; i < MAX_JOBS; i++) {
if (daemon->jobs[i] != job)
static void logging_callback(void* data, int r, const char* msg) {
struct pakfire_ctx* ctx = data;
- CTX_ERROR(ctx, "Database Error: %s: %s\n",
+ ERROR(ctx, "Database Error: %s: %s\n",
sqlite3_errstr(r), msg);
}
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
sql, sqlite3_errmsg(db->handle));
goto ERROR;
}
// Bind type
r = sqlite3_bind_text(stmt, 1, "table", -1, NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Bind name
r = sqlite3_bind_text(stmt, 2, table, -1, NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r != SQLITE_OK) {
- //CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ //ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
// sql, sqlite3_errmsg(db->handle));
return NULL;
}
// Bind key
r = sqlite3_bind_text(stmt, 1, key, strlen(key), NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Read value
val = sqlite3_column_value(stmt, 0);
if (!val) {
- CTX_ERROR(db->ctx, "Could not read value\n");
+ ERROR(db->ctx, "Could not read value\n");
goto ERROR;
}
sqlite3_stmt* stmt = NULL;
int r;
- CTX_DEBUG(db->ctx, "Setting %s to '%s'\n", key, val);
+ DEBUG(db->ctx, "Setting %s to '%s'\n", key, val);
const char* sql = "INSERT INTO settings(key, val) VALUES(?, ?) \
ON CONFLICT (key) DO UPDATE SET val = excluded.val";
// Prepare statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
sql, sqlite3_errmsg(db->handle));
return 1;
}
// Bind key
r = sqlite3_bind_text(stmt, 1, key, strlen(key), NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Bind val
r = sqlite3_bind_text(stmt, 2, val, strlen(val), NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
sqlite3_stmt* stmt = NULL;
int r;
- CTX_DEBUG(db->ctx, "Setting %s to '%d'\n", key, val);
+ DEBUG(db->ctx, "Setting %s to '%d'\n", key, val);
const char* sql = "INSERT INTO settings(key, val) VALUES(?, ?) \
ON CONFLICT (key) DO UPDATE SET val = excluded.val";
// Prepare statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
sql, sqlite3_errmsg(db->handle));
return 1;
}
// Bind key
r = sqlite3_bind_text(stmt, 1, key, strlen(key), NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind key: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Bind val
r = sqlite3_bind_int64(stmt, 2, val);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind val: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
t = sqlite3_value_int64(value);
sqlite3_value_free(value);
} else {
- CTX_DEBUG(db->ctx, "Could not find last modification timestamp\n");
+ DEBUG(db->ctx, "Could not find last modification timestamp\n");
}
return t;
static int pakfire_db_execute(struct pakfire_db* db, const char* stmt) {
int r;
- CTX_DEBUG(db->ctx, "Executing database query: %s\n", stmt);
+ DEBUG(db->ctx, "Executing database query: %s\n", stmt);
do {
r = sqlite3_exec(db->handle, stmt, NULL, NULL, NULL);
// Log any errors
if (r) {
- CTX_ERROR(db->ctx, "Database query failed: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Database query failed: %s\n", sqlite3_errmsg(db->handle));
}
return r;
// Close database handle
int r = sqlite3_close(db->handle);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not close database handle: %s\n",
+ ERROR(db->ctx, "Could not close database handle: %s\n",
sqlite3_errmsg(db->handle));
}
}
int schema = sqlite3_value_int64(value);
sqlite3_value_free(value);
- CTX_DEBUG(db->ctx, "Database has schema version %d\n", schema);
+ DEBUG(db->ctx, "Database has schema version %d\n", schema);
return schema;
}
// Set architecture
r = pakfire_db_set_string(db, "arch", arch);
if (r) {
- CTX_ERROR(db->ctx, "Could not set architecture\n");
+ ERROR(db->ctx, "Could not set architecture\n");
return r;
}
break;
default:
- CTX_ERROR(db->ctx, "Cannot migrate database from schema %d\n", db->schema);
+ ERROR(db->ctx, "Cannot migrate database from schema %d\n", db->schema);
goto ROLLBACK;
}
// Fetch database architecture
char* db_arch = pakfire_db_get_string(db, "arch");
if (!db_arch) {
- CTX_ERROR(db->ctx, "Database is of an unknown architecture\n");
+ ERROR(db->ctx, "Database is of an unknown architecture\n");
goto ERROR;
}
// Check if the schema is recent enough
if (db->schema && db->schema < SCHEMA_MIN_SUP) {
- CTX_ERROR(db->ctx, "Database schema %d is not supported by this version of Pakfire\n",
+ ERROR(db->ctx, "Database schema %d is not supported by this version of Pakfire\n",
db->schema);
return 1;
}
// Read modification timestamp
db->last_modified_at = pakfire_read_modification_time(db);
- CTX_DEBUG(db->ctx, "The database was last modified at %ld\n", db->last_modified_at);
+ DEBUG(db->ctx, "The database was last modified at %ld\n", db->last_modified_at);
// Done when not in read-write mode
if (db->mode != PAKFIRE_DB_READWRITE)
// Set database journal to WAL
r = pakfire_db_execute(db, "PRAGMA journal_mode = WAL");
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not set journal mode to WAL: %s\n",
+ ERROR(db->ctx, "Could not set journal mode to WAL: %s\n",
sqlite3_errmsg(db->handle));
return 1;
}
// Disable autocheckpoint
r = sqlite3_wal_autocheckpoint(db->handle, 0);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not disable autocheckpoint: %s\n",
+ ERROR(db->ctx, "Could not disable autocheckpoint: %s\n",
sqlite3_errmsg(db->handle));
return 1;
}
// Try to open the sqlite3 database file
r = sqlite3_open_v2(o->path, &o->handle, sqlite3_flags, NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(o->ctx, "Could not open database %s: %s\n",
+ ERROR(o->ctx, "Could not open database %s: %s\n",
o->path, sqlite3_errmsg(o->handle));
r = 1;
r = sqlite3_prepare_v2(db->handle, "PRAGMA integrity_check", -1, &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare integrity check: %s\n",
+ ERROR(db->ctx, "Could not prepare integrity check: %s\n",
sqlite3_errmsg(db->handle));
return 1;
}
errors++;
// Log the message
- CTX_ERROR(db->ctx, "%s\n", error);
+ ERROR(db->ctx, "%s\n", error);
// Break on anything else
} else
sqlite3_finalize(stmt);
if (errors)
- CTX_ERROR(db->ctx, "Database integrity check failed\n");
+ ERROR(db->ctx, "Database integrity check failed\n");
else
- CTX_INFO(db->ctx, "Database integrity check passed\n");
+ INFO(db->ctx, "Database integrity check passed\n");
return errors;
}
r = sqlite3_prepare_v2(db->handle, "PRAGMA foreign_key_check", -1, &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare foreign key check: %s\n",
+ ERROR(db->ctx, "Could not prepare foreign key check: %s\n",
sqlite3_errmsg(db->handle));
return 1;
}
errors++;
// Log the message
- CTX_ERROR(db->ctx, "Foreign key violation found in %s, row %lu: "
+ ERROR(db->ctx, "Foreign key violation found in %s, row %lu: "
"%lu does not exist in table %s\n", table, rowid, foreign_rowid, foreign_table);
// Break on anything else
sqlite3_finalize(stmt);
if (errors)
- CTX_ERROR(db->ctx, "Foreign key check failed\n");
+ ERROR(db->ctx, "Foreign key check failed\n");
else
- CTX_INFO(db->ctx, "Foreign key check passed\n");
+ INFO(db->ctx, "Foreign key check passed\n");
return errors;
}
int r = sqlite3_prepare_v2(db->handle, "SELECT COUNT(*) FROM packages", -1, &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s\n",
sqlite3_errmsg(db->handle));
return -1;
}
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, -1, &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
sql, sqlite3_errmsg(db->handle));
goto END;
}
// Bind package ID
r = sqlite3_bind_int64(stmt, 1, id);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind id: %s\n",
+ ERROR(db->ctx, "Could not bind id: %s\n",
sqlite3_errmsg(db->handle));
goto END;
}
// Bind type
r = sqlite3_bind_text(stmt, 2, dep->name, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind type: %s\n",
+ ERROR(db->ctx, "Could not bind type: %s\n",
sqlite3_errmsg(db->handle));
goto END;
}
// Bind dependency
r = sqlite3_bind_text(stmt, 3, *d, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind dependency: %s\n",
+ ERROR(db->ctx, "Could not bind dependency: %s\n",
sqlite3_errmsg(db->handle));
goto END;
}
// Get the filelist from the archive
struct pakfire_filelist* filelist = pakfire_archive_get_filelist(archive);
if (!filelist) {
- CTX_ERROR(db->ctx, "Could not fetch filelist from archive\n");
+ ERROR(db->ctx, "Could not fetch filelist from archive\n");
return 1;
}
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
sql, sqlite3_errmsg(db->handle));
goto END;
}
// Bind package ID
r = sqlite3_bind_int64(stmt, 1, id);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
r = sqlite3_bind_text(stmt, 2, path, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind path: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind path: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
r = sqlite3_bind_int64(stmt, 3, size);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
// Bind config - XXX TODO
r = sqlite3_bind_null(stmt, 4);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind config: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind config: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
// Bind datafile - XXX TODO
r = sqlite3_bind_null(stmt, 5);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind datafile: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind datafile: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
r = sqlite3_bind_int64(stmt, 6, mode);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind mode: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind mode: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
r = sqlite3_bind_text(stmt, 7, uname, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind uname: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind uname: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
r = sqlite3_bind_text(stmt, 8, gname, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind gname: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind gname: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
r = sqlite3_bind_int64(stmt, 9, ctime);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind ctime: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind ctime: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
r = sqlite3_bind_int64(stmt, 10, mtime);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind mtime: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind mtime: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
if (mimetype) {
r = sqlite3_bind_text(stmt, 11, mimetype, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind MIME type: %s\n",
+ ERROR(db->ctx, "Could not bind MIME type: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
} else {
r = sqlite3_bind_null(stmt, 11);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind an empty MIME type: %s\n",
+ ERROR(db->ctx, "Could not bind an empty MIME type: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// Bind capabilities - XXX TODO
r = sqlite3_bind_null(stmt, 12);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind capabilities: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind capabilities: %s\n", sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
}
// SHA2-512 Digest
r = pakfire_db_bind_digest(db, stmt, 13, file, PAKFIRE_DIGEST_SHA2_512);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind SHA2-512 digest: %s\n",
+ ERROR(db->ctx, "Could not bind SHA2-512 digest: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// SHA2-256 Digest
r = pakfire_db_bind_digest(db, stmt, 14, file, PAKFIRE_DIGEST_SHA2_256);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind SHA2-256 digest: %s\n",
+ ERROR(db->ctx, "Could not bind SHA2-256 digest: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// BLAKE2b512 Digest
r = pakfire_db_bind_digest(db, stmt, 15, file, PAKFIRE_DIGEST_BLAKE2B512);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind BLAKE2b512 digest: %s\n",
+ ERROR(db->ctx, "Could not bind BLAKE2b512 digest: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// BLAKE2s256 Digest
r = pakfire_db_bind_digest(db, stmt, 16, file, PAKFIRE_DIGEST_BLAKE2S256);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind BLAKE2s256 digest: %s\n",
+ ERROR(db->ctx, "Could not bind BLAKE2s256 digest: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// SHA3-512 Digest
r = pakfire_db_bind_digest(db, stmt, 17, file, PAKFIRE_DIGEST_SHA3_512);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind SHA3-512 digest: %s\n",
+ ERROR(db->ctx, "Could not bind SHA3-512 digest: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// SHA3-256 Digest
r = pakfire_db_bind_digest(db, stmt, 18, file, PAKFIRE_DIGEST_SHA3_256);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind SHA3-256 digest: %s\n",
+ ERROR(db->ctx, "Could not bind SHA3-256 digest: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// Check for errors
if (r != SQLITE_DONE) {
- CTX_ERROR(db->ctx, "Could not add file to database: %s\n",
+ ERROR(db->ctx, "Could not add file to database: %s\n",
sqlite3_errmsg(db->handle));
pakfire_file_unref(file);
goto END;
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, -1, &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
sql, sqlite3_errmsg(db->handle));
goto END;
}
// Bind package ID
r = sqlite3_bind_int64(stmt, 1, id);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind id: %s\n", sqlite3_errmsg(db->handle));
pakfire_scriptlet_unref(scriptlet);
goto END;
}
// Bind handle
r = sqlite3_bind_text(stmt, 2, *type, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
pakfire_scriptlet_unref(scriptlet);
goto END;
}
// Bind scriptlet
r = sqlite3_bind_text(stmt, 3, data, size, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind scriptlet: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind scriptlet: %s\n", sqlite3_errmsg(db->handle));
pakfire_scriptlet_unref(scriptlet);
goto END;
}
// Check for errors
if (r != SQLITE_DONE) {
- CTX_ERROR(db->ctx, "Could not add scriptlet to database: %s\n",
+ ERROR(db->ctx, "Could not add scriptlet to database: %s\n",
sqlite3_errmsg(db->handle));
pakfire_scriptlet_unref(scriptlet);
goto END;
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r != SQLITE_OK) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s: %s\n",
sql, sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 1, name, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind name: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 2, evr, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind evr: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind evr: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 3, arch, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind arch: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind arch: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 4, __groups, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind groups: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind groups: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 5, filename, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind filename: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind filename: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_int64(stmt, 6, size);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind size: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_int64(stmt, 7, inst_size);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind inst_size: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind inst_size: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Fetch the digest
digest = pakfire_package_get_digest(pkg, &digest_type, &digest_length);
if (!digest) {
- CTX_ERROR(db->ctx, "Could not fetch the package's digest: %m\n");
+ ERROR(db->ctx, "Could not fetch the package's digest: %m\n");
r = 1;
goto ERROR;
}
// Set the digest type
r = sqlite3_bind_int64(stmt, 8, digest_type);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind digest type: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind digest type: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Set the digest
r = sqlite3_bind_blob(stmt, 9, digest, digest_length, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind digest: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind digest: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 10, license, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind license: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind license: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 11, summary, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind summary: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind summary: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 12, description, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind description: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind description: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 13, uuid, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 14, vendor, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind vendor: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind vendor: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 15, build_host, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind build_host: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind build_host: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_int64(stmt, 16, build_time);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind build_time: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind build_time: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// installed by the user?
r = sqlite3_bind_int(stmt, 18, userinstalled);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind userinstalled: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind userinstalled: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
} while (r == SQLITE_BUSY);
if (r != SQLITE_DONE) {
- CTX_ERROR(db->ctx, "Could not add package to database: %s\n",
+ ERROR(db->ctx, "Could not add package to database: %s\n",
sqlite3_errmsg(db->handle));
r = 1;
goto ERROR;
// Fetch the package's UUID
const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
if (!uuid) {
- CTX_ERROR(db->ctx, "Package has no UUID\n");
+ ERROR(db->ctx, "Package has no UUID\n");
r = 1;
goto ERROR;
}
r = sqlite3_prepare_v2(db->handle,
"DELETE FROM packages WHERE uuid = ?", -1, &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s\n",
sqlite3_errmsg(db->handle));
goto ERROR;
}
// Bind UUID
r = sqlite3_bind_text(stmt, 1, uuid, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Check if we have been successful
if (r != SQLITE_DONE) {
- CTX_ERROR(db->ctx, "Could not delete package %s\n", uuid);
+ ERROR(db->ctx, "Could not delete package %s\n", uuid);
r = 1;
goto ERROR;
}
// Fetch the package's UUID
const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
if (!uuid) {
- CTX_ERROR(db->ctx, "Package has no UUID\n");
+ ERROR(db->ctx, "Package has no UUID\n");
goto ERROR;
}
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
sql, sqlite3_errmsg(db->handle));
goto ERROR;
}
// Bind UUID
r = sqlite3_bind_text(stmt, 1, uuid, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind uuid: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
r = sqlite3_bind_text(stmt, 2, type, -1, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind type: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
- CTX_DEBUG(db->ctx, "Searching for scriptlet for package %s of type %s\n", uuid, type);
+ DEBUG(db->ctx, "Searching for scriptlet for package %s of type %s\n", uuid, type);
// Execute query
do {
// Name
const char* name = (const char*)sqlite3_column_text(stmt, 0);
if (!name) {
- CTX_ERROR(db->ctx, "Could not read name: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not read name: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// EVR
const char* evr = (const char*)sqlite3_column_text(stmt, 1);
if (!evr) {
- CTX_ERROR(db->ctx, "Could not read evr: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not read evr: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Arch
const char* arch = (const char*)sqlite3_column_text(stmt, 2);
if (!arch) {
- CTX_ERROR(db->ctx, "Could not read arch: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not read arch: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
// Create package
r = pakfire_package_create(&pkg, db->pakfire, repo, name, evr, arch);
if (r) {
- CTX_ERROR(db->ctx, "Could not create package '%s-%s.%s': %m\n", name, evr, arch);
+ ERROR(db->ctx, "Could not create package '%s-%s.%s': %m\n", name, evr, arch);
goto ERROR;
}
sqlite3_stmt* stmt = NULL;
int r = 1;
- CTX_DEBUG(db->ctx, "Loading package database...\n");
+ DEBUG(db->ctx, "Loading package database...\n");
// Drop contents of the repository
pakfire_repo_clear(repo);
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
sql, sqlite3_errmsg(db->handle));
goto ERROR;
}
// Save time when we finished
t_end = clock();
- CTX_DEBUG(db->ctx, "Loading package database completed in %.4fms\n",
+ DEBUG(db->ctx, "Loading package database completed in %.4fms\n",
(double)(t_end - t_start) * 1000 / CLOCKS_PER_SEC);
// Mark repository as changed
ERROR:
if (r) {
- CTX_ERROR(db->ctx, "Failed reading package database: %m\n");
+ ERROR(db->ctx, "Failed reading package database: %m\n");
pakfire_repo_clear(repo);
}
// Abort if no path is set
if (!path) {
- CTX_ERROR(db->ctx, "File has no path\n");
+ ERROR(db->ctx, "File has no path\n");
r = -errno;
goto ERROR;
}
// Abort if no user is set
if (!uname) {
- CTX_ERROR(db->ctx, "%s: No user\n", path);
+ ERROR(db->ctx, "%s: No user\n", path);
r = 1;
goto ERROR;
}
// Set uname
r = pakfire_file_set_uname(file, uname);
if (r) {
- CTX_ERROR(db->ctx, "%s: Could not set user '%s': %m\n", path, uname);
+ ERROR(db->ctx, "%s: Could not set user '%s': %m\n", path, uname);
goto ERROR;
}
// Abort if no group is set
if (!gname) {
- CTX_ERROR(db->ctx, "%s: No group\n", path);
+ ERROR(db->ctx, "%s: No group\n", path);
r = 1;
goto ERROR;
}
// Set gname
r = pakfire_file_set_gname(file, gname);
if (r) {
- CTX_ERROR(db->ctx, "%s: Could not set group '%s': %m\n", path, gname);
+ ERROR(db->ctx, "%s: Could not set group '%s': %m\n", path, gname);
goto ERROR;
}
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
sql, sqlite3_errmsg(db->handle));
goto ERROR;
}
ERROR:
if (r)
- CTX_ERROR(db->ctx, "Could not fetch filelist: %m\n");
+ ERROR(db->ctx, "Could not fetch filelist: %m\n");
if (stmt)
sqlite3_finalize(stmt);
// Fetch the package ID
uint64_t id = pakfire_package_get_num(pkg, PAKFIRE_PKG_DBID, 0);
if (!id) {
- CTX_ERROR(db->ctx, "Package did not have an ID\n");
+ ERROR(db->ctx, "Package did not have an ID\n");
return 1;
}
// Create a new filelist
r = pakfire_filelist_create(&fl, db->pakfire);
if (r) {
- CTX_ERROR(db->ctx, "Could not create filelist: %m\n");
+ ERROR(db->ctx, "Could not create filelist: %m\n");
goto ERROR;
}
// Prepare the statement
r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
if (r) {
- CTX_ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
+ ERROR(db->ctx, "Could not prepare SQL statement: %s %s\n",
sql, sqlite3_errmsg(db->handle));
goto ERROR;
}
// Bind package ID
r = sqlite3_bind_int64(stmt, 1, id);
if (r) {
- CTX_ERROR(db->ctx, "Could not bind package ID: %s\n", sqlite3_errmsg(db->handle));
+ ERROR(db->ctx, "Could not bind package ID: %s\n", sqlite3_errmsg(db->handle));
goto ERROR;
}
return 0;
// Otherwise set an error
- CTX_ERROR(ctx, "Digest is of an unexpected length\n");
+ ERROR(ctx, "Digest is of an unexpected length\n");
return -ENOMSG;
}
// Setup a new context
evp_ctx = EVP_MD_CTX_new();
if (!evp_ctx) {
- CTX_ERROR(ctx, "Could not initialize OpenSSL context: %s\n",
+ ERROR(ctx, "Could not initialize OpenSSL context: %s\n",
ERR_error_string(ERR_get_error(), NULL));
goto ERROR;
}
// Setup digest
r = EVP_DigestInit_ex(evp_ctx, md, NULL);
if (r != 1) {
- CTX_ERROR(ctx, "Could not setup digest: %s\n",
+ ERROR(ctx, "Could not setup digest: %s\n",
ERR_error_string(ERR_get_error(), NULL));
goto ERROR;
}
// Update digest
r = EVP_DigestUpdate(evp_ctx, buffer, length);
if (r != 1) {
- CTX_ERROR(ctx, "EVP_Digest_Update() failed: %s\n",
+ ERROR(ctx, "EVP_Digest_Update() failed: %s\n",
ERR_error_string(ERR_get_error(), NULL));
return 1;
}
// Finalize digest
r = EVP_DigestFinal_ex(evp_ctx, digest, NULL);
if (r != 1) {
- CTX_ERROR(ctx, "EVP_DigestFinal_ex() failed: %s\n",
+ ERROR(ctx, "EVP_DigestFinal_ex() failed: %s\n",
ERR_error_string(ERR_get_error(), NULL));
return 1;
}
char* hexdigest1 = __pakfire_hexlify(digest1, length);
char* hexdigest2 = __pakfire_hexlify(digest2, length);
- CTX_DEBUG(ctx, "%s digest does not match:\n", what);
+ DEBUG(ctx, "%s digest does not match:\n", what);
if (hexdigest1)
- CTX_DEBUG(ctx, " Digest 1: %s\n", hexdigest1);
+ DEBUG(ctx, " Digest 1: %s\n", hexdigest1);
if (hexdigest2)
- CTX_DEBUG(ctx, " Digest 2: %s\n", hexdigest2);
+ DEBUG(ctx, " Digest 2: %s\n", hexdigest2);
if (hexdigest1)
free(hexdigest1);
// Find all macros
- CTX_DEBUG(ctx, "Searching for macros in %s\n", PAKFIRE_MACROS_GLOB_PATTERN);
+ DEBUG(ctx, "Searching for macros in %s\n", PAKFIRE_MACROS_GLOB_PATTERN);
glob_t globmacros;
r = glob(PAKFIRE_MACROS_GLOB_PATTERN, 0, NULL, &globmacros);
goto ERROR;
default:
- CTX_ERROR(ctx, "glob() returned an unhandled error: %d\n", r);
+ ERROR(ctx, "glob() returned an unhandled error: %d\n", r);
goto ERROR;
}
- CTX_DEBUG(ctx, "Found %zu macro(s)\n", globmacros.gl_pathc);
+ DEBUG(ctx, "Found %zu macro(s)\n", globmacros.gl_pathc);
// Read all macros
for (unsigned int i = 0; i < globmacros.gl_pathc; i++) {
// Finally, parse the makefile
r = pakfire_parser_read_file(*parser, path, error);
if (r) {
- CTX_ERROR(ctx, "Could not read makefile %s: %m\n", path);
+ ERROR(ctx, "Could not read makefile %s: %m\n", path);
goto ERROR;
}
// Create mirrorlist
r = pakfire_mirrorlist_create(&m, ctx);
if (r) {
- CTX_ERROR(ctx, "Could not create the mirrorlist\n");
+ ERROR(ctx, "Could not create the mirrorlist\n");
goto ERROR;
}
// Add all mirrors
const char* source = strtok_r(sources, " ", &p);
while (source) {
- CTX_DEBUG(ctx, "Adding source file %s\n", source);
+ DEBUG(ctx, "Adding source file %s\n", source);
r = pakfire_dist_add_source(pakfire, packager, pkg, ctx, mirrorlist, source);
if (r) {
- CTX_ERROR(ctx, "Could not add '%s' to package: %m\n", source);
+ ERROR(ctx, "Could not add '%s' to package: %m\n", source);
goto ERROR;
}
// Find the package directory
r = pakfire_dist_find_root(root, file);
if (r) {
- CTX_ERROR(ctx, "Could not find package root directory: %s\n", strerror(r));
+ ERROR(ctx, "Could not find package root directory: %s\n", strerror(r));
return r;
}
- CTX_DEBUG(ctx, "Adding all files in '%s' to package...\n", root);
+ DEBUG(ctx, "Adding all files in '%s' to package...\n", root);
// Create a new filelist
r = pakfire_filelist_create(&filelist, pakfire);
if (error)
pakfire_parser_error_unref(error);
else
- CTX_ERROR(ctx, "Could not read makefile: %m\n");
+ ERROR(ctx, "Could not read makefile: %m\n");
goto ERROR;
}
// The architecture is always "src"
r = pakfire_parser_set(makefile, NULL, "arch", "src", 0);
if (r) {
- CTX_ERROR(ctx, "Could not set architecture to 'src': %m\n");
+ ERROR(ctx, "Could not set architecture to 'src': %m\n");
goto ERROR;
}
// Match!
case 1:
- CTX_DEBUG(ctx, "%s matches check '%s'\n", path, check->path);
+ DEBUG(ctx, "%s matches check '%s'\n", path, check->path);
return check;
}
ERROR:
- CTX_ERROR(ctx, "Could not find FHS entry for %s: %m\n", path);
+ ERROR(ctx, "Could not find FHS entry for %s: %m\n", path);
return NULL;
}
// Check that none of the executable bits are set
if ((perms & (S_IWUSR|S_IWGRP|S_IWOTH)) == (S_IWUSR|S_IWGRP|S_IWOTH)) {
- CTX_DEBUG(ctx, "%s is world-writable\n", path);
+ DEBUG(ctx, "%s is world-writable\n", path);
return PAKFIRE_FHS_WORLDWRITABLE;
}
// Check if they match
if (check->perms != perms) {
- CTX_DEBUG(ctx, "%s: Permissions do not match\n", path);
+ DEBUG(ctx, "%s: Permissions do not match\n", path);
return PAKFIRE_FHS_PERMS_MISMATCH;
}
return 1;
if (strcmp(check->uname, uname) != 0) {
- CTX_DEBUG(ctx, "%s: uname does not match\n", path);
+ DEBUG(ctx, "%s: uname does not match\n", path);
return PAKFIRE_FHS_UNAME_MISMATCH;
}
}
return 1;
if (strcmp(check->gname, gname) != 0) {
- CTX_DEBUG(ctx, "%s: gname does not match\n", path);
+ DEBUG(ctx, "%s: gname does not match\n", path);
return PAKFIRE_FHS_GNAME_MISMATCH;
}
}
// Check that none of the executable bits are set
if (perms & (S_IXUSR|S_IXGRP|S_IXOTH)) {
- CTX_DEBUG(ctx, "%s must not be executable\n", path);
+ DEBUG(ctx, "%s must not be executable\n", path);
return PAKFIRE_FHS_NOEXEC;
}
// Find a check
check = pakfire_fhs_find_check(ctx, file);
if (!check) {
- CTX_ERROR(ctx, "Could not match file %s: %m\n", path);
+ ERROR(ctx, "Could not match file %s: %m\n", path);
return -errno;
}
// Should this file exist at all?
if (check->flags & PAKFIRE_FHS_CHECK_MUSTNOTEXIST) {
- CTX_DEBUG(ctx, "%s must not exist here\n", path);
+ DEBUG(ctx, "%s must not exist here\n", path);
return PAKFIRE_FHS_MUSTNOTEXIST;
}
// Allocate capabilities
file->caps = cap_init();
if (!file->caps) {
- CTX_ERROR(file->ctx, "Could not allocate capabilities: %m\n");
+ ERROR(file->ctx, "Could not allocate capabilities: %m\n");
r = 1;
goto ERROR;
}
if (cap_permitted) {
r = cap_set_flag(file->caps, CAP_PERMITTED, 1, caps, CAP_SET);
if (r) {
- CTX_ERROR(file->ctx, "Could not set capability %u: %m\n", cap);
+ ERROR(file->ctx, "Could not set capability %u: %m\n", cap);
goto ERROR;
}
}
if (cap_inheritable) {
r = cap_set_flag(file->caps, CAP_INHERITABLE, 1, caps, CAP_SET);
if (r) {
- CTX_ERROR(file->ctx, "Could not set capability %u: %m\n", cap);
+ ERROR(file->ctx, "Could not set capability %u: %m\n", cap);
goto ERROR;
}
}
if (cap_effective) {
r = cap_set_flag(file->caps, CAP_EFFECTIVE, 1, caps, CAP_SET);
if (r) {
- CTX_ERROR(file->ctx, "Could not set capability %u: %m\n", cap);
+ ERROR(file->ctx, "Could not set capability %u: %m\n", cap);
goto ERROR;
}
}
#ifdef ENABLE_DEBUG
char* text = cap_to_text(file->caps, NULL);
if (text) {
- CTX_DEBUG(file->ctx, "%s: Capabilities %s\n", pakfire_file_get_path(file), text);
+ DEBUG(file->ctx, "%s: Capabilities %s\n", pakfire_file_get_path(file), text);
cap_free(text);
}
#endif
// Fetch CAP_PERMITTED
r = cap_get_flag(file->caps, cap, CAP_PERMITTED, &cap_permitted);
if (r) {
- CTX_ERROR(file->ctx, "Could not fetch capability %u: %m\n", cap);
+ ERROR(file->ctx, "Could not fetch capability %u: %m\n", cap);
goto ERROR;
}
// Fetch CAP_INHERITABLE
r = cap_get_flag(file->caps, cap, CAP_INHERITABLE, &cap_inheritable);
if (r) {
- CTX_ERROR(file->ctx, "Could not fetch capability %u: %m\n", cap);
+ ERROR(file->ctx, "Could not fetch capability %u: %m\n", cap);
goto ERROR;
}
// Fetch CAP_EFFECTIVE
r = cap_get_flag(file->caps, cap, CAP_EFFECTIVE, &cap_effective);
if (r) {
- CTX_ERROR(file->ctx, "Could not fetch capability %u: %m\n", cap);
+ ERROR(file->ctx, "Could not fetch capability %u: %m\n", cap);
goto ERROR;
}
goto ERROR;
} else {
- CTX_DEBUG(file->ctx, "Received an unknown extended attribute: %s\n", attr);
+ DEBUG(file->ctx, "Received an unknown extended attribute: %s\n", attr);
}
}
if (file->caps) {
r = pakfire_file_write_fcaps(file, &cap_data);
if (r) {
- CTX_ERROR(file->ctx, "Could not export capabilities: %m\n");
+ ERROR(file->ctx, "Could not export capabilities: %m\n");
goto ERROR;
}
// Duplicate the file descriptor
file->fd = dup(fd);
if (file->fd < 0) {
- CTX_ERROR(file->ctx, "Could not duplicate file descriptor: %m\n");
+ ERROR(file->ctx, "Could not duplicate file descriptor: %m\n");
return -errno;
}
// Check buffer length
if (pakfire_digest_length(type) != length) {
- CTX_ERROR(file->ctx, "Digest has an incorrect length of %zu byte(s)\n", length);
+ ERROR(file->ctx, "Digest has an incorrect length of %zu byte(s)\n", length);
return -ENOMSG;
}
if (file->caps) {
text = cap_to_text(file->caps, &length);
if (!text) {
- CTX_ERROR(file->ctx, "Could not export capabilities: %m\n");
+ ERROR(file->ctx, "Could not export capabilities: %m\n");
goto ERROR;
}
FILE* f = fopen(path, "r+");
if (!f)
- CTX_ERROR(file->ctx, "Could not open %s: %m\n", path);
+ ERROR(file->ctx, "Could not open %s: %m\n", path);
return f;
}
const char* path = pakfire_file_get_path(file);
const char* abspath = pakfire_file_get_abspath(file);
- CTX_DEBUG(file->ctx, "Removing %s...\n", path);
+ DEBUG(file->ctx, "Removing %s...\n", path);
// We cannot delete if we don't have the absolute path
if (!abspath)
// Log anything else
default:
- CTX_ERROR(file->ctx, "Could not remove directory %s: %m\n", path);
+ ERROR(file->ctx, "Could not remove directory %s: %m\n", path);
break;
}
}
break;
default:
- CTX_ERROR(file->ctx, "Could not remove %s: %m\n", path);
+ ERROR(file->ctx, "Could not remove %s: %m\n", path);
break;
}
}
// Check the file
const char* mimetype = magic_file(magic, path);
if (!mimetype) {
- CTX_ERROR(file->ctx, "Could not classify %s: %s\n",
+ ERROR(file->ctx, "Could not classify %s: %s\n",
pakfire_file_get_path(file), magic_error(magic));
return 1;
}
- CTX_DEBUG(file->ctx, "Classified %s as %s\n", pakfire_file_get_path(file), mimetype);
+ DEBUG(file->ctx, "Classified %s as %s\n", pakfire_file_get_path(file), mimetype);
// Store the value
return pakfire_file_set_mimetype(file, mimetype);
static int setup_libelf(struct pakfire_ctx* ctx) {
// Initialize libelf
if (elf_version(EV_CURRENT) == EV_NONE) {
- CTX_ERROR(ctx, "Could not initialize libelf: %s\n", elf_errmsg(-1));
+ ERROR(ctx, "Could not initialize libelf: %s\n", elf_errmsg(-1));
return 1;
}
// Open the file
f = pakfire_file_open(file);
if (!f) {
- CTX_ERROR(file->ctx, "Could not open %s: %m\n", pakfire_file_get_path(file));
+ ERROR(file->ctx, "Could not open %s: %m\n", pakfire_file_get_path(file));
return 1;
}
if (!*path)
break;
- CTX_DEBUG(file->ctx, "Trying to remove parent directory %s\n", path);
+ DEBUG(file->ctx, "Trying to remove parent directory %s\n", path);
r = rmdir(path);
if (type != (st->st_mode & S_IFMT)) {
file->verify_status |= PAKFIRE_FILE_TYPE_CHANGED;
- CTX_DEBUG(file->ctx, "%s: File Type changed\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: File Type changed\n", pakfire_file_get_path(file));
}
const mode_t perms = pakfire_file_get_perms(file);
if (perms != (st->st_mode & 0777)) {
file->verify_status |= PAKFIRE_FILE_PERMISSIONS_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Permissions changed\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: Permissions changed\n", pakfire_file_get_path(file));
}
#if 0
if (dev != st->st_dev) {
file->verify_status |= PAKFIRE_FILE_DEV_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Device Node changed\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: Device Node changed\n", pakfire_file_get_path(file));
}
}
#endif
// Size differs
file->verify_status |= PAKFIRE_FILE_SIZE_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Filesize differs (expected %zd, got %zd byte(s))\n",
+ DEBUG(file->ctx, "%s: Filesize differs (expected %zd, got %zd byte(s))\n",
pakfire_file_get_path(file), size, st->st_size);
return 0;
if (!owner || owner->pw_uid != uid) {
file->verify_status |= PAKFIRE_FILE_OWNER_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Owner differs\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: Owner differs\n", pakfire_file_get_path(file));
}
// Check if group matches
if (!group || group->gr_gid != gid) {
file->verify_status |= PAKFIRE_FILE_GROUP_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Group differs\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: Group differs\n", pakfire_file_get_path(file));
}
return 0;
if (ctime != st->st_ctime) {
file->verify_status |= PAKFIRE_FILE_CTIME_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Creation time changed\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: Creation time changed\n", pakfire_file_get_path(file));
}
// Check modification time
if (mtime != st->st_mtime) {
file->verify_status |= PAKFIRE_FILE_MTIME_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Modification time changed\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: Modification time changed\n", pakfire_file_get_path(file));
}
return 0;
digest_types = pakfire_digest_has_any(&file->digests);
if (!digest_types) {
- CTX_ERROR(file->ctx, "%s: No digests available\n", pakfire_file_get_path(file));
+ ERROR(file->ctx, "%s: No digests available\n", pakfire_file_get_path(file));
return 0;
}
if (r) {
file->verify_status |= PAKFIRE_FILE_PAYLOAD_CHANGED;
- CTX_DEBUG(file->ctx, "%s: Digest(s) do not match\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s: Digest(s) do not match\n", pakfire_file_get_path(file));
}
ERROR:
struct stat st;
int r;
- CTX_DEBUG(file->ctx, "Verifying %s...\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "Verifying %s...\n", pakfire_file_get_path(file));
const char* abspath = pakfire_file_get_abspath(file);
// Open the file
f = pakfire_file_open(file);
if (!f) {
- CTX_ERROR(file->ctx, "Could not open %s: %m\n", pakfire_file_get_abspath(file));
+ ERROR(file->ctx, "Could not open %s: %m\n", pakfire_file_get_abspath(file));
return 1;
}
// Parse the ELF header
elf = elf_begin(fileno(f), ELF_C_READ, NULL);
if (!elf) {
- CTX_ERROR(file->ctx, "Could not open ELF file: %s\n", elf_errmsg(-1));
+ ERROR(file->ctx, "Could not open ELF file: %s\n", elf_errmsg(-1));
r = 1;
goto ERROR;
}
break;
default:
- CTX_ERROR(file->ctx, "%s is not an ELF object\n", pakfire_file_get_path(file));
+ ERROR(file->ctx, "%s is not an ELF object\n", pakfire_file_get_path(file));
r = 1;
goto ERROR;
}
// Fetch the ELF header
if (!gelf_getehdr(elf, &ehdr)) {
- CTX_ERROR(file->ctx, "Could not parse ELF header: %s\n", elf_errmsg(-1));
+ ERROR(file->ctx, "Could not parse ELF header: %s\n", elf_errmsg(-1));
return 1;
}
// Find the dynamic linking information
r = pakfire_file_get_elf_section(file, elf, SHT_DYNAMIC, &dynamic, &shdr, &elf_data);
if (r) {
- CTX_DEBUG(file->ctx, "%s does not have a dynamic section\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s does not have a dynamic section\n", pakfire_file_get_path(file));
return 0;
}
// Not found
if (r) {
- CTX_DEBUG(file->ctx, "%s has no debug sections\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s has no debug sections\n", pakfire_file_get_path(file));
// Store the result
file->issues |= PAKFIRE_FILE_MISSING_DEBUGINFO;
// Fetch the symbol table
r = pakfire_file_get_elf_section(file, elf, SHT_SYMTAB, &symtab, &shdr, &elf_data);
if (r) {
- CTX_ERROR(file->ctx, "%s has no symbol table\n", pakfire_file_get_path(file));
+ ERROR(file->ctx, "%s has no symbol table\n", pakfire_file_get_path(file));
return 1;
}
// We do not perform the check for libraries that do not contain any functions.
// Some packages use shared libraries to provide data.
if (!counter) {
- CTX_DEBUG(file->ctx, "%s: File has no functions. Skipping SSP check.\n",
+ DEBUG(file->ctx, "%s: File has no functions. Skipping SSP check.\n",
pakfire_file_get_path(file));
return 0;
}
// Check if this file is whitelisted
for (const char** path = whitelist; *path; path++) {
if (pakfire_file_matches(file, *path)) {
- CTX_DEBUG(file->ctx, "Skipping SSP check for whitelisted file %s\n",
+ DEBUG(file->ctx, "Skipping SSP check for whitelisted file %s\n",
pakfire_file_get_path(file));
return 0;
}
// Fetch the total numbers of program headers
r = elf_getphdrnum(elf, &phnum);
if (r) {
- CTX_ERROR(file->ctx, "Could not fetch number of program headers: %s\n",
+ ERROR(file->ctx, "Could not fetch number of program headers: %s\n",
elf_errmsg(-1));
return 1;
}
// Walk through all program headers
for (unsigned int i = 0; i < phnum; i++) {
if (!gelf_getphdr(elf, i, &phdr)) {
- CTX_ERROR(file->ctx, "Could not parse program header: %s\n", elf_errmsg(-1));
+ ERROR(file->ctx, "Could not parse program header: %s\n", elf_errmsg(-1));
return 1;
}
switch (phdr.p_type) {
case PT_GNU_STACK:
- CTX_DEBUG(file->ctx,
+ DEBUG(file->ctx,
"%s: GNU_STACK flags: %c%c%c\n",
pakfire_file_get_path(file),
(phdr.p_flags & PF_R) ? 'R' : '-',
if (!value)
return 1;
- CTX_DEBUG(file->ctx, "%s has a RUNPATH: %s\n",
+ DEBUG(file->ctx, "%s has a RUNPATH: %s\n",
pakfire_file_get_path(file), value);
// Copy the value into a buffer we can modify
// Iterate over all elements
while (runpath) {
- CTX_ERROR(file->ctx, "Checking RUNPATH %s\n", runpath);
+ ERROR(file->ctx, "Checking RUNPATH %s\n", runpath);
// We do not allow any relative RUNPATHs
if (pakfire_path_match(runpath, "**/../**"))
// Handle any reading errors
if (bytes_read < 0) {
- CTX_ERROR(file->ctx, "Could not read from file %s: %m\n",
+ ERROR(file->ctx, "Could not read from file %s: %m\n",
pakfire_file_get_path(file));
r = 1;
goto ERROR;
}
if (strncmp("#!", shebang, 2) == 0) {
- CTX_DEBUG(file->ctx, "%s is a script\n", pakfire_file_get_path(file));
+ DEBUG(file->ctx, "%s is a script\n", pakfire_file_get_path(file));
// Find the end of the first line (to be able to perform string operations)
p = memchr(shebang, '\n', sizeof(shebang));
if (!p) {
- CTX_ERROR(file->ctx, "%s: First line seems to be too long\n",
+ ERROR(file->ctx, "%s: First line seems to be too long\n",
pakfire_file_get_path(file));
errno = ENOBUFS;
r = 1;
const char* path = pakfire_file_get_path(file);
- CTX_DEBUG(file->ctx, "%s: Fixing interpreter %s\n", path, interpreter);
+ DEBUG(file->ctx, "%s: Fixing interpreter %s\n", path, interpreter);
// Open the file
f = pakfire_file_open(file);
if (!f) {
- CTX_ERROR(file->ctx, "Could not open %s: %m\n", path);
+ ERROR(file->ctx, "Could not open %s: %m\n", path);
r = -errno;
goto ERROR;
}
if (feof(f))
break;
- CTX_ERROR(file->ctx, "Could not read line from %s: %m\n", path);
+ ERROR(file->ctx, "Could not read line from %s: %m\n", path);
goto ERROR;
}
if (*p)
args = p;
- CTX_DEBUG(file->ctx, "%s: Found command %s (%s)\n", path, interpreter, args);
+ DEBUG(file->ctx, "%s: Found command %s (%s)\n", path, interpreter, args);
// Find the real path
r = pakfire_which(file->pakfire, command, interpreter);
if (r) {
- CTX_ERROR(file->ctx, "%s: Could not resolve %s: %m\n", path, interpreter);
+ ERROR(file->ctx, "%s: Could not resolve %s: %m\n", path, interpreter);
goto ERROR;
}
// If we could not resolve the command, this file has an invalid interpreter
if (!*command) {
- CTX_ERROR(file->ctx, "%s: Could not find path for command %s\n", path, interpreter);
+ ERROR(file->ctx, "%s: Could not find path for command %s\n", path, interpreter);
file->issues |= PAKFIRE_FILE_INVALID_INTERPRETER;
r = 0;
// Truncate the existing content
r = ftruncate(fileno(f), 0);
if (r) {
- CTX_ERROR(file->ctx, "Could not truncate %s: %m\n", path);
+ ERROR(file->ctx, "Could not truncate %s: %m\n", path);
r = -errno;
goto ERROR;
}
if (buffer) {
size_t bytes_written = fwrite(buffer, 1, l, f);
if (bytes_written < l) {
- CTX_ERROR(file->ctx, "%s: Could not write the payload: %m\n", path);
+ ERROR(file->ctx, "%s: Could not write the payload: %m\n", path);
r = -errno;
goto ERROR;
}
if (!interpreter)
return 0;
- CTX_DEBUG(file->ctx, "%s: Interpreter: %s\n",
+ DEBUG(file->ctx, "%s: Interpreter: %s\n",
pakfire_file_get_path(file), interpreter);
// Paths must be absolute
else if (strcmp(interpreter, "/usr/bin/env") == 0) {
r = pakfire_file_fix_interpreter(file, interpreter);
if (r) {
- CTX_ERROR(file->ctx, "%s: Could not fix interpreter: %m\n",
+ ERROR(file->ctx, "%s: Could not fix interpreter: %m\n",
pakfire_file_get_path(file));
goto ERROR;
}
// Check for IBT
if (!(property & GNU_PROPERTY_X86_FEATURE_1_IBT)) {
- CTX_DEBUG(file->ctx, "%s: IBT property is not enabled\n",
+ DEBUG(file->ctx, "%s: IBT property is not enabled\n",
pakfire_file_get_path(file));
// XXX TODO Actually modify any flags
// Check for Shadow Stack
if (!(property & GNU_PROPERTY_X86_FEATURE_1_SHSTK)) {
- CTX_DEBUG(file->ctx, "%s: Shadow Stack is not enabled\n",
+ DEBUG(file->ctx, "%s: Shadow Stack is not enabled\n",
pakfire_file_get_path(file));
// XXX TODO Actually modify any flags
// Fetch the ELF header
if (!gelf_getehdr(elf, &ehdr)) {
- CTX_ERROR(file->ctx, "Could not fetch the ELF header for %s: %m\n",
+ ERROR(file->ctx, "Could not fetch the ELF header for %s: %m\n",
pakfire_file_get_path(file));
return 1;
}
// Fetch the .note header
offset = gelf_getnote(data, offset, &nhdr, &offset_name, &offset_data);
if (!offset) {
- CTX_ERROR(file->ctx, "Could not read note section: %m\n");
+ ERROR(file->ctx, "Could not read note section: %m\n");
return 1;
}
payload += sizeof(type) + sizeof(size);
if (length < size) {
- CTX_ERROR(file->ctx, "GNU Property note has an incorrect format\n");
+ ERROR(file->ctx, "GNU Property note has an incorrect format\n");
return 1;
}
break;
default:
- CTX_ERROR(file->ctx, "Unsupported ELF type (%d)\n", ehdr.e_machine);
+ ERROR(file->ctx, "Unsupported ELF type (%d)\n", ehdr.e_machine);
return 1;
}
// Allocate a new element
element = calloc(1, sizeof *element);
if (!element) {
- CTX_ERROR(list->ctx, "Could not allocate a new filelist element: %m\n");
+ ERROR(list->ctx, "Could not allocate a new filelist element: %m\n");
return 1;
}
return 1;
}
- CTX_DEBUG(list->ctx, "Scanning %s...\n", root);
+ DEBUG(list->ctx, "Scanning %s...\n", root);
if (includes) {
- CTX_DEBUG(list->ctx, " Includes:\n");
+ DEBUG(list->ctx, " Includes:\n");
for (const char** include = includes; *include; include++)
- CTX_DEBUG(list->ctx, " %s\n", *include);
+ DEBUG(list->ctx, " %s\n", *include);
}
if (excludes) {
- CTX_DEBUG(list->ctx, " Excludes:\n");
+ DEBUG(list->ctx, " Excludes:\n");
for (const char** exclude = excludes; *exclude; exclude++)
- CTX_DEBUG(list->ctx, " %s\n", *exclude);
+ DEBUG(list->ctx, " %s\n", *exclude);
}
// Check if the path exists
if (!pakfire_path_exists(root)) {
- CTX_DEBUG(list->ctx, "Path to scan (%s) does not exist\n", root);
+ DEBUG(list->ctx, "Path to scan (%s) does not exist\n", root);
r = 0;
goto ERROR;
}
// Start reading from here
r = archive_read_disk_open(reader, root);
if (r) {
- CTX_ERROR(list->ctx, "Could not open %s: %s\n",
+ ERROR(list->ctx, "Could not open %s: %s\n",
root, archive_error_string(reader));
goto ERROR;
}
r = archive_read_disk_set_metadata_filter_callback(reader,
pakfire_filelist_scan_filter, &matches);
if (r) {
- CTX_ERROR(list->ctx, "Could not set filter callback: %s\n",
+ ERROR(list->ctx, "Could not set filter callback: %s\n",
archive_error_string(reader));
goto ERROR;
}
// Raise any other errors
default:
- CTX_ERROR(list->ctx, "Could not read next file: %s\n",
+ ERROR(list->ctx, "Could not read next file: %s\n",
archive_error_string(reader));
goto ERROR;
}
char* s = pakfire_file_dump(file, *flags);
if (s) {
- CTX_INFO(ctx, "%s\n", s);
+ INFO(ctx, "%s\n", s);
free(s);
}
const size_t length = pakfire_filelist_length(list);
- CTX_DEBUG(list->ctx, "Verifying filelist (%zu file(s))...\n", length);
+ DEBUG(list->ctx, "Verifying filelist (%zu file(s))...\n", length);
// Setup progress
r = pakfire_progress_create(&progress, list->ctx,
break;
default:
- CTX_ERROR(client->ctx, "Received unhandled cURL message %u\n", msg->msg);
+ ERROR(client->ctx, "Received unhandled cURL message %u\n", msg->msg);
break;
}
}
struct pakfire_httpclient* client = data;
int r;
- CTX_DEBUG(client->ctx, "cURL timer fired\n");
+ DEBUG(client->ctx, "cURL timer fired\n");
r = curl_multi_socket_action(client->curl, CURL_SOCKET_TIMEOUT, 0, &client->still_running);
if (r)
if (client->timer) {
r = sd_event_source_set_enabled(client->timer, SD_EVENT_OFF);
if (r < 0)
- CTX_ERROR(client->ctx, "Could not disarm the timer: %s\n", strerror(-r));
+ ERROR(client->ctx, "Could not disarm the timer: %s\n", strerror(-r));
}
return 0;
// Set the timer
r = sd_event_source_set_time_relative(client->timer, timeout_ms * 1000);
if (r < 0) {
- CTX_ERROR(client->ctx, "Could not set timer: %s\n", strerror(-r));
+ ERROR(client->ctx, "Could not set timer: %s\n", strerror(-r));
return r;
}
// Have the timer fire once
r = sd_event_source_set_enabled(client->timer, SD_EVENT_ONESHOT);
if (r < 0) {
- CTX_ERROR(client->ctx, "Could not enable the timer: %s\n", strerror(-r));
+ ERROR(client->ctx, "Could not enable the timer: %s\n", strerror(-r));
return r;
}
- CTX_DEBUG(client->ctx, "cURL set a timer for %ldms\n", timeout_ms);
+ DEBUG(client->ctx, "cURL set a timer for %ldms\n", timeout_ms);
return 0;
}
if (events & EPOLLOUT)
action |= CURL_CSELECT_OUT;
- //CTX_DEBUG(client->ctx, "cURL has activity on socket %d\n", fd);
+ //DEBUG(client->ctx, "cURL has activity on socket %d\n", fd);
// Inform cURL about some socket activity
r = curl_multi_socket_action(client->curl, fd, action, &client->still_running);
if (client->timer) {
r = sd_event_source_set_enabled(client->timer, SD_EVENT_OFF);
if (r < 0) {
- CTX_ERROR(client->ctx, "Could not disarm the timer: %s\n", strerror(-r));
+ ERROR(client->ctx, "Could not disarm the timer: %s\n", strerror(-r));
return r;
}
// Disable the event
r = sd_event_source_set_enabled(s, SD_EVENT_OFF);
if (r < 0)
- CTX_ERROR(client->ctx, "Could not disable fd %d: %s\n", fd, strerror(-r));
+ ERROR(client->ctx, "Could not disable fd %d: %s\n", fd, strerror(-r));
- CTX_DEBUG(client->ctx, "cURL deregistered socket %d\n", fd);
+ DEBUG(client->ctx, "cURL deregistered socket %d\n", fd);
return r;
}
if (s) {
r = sd_event_source_set_io_events(s, events);
if (r < 0) {
- CTX_ERROR(client->ctx, "Could not change events for socket %d: %s\n",
+ ERROR(client->ctx, "Could not change events for socket %d: %s\n",
fd, strerror(-r));
return r;
}
- CTX_DEBUG(client->ctx, "cURL changed socket %d\n", fd);
+ DEBUG(client->ctx, "cURL changed socket %d\n", fd);
return 0;
}
// Add the socket to the event loop
r = sd_event_add_io(client->loop, &s, fd, events, __pakfire_httpclient_socket, client);
if (r < 0) {
- CTX_ERROR(client->ctx, "Could not register socket %d: %s\n", fd, strerror(-r));
+ ERROR(client->ctx, "Could not register socket %d: %s\n", fd, strerror(-r));
goto ERROR;
}
// Store the event source
curl_multi_assign(client->curl, fd, sd_event_source_ref(s));
- CTX_DEBUG(client->ctx, "cURL registered socket %d\n", fd);
+ DEBUG(client->ctx, "cURL registered socket %d\n", fd);
ERROR:
if (s)
} else {
r = sd_event_new(&client->loop);
if (r < 0) {
- CTX_ERROR(client->ctx, "Could not setup event loop: %s\n", strerror(-r));
+ ERROR(client->ctx, "Could not setup event loop: %s\n", strerror(-r));
return r;
}
r = sd_event_add_time_relative(client->loop, &client->timer, CLOCK_MONOTONIC, 0, 0,
__pakfire_httpclient_timer, client);
if (r < 0) {
- CTX_ERROR(client->ctx, "Could not set timer: %s\n", strerror(-r));
+ ERROR(client->ctx, "Could not set timer: %s\n", strerror(-r));
return r;
}
// Initialize cURL
r = curl_global_init(CURL_GLOBAL_DEFAULT);
if (r) {
- CTX_ERROR(client->ctx, "Could not initialize cURL: %d\n", r);
+ ERROR(client->ctx, "Could not initialize cURL: %d\n", r);
return r;
}
// Create a new multi handle
client->curl = curl_multi_init();
if (!client->curl) {
- CTX_ERROR(client->ctx, "Could not create cURL multi handle\n");
+ ERROR(client->ctx, "Could not create cURL multi handle\n");
return 1;
}
// Register with the event loop
r = curl_multi_setopt(client->curl, CURLMOPT_TIMERFUNCTION, pakfire_httpclient_timer);
if (r) {
- CTX_ERROR(client->ctx, "Could not register the timer function: %s\n",
+ ERROR(client->ctx, "Could not register the timer function: %s\n",
curl_multi_strerror(r));
return r;
r = curl_multi_setopt(client->curl, CURLMOPT_TIMERDATA, client);
if (r) {
- CTX_ERROR(client->ctx, "Could not register the timer data: %s\n",
+ ERROR(client->ctx, "Could not register the timer data: %s\n",
curl_multi_strerror(r));
return r;
r = curl_multi_setopt(client->curl, CURLMOPT_SOCKETFUNCTION, pakfire_httpclient_socket);
if (r) {
- CTX_ERROR(client->ctx, "Could not register the socket function: %s\n",
+ ERROR(client->ctx, "Could not register the socket function: %s\n",
curl_multi_strerror(r));
return r;
r = curl_multi_setopt(client->curl, CURLMOPT_SOCKETDATA, client);
if (r) {
- CTX_ERROR(client->ctx, "Could not register the socket data: %s\n",
+ ERROR(client->ctx, "Could not register the socket data: %s\n",
curl_multi_strerror(r));
return r;
// Limit parallel transfers
r = curl_multi_setopt(client->curl, CURLMOPT_MAXCONNECTS, client->max_parallel);
if (r) {
- CTX_ERROR(client->ctx, "Could not set max parallel transfers: %s\n",
+ ERROR(client->ctx, "Could not set max parallel transfers: %s\n",
curl_multi_strerror(r));
return r;
// Add the handle to cURL
r = curl_multi_add_handle(client->curl, pakfire_xfer_handle(xfer));
if (r) {
- CTX_ERROR(client->ctx, "Adding handle failed: %s\n", curl_multi_strerror(r));
+ ERROR(client->ctx, "Adding handle failed: %s\n", curl_multi_strerror(r));
goto ERROR;
}
// Remove the handle
r = curl_multi_remove_handle(client->curl, pakfire_xfer_handle(xfer));
if (r) {
- CTX_ERROR(client->ctx, "Could not remove the handle: %s\n", curl_multi_strerror(r));
+ ERROR(client->ctx, "Could not remove the handle: %s\n", curl_multi_strerror(r));
goto ERROR;
}
// Cannot run without any transfers
if (!client->total_xfers) {
- CTX_DEBUG(client->ctx, "Skipping running HTTP client without any transfers\n");
+ DEBUG(client->ctx, "Skipping running HTTP client without any transfers\n");
return 0;
}
// Run the event loop
r = sd_event_loop(client->loop);
if (r < 0) {
- CTX_ERROR(client->ctx, "Event loop failed: %s\n", strerror(-r));
+ ERROR(client->ctx, "Event loop failed: %s\n", strerror(-r));
goto ERROR;
}
static inline void __attribute__((always_inline, format(printf, 2, 3)))
pakfire_ctx_log_null(struct pakfire_ctx* ctx, const char *format, ...) {}
-#define CTX_INFO(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_INFO, ## arg)
-#define CTX_ERROR(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_ERR, ## arg)
+#define INFO(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_INFO, ## arg)
+#define ERROR(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_ERR, ## arg)
#ifdef ENABLE_DEBUG
-# define CTX_DEBUG(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_DEBUG, ## arg)
+# define DEBUG(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_DEBUG, ## arg)
#else
-# define CTX_DEBUG pakfire_ctx_log_null
+# define DEBUG pakfire_ctx_log_null
#endif
#endif /* PAKFIRE_PRIVATE */
}
static void pakfire_jail_free(struct pakfire_jail* jail) {
- CTX_DEBUG(jail->ctx, "Freeing jail at %p\n", jail);
+ DEBUG(jail->ctx, "Freeing jail at %p\n", jail);
// Free environment
for (unsigned int i = 0; jail->env[i]; i++)
// Generate a random UUID
uuid_generate_random(j->uuid);
- CTX_DEBUG(j->ctx, "Allocated new jail at %p\n", j);
+ DEBUG(j->ctx, "Allocated new jail at %p\n", j);
// Set default environment
for (const struct environ* e = ENV; e->key; e++) {
// Set any new cgroup
if (cgroup) {
- CTX_DEBUG(jail->ctx, "Setting cgroup %p\n", cgroup);
+ DEBUG(jail->ctx, "Setting cgroup %p\n", cgroup);
jail->cgroup = pakfire_cgroup_ref(cgroup);
}
// Format and set environment variable
asprintf(&jail->env[i], "%s=%s", key, value);
- CTX_DEBUG(jail->ctx, "Set environment variable: %s\n", jail->env[i]);
+ DEBUG(jail->ctx, "Set environment variable: %s\n", jail->env[i]);
return 0;
}
jail->timeout = timeout;
if (timeout > 0)
- CTX_DEBUG(jail->ctx, "Timeout set to %u second(s)\n", timeout);
+ DEBUG(jail->ctx, "Timeout set to %u second(s)\n", timeout);
else
- CTX_DEBUG(jail->ctx, "Timeout disabled\n");
+ DEBUG(jail->ctx, "Timeout disabled\n");
return 0;
}
static int pakfire_jail_INFO(struct pakfire_log_stream* stream, const char* line, size_t length, void* data) {
struct pakfire_jail* jail = data;
- CTX_INFO(jail->ctx, "%.*s", (int)length, line);
+ INFO(jail->ctx, "%.*s", (int)length, line);
return 0;
}
static int pakfire_jail_ERROR(struct pakfire_log_stream* stream, const char* line, size_t length, void* data) {
struct pakfire_jail* jail = data;
- CTX_ERROR(jail->ctx, "%.*s", (int)length, line);
+ ERROR(jail->ctx, "%.*s", (int)length, line);
return 0;
}
static int pakfire_jail_DEBUG(struct pakfire_log_stream* stream, const char* line, size_t length, void* data) {
struct pakfire_jail* jail = data;
- CTX_DEBUG(jail->ctx, "%.*s", (int)length, line);
+ DEBUG(jail->ctx, "%.*s", (int)length, line);
return 0;
}
#endif /* ENABLE_DEBUG */
// Fetch all capabilities
caps = cap_get_proc();
if (!caps) {
- CTX_ERROR(jail->ctx, "Could not fetch capabilities: %m\n");
+ ERROR(jail->ctx, "Could not fetch capabilities: %m\n");
r = 1;
goto ERROR;
}
- CTX_DEBUG(jail->ctx, "Capabilities of PID %d:\n", pid);
+ DEBUG(jail->ctx, "Capabilities of PID %d:\n", pid);
// Iterate over all capabilities
for (unsigned int cap = 0; cap_valid(cap); cap++) {
if (r)
goto ERROR;
- CTX_DEBUG(jail->ctx,
+ DEBUG(jail->ctx,
" %-24s : %c%c%c\n",
name,
(value_e == CAP_SET) ? 'e' : '-',
// Fetch capabilities
caps = cap_get_proc();
if (!caps) {
- CTX_ERROR(jail->ctx, "Could not read capabilities: %m\n");
+ ERROR(jail->ctx, "Could not read capabilities: %m\n");
r = 1;
goto ERROR;
}
r = cap_set_flag(caps, CAP_EFFECTIVE, 1, _caps, CAP_SET);
if (r) {
- CTX_ERROR(jail->ctx, "Could not set %s: %m\n", name);
+ ERROR(jail->ctx, "Could not set %s: %m\n", name);
goto ERROR;
}
r = cap_set_flag(caps, CAP_INHERITABLE, 1, _caps, CAP_SET);
if (r) {
- CTX_ERROR(jail->ctx, "Could not set %s: %m\n", name);
+ ERROR(jail->ctx, "Could not set %s: %m\n", name);
goto ERROR;
}
r = cap_set_flag(caps, CAP_PERMITTED, 1, _caps, CAP_SET);
if (r) {
- CTX_ERROR(jail->ctx, "Could not set %s: %m\n", name);
+ ERROR(jail->ctx, "Could not set %s: %m\n", name);
goto ERROR;
}
// Restore all capabilities
r = cap_set_proc(caps);
if (r) {
- CTX_ERROR(jail->ctx, "Restoring capabilities failed: %m\n");
+ ERROR(jail->ctx, "Restoring capabilities failed: %m\n");
goto ERROR;
}
// Raise the capability
r = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0);
if (r) {
- CTX_ERROR(jail->ctx, "Could not set ambient capability %s: %m\n", name);
+ ERROR(jail->ctx, "Could not set ambient capability %s: %m\n", name);
goto ERROR;
}
};
int r = 1;
- CTX_DEBUG(jail->ctx, "Applying syscall filter...\n");
+ DEBUG(jail->ctx, "Applying syscall filter...\n");
// Setup a syscall filter which allows everything by default
scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_ALLOW);
if (!ctx) {
- CTX_ERROR(jail->ctx, "Could not setup seccomp filter: %m\n");
+ ERROR(jail->ctx, "Could not setup seccomp filter: %m\n");
goto ERROR;
}
for (const int* syscall = syscalls; *syscall; syscall++) {
r = seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), *syscall, 0);
if (r) {
- CTX_ERROR(jail->ctx, "Could not configure syscall %d: %m\n", *syscall);
+ ERROR(jail->ctx, "Could not configure syscall %d: %m\n", *syscall);
goto ERROR;
}
}
// Load syscall filter into the kernel
r = seccomp_load(ctx);
if (r) {
- CTX_ERROR(jail->ctx, "Could not load syscall filter into the kernel: %m\n");
+ ERROR(jail->ctx, "Could not load syscall filter into the kernel: %m\n");
goto ERROR;
}
// Copy source
r = pakfire_string_set(mp->source, source);
if (r) {
- CTX_ERROR(jail->ctx, "Could not copy source: %m\n");
+ ERROR(jail->ctx, "Could not copy source: %m\n");
return r;
}
// Copy target
r = pakfire_string_set(mp->target, target);
if (r) {
- CTX_ERROR(jail->ctx, "Could not copy target: %m\n");
+ ERROR(jail->ctx, "Could not copy target: %m\n");
return r;
}
struct rtnl_link* change = NULL;
int r;
- CTX_DEBUG(jail->ctx, "Setting up loopback...\n");
+ DEBUG(jail->ctx, "Setting up loopback...\n");
// Allocate a netlink socket
nl = nl_socket_alloc();
if (!nl) {
- CTX_ERROR(jail->ctx, "Could not allocate a netlink socket: %m\n");
+ ERROR(jail->ctx, "Could not allocate a netlink socket: %m\n");
r = 1;
goto ERROR;
}
// Connect the socket
r = nl_connect(nl, NETLINK_ROUTE);
if (r) {
- CTX_ERROR(jail->ctx, "Could not connect netlink socket: %s\n", nl_geterror(r));
+ ERROR(jail->ctx, "Could not connect netlink socket: %s\n", nl_geterror(r));
goto ERROR;
}
// Allocate the netlink cache
r = rtnl_link_alloc_cache(nl, AF_UNSPEC, &cache);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Unable to allocate netlink cache: %s\n", nl_geterror(r));
+ ERROR(jail->ctx, "Unable to allocate netlink cache: %s\n", nl_geterror(r));
goto ERROR;
}
// Fetch loopback interface
link = rtnl_link_get_by_name(cache, "lo");
if (!link) {
- CTX_ERROR(jail->ctx, "Could not find lo interface. Ignoring.\n");
+ ERROR(jail->ctx, "Could not find lo interface. Ignoring.\n");
r = 0;
goto ERROR;
}
// Allocate a new link
change = rtnl_link_alloc();
if (!change) {
- CTX_ERROR(jail->ctx, "Could not allocate change link\n");
+ ERROR(jail->ctx, "Could not allocate change link\n");
r = 1;
goto ERROR;
}
// Apply any changes
r = rtnl_link_change(nl, link, change, 0);
if (r) {
- CTX_ERROR(jail->ctx, "Unable to activate loopback: %s\n", nl_geterror(r));
+ ERROR(jail->ctx, "Unable to activate loopback: %s\n", nl_geterror(r));
goto ERROR;
}
}
if (r) {
- CTX_ERROR(jail->ctx, "Could not map UIDs: %m\n");
+ ERROR(jail->ctx, "Could not map UIDs: %m\n");
return r;
}
}
if (r) {
- CTX_ERROR(jail->ctx, "Could not map GIDs: %m\n");
+ ERROR(jail->ctx, "Could not map GIDs: %m\n");
return r;
}
r = pakfire_file_write(jail->pakfire, path, 0, 0, 0, "deny\n");
if (r) {
- CTX_ERROR(jail->ctx, "Could not set setgroups to deny: %s\n", strerror(errno));
+ ERROR(jail->ctx, "Could not set setgroups to deny: %s\n", strerror(errno));
r = -errno;
}
const uint64_t val = 1;
int r = 0;
- CTX_DEBUG(jail->ctx, "Sending signal...\n");
+ DEBUG(jail->ctx, "Sending signal...\n");
// Write to the file descriptor
r = eventfd_write(fd, val);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not send signal: %s\n", strerror(errno));
+ ERROR(jail->ctx, "Could not send signal: %s\n", strerror(errno));
r = -errno;
}
uint64_t val = 0;
int r = 0;
- CTX_DEBUG(jail->ctx, "Waiting for signal...\n");
+ DEBUG(jail->ctx, "Waiting for signal...\n");
r = eventfd_read(fd, &val);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Error waiting for signal: %s\n", strerror(errno));
+ ERROR(jail->ctx, "Error waiting for signal: %s\n", strerror(errno));
r = -errno;
}
struct pakfire_jail* jail = ctx->jail;
int r;
- CTX_DEBUG(jail->ctx, "Timer has fired...\n");
+ DEBUG(jail->ctx, "Timer has fired...\n");
// Send SIGKILL to the process
r = pidfd_send_signal(ctx->pidfd, SIGKILL, NULL, 0);
if (r)
- CTX_ERROR(jail->ctx, "Could not send SIGKILL to the process: %m\n");
+ ERROR(jail->ctx, "Could not send SIGKILL to the process: %m\n");
return r;
}
switch (si->si_code) {
case CLD_EXITED:
- CTX_DEBUG(jail->ctx, "Process has exited with status code %d\n", si->si_status);
+ DEBUG(jail->ctx, "Process has exited with status code %d\n", si->si_status);
// Store the exit code
ctx->exit = si->si_status;
break;
case CLD_KILLED:
- CTX_ERROR(jail->ctx, "Process has been killed by signal %d\n", si->si_signo);
+ ERROR(jail->ctx, "Process has been killed by signal %d\n", si->si_signo);
// Store the exit code
ctx->exit = 139;
break;
case CLD_DUMPED:
- CTX_ERROR(jail->ctx, "The child process terminated abnormally\n");
+ ERROR(jail->ctx, "The child process terminated abnormally\n");
break;
}
// Register the PID file descriptor
r = sd_event_add_child_pidfd(ctx->loop, NULL, ctx->pidfd, WEXITED, pakfire_jail_exited, ctx);
if (r < 0) {
- CTX_DEBUG(jail->ctx, "Could not register the child process with the event loop: %s\n", strerror(-r));
+ DEBUG(jail->ctx, "Could not register the child process with the event loop: %s\n", strerror(-r));
return r;
}
return r;
// Parent has finished initialisation
- CTX_DEBUG(jail->ctx, "Parent has finished initialization\n");
+ DEBUG(jail->ctx, "Parent has finished initialization\n");
// Send signal to client
r = pakfire_jail_send_signal(jail, ctx->completed_fd);
// Change to the new root
r = chdir(root);
if (r) {
- CTX_ERROR(jail->ctx, "chdir(%s) failed: %m\n", root);
+ ERROR(jail->ctx, "chdir(%s) failed: %m\n", root);
return r;
}
// Switch Root!
r = pivot_root(".", ".");
if (r) {
- CTX_ERROR(jail->ctx, "Failed changing into the new root directory %s: %m\n", root);
+ ERROR(jail->ctx, "Failed changing into the new root directory %s: %m\n", root);
return r;
}
// Umount the old root
r = umount2(".", MNT_DETACH);
if (r) {
- CTX_ERROR(jail->ctx, "Could not umount the old root filesystem: %m\n");
+ ERROR(jail->ctx, "Could not umount the old root filesystem: %m\n");
return r;
}
// Fetch my own PID
pid_t pid = getpid();
- CTX_DEBUG(jail->ctx, "Launched child process in jail with PID %d\n", pid);
+ DEBUG(jail->ctx, "Launched child process in jail with PID %d\n", pid);
// Die with parent
r = prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
if (r) {
- CTX_ERROR(jail->ctx, "Could not configure to die with parent: %m\n");
+ ERROR(jail->ctx, "Could not configure to die with parent: %m\n");
return 126;
}
// Make this process dumpable
r = prctl (PR_SET_DUMPABLE, 1, 0, 0, 0);
if (r) {
- CTX_ERROR(jail->ctx, "Could not make the process dumpable: %m\n");
+ ERROR(jail->ctx, "Could not make the process dumpable: %m\n");
return 126;
}
// Don't drop any capabilities on setuid()
r = prctl(PR_SET_KEEPCAPS, 1);
if (r) {
- CTX_ERROR(jail->ctx, "Could not set PR_SET_KEEPCAPS: %m\n");
+ ERROR(jail->ctx, "Could not set PR_SET_KEEPCAPS: %m\n");
return 126;
}
uid_t euid = geteuid();
gid_t egid = getegid();
- CTX_DEBUG(jail->ctx, " UID: %u (effective %u)\n", uid, euid);
- CTX_DEBUG(jail->ctx, " GID: %u (effective %u)\n", gid, egid);
+ DEBUG(jail->ctx, " UID: %u (effective %u)\n", uid, euid);
+ DEBUG(jail->ctx, " GID: %u (effective %u)\n", gid, egid);
// Log all mountpoints
pakfire_mount_list(jail->ctx);
// Fail if we are not PID 1
if (pid != 1) {
- CTX_ERROR(jail->ctx, "Child process is not PID 1\n");
+ ERROR(jail->ctx, "Child process is not PID 1\n");
return 126;
}
// Fail if we are not running as root
if (uid || gid || euid || egid) {
- CTX_ERROR(jail->ctx, "Child process is not running as root\n");
+ ERROR(jail->ctx, "Child process is not running as root\n");
return 126;
}
if (persona) {
r = personality(persona);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not set personality (%x)\n", (unsigned int)persona);
+ ERROR(jail->ctx, "Could not set personality (%x)\n", (unsigned int)persona);
return 1;
}
}
// Set nice level
if (jail->nice) {
- CTX_DEBUG(jail->ctx, "Setting nice level to %d\n", jail->nice);
+ DEBUG(jail->ctx, "Setting nice level to %d\n", jail->nice);
r = setpriority(PRIO_PROCESS, pid, jail->nice);
if (r) {
- CTX_ERROR(jail->ctx, "Could not set nice level: %m\n");
+ ERROR(jail->ctx, "Could not set nice level: %m\n");
return 1;
}
}
// Create a new session
r = setsid();
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not create a new session: %s\n", strerror(errno));
+ ERROR(jail->ctx, "Could not create a new session: %s\n", strerror(errno));
return r;
}
// Open a new PTY
r = pakfire_pty_open(ctx->pty);
if (r) {
- CTX_ERROR(jail->ctx, "Could not open a new PTY: %s\n", strerror(-r));
+ ERROR(jail->ctx, "Could not open a new PTY: %s\n", strerror(-r));
return r;
}
if (r)
return r;
- CTX_DEBUG(jail->ctx, "Child process initialization done\n");
- CTX_DEBUG(jail->ctx, "Launching command:\n");
+ DEBUG(jail->ctx, "Child process initialization done\n");
+ DEBUG(jail->ctx, "Launching command:\n");
// Log argv
for (unsigned int i = 0; argv[i]; i++)
- CTX_DEBUG(jail->ctx, " argv[%u] = %s\n", i, argv[i]);
+ DEBUG(jail->ctx, " argv[%u] = %s\n", i, argv[i]);
// exec() command
r = execvpe(argv[0], (char**)argv, jail->env);
r = 1;
}
- CTX_ERROR(jail->ctx, "Could not execve(%s): %m\n", argv[0]);
+ ERROR(jail->ctx, "Could not execve(%s): %m\n", argv[0]);
}
// We should not get here
.exit = -1,
};
- CTX_DEBUG(jail->ctx, "Executing jail...\n");
+ DEBUG(jail->ctx, "Executing jail...\n");
// Create a new event loop
r = sd_event_new(&ctx.loop);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not create a new event loop: %s\n", strerror(-r));
+ ERROR(jail->ctx, "Could not create a new event loop: %s\n", strerror(-r));
goto ERROR;
}
r = sd_event_add_signal(ctx.loop, NULL, SIGCHLD|SD_EVENT_SIGNAL_PROCMASK,
pakfire_jail_SIGCHLD, NULL);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not register handling SIGCHLD: %s\n", strerror(-r));
+ ERROR(jail->ctx, "Could not register handling SIGCHLD: %s\n", strerror(-r));
goto ERROR;
}
// We cannot capture the output in interactive mode
if (output) {
- CTX_ERROR(jail->ctx, "Cannot capture output in interactive mode\n");
+ ERROR(jail->ctx, "Cannot capture output in interactive mode\n");
r = -ENOTSUP;
goto ERROR;
}
*/
ctx.completed_fd = eventfd(0, EFD_CLOEXEC);
if (ctx.completed_fd < 0) {
- CTX_ERROR(jail->ctx, "eventfd() failed: %m\n");
+ ERROR(jail->ctx, "eventfd() failed: %m\n");
return -1;
}
r = sd_event_add_time_relative(ctx.loop, &ctx.timeout, CLOCK_MONOTONIC,
jail->timeout * 1000000, 0, pakfire_jail_timer, &ctx);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not setup timer: %s\n", strerror(-r));
+ ERROR(jail->ctx, "Could not setup timer: %s\n", strerror(-r));
goto ERROR;
}
}
// Create a temporary cgroup
r = pakfire_cgroup_child(&ctx.cgroup, jail->cgroup, uuid, 0);
if (r) {
- CTX_ERROR(jail->ctx, "Could not create cgroup for jail: %m\n");
+ ERROR(jail->ctx, "Could not create cgroup for jail: %m\n");
goto ERROR;
}
// Fork this process
ctx.pid = clone3(&args, sizeof(args));
if (ctx.pid < 0) {
- CTX_ERROR(jail->ctx, "Could not clone: %m\n");
+ ERROR(jail->ctx, "Could not clone: %m\n");
return -1;
// Child process
if (r)
goto ERROR;
- CTX_DEBUG(jail->ctx, "Entering main loop...\n");
+ DEBUG(jail->ctx, "Entering main loop...\n");
// Main Loop
r = sd_event_loop(ctx.loop);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not run the event loop: %s\n", strerror(-r));
+ ERROR(jail->ctx, "Could not run the event loop: %s\n", strerror(-r));
goto ERROR;
}
// Create a temporary file
f = pakfire_mktemp(path, 0700);
if (!f) {
- CTX_ERROR(jail->ctx, "Could not create temporary file: %m\n");
+ ERROR(jail->ctx, "Could not create temporary file: %m\n");
goto ERROR;
}
- CTX_DEBUG(jail->ctx, "Writing script to %s:\n%.*s\n", path, (int)size, script);
+ DEBUG(jail->ctx, "Writing script to %s:\n%.*s\n", path, (int)size, script);
// Write data
r = fprintf(f, "%s", script);
if (r < 0) {
- CTX_ERROR(jail->ctx, "Could not write script to file %s: %m\n", path);
+ ERROR(jail->ctx, "Could not write script to file %s: %m\n", path);
goto ERROR;
}
// Close file
r = fclose(f);
if (r) {
- CTX_ERROR(jail->ctx, "Could not close script file %s: %m\n", path);
+ ERROR(jail->ctx, "Could not close script file %s: %m\n", path);
goto ERROR;
}
argv = calloc(argc + 1, sizeof(*argv));
if (!argv) {
- CTX_ERROR(jail->ctx, "Could not allocate argv: %m\n");
+ ERROR(jail->ctx, "Could not allocate argv: %m\n");
goto ERROR;
}
// Check if the file is executable
r = access(path, X_OK);
if (r) {
- CTX_DEBUG(ctx, "%s is not executable. Skipping...\n", *argv);
+ DEBUG(ctx, "%s is not executable. Skipping...\n", *argv);
goto ERROR;
}
// Fetch the Job ID
if (!json_object_object_get_ex(data, "id", &o)) {
- CTX_ERROR(job->ctx, "Job does not have an ID\n");
+ ERROR(job->ctx, "Job does not have an ID\n");
return -EINVAL;
}
// Parse the Job ID
r = uuid_parse(s, job->job_id);
if (r) {
- CTX_ERROR(job->ctx, "Could not parse the Job ID (%s)\n", s);
+ ERROR(job->ctx, "Could not parse the Job ID (%s)\n", s);
return -EINVAL;
}
// Fetch the name
if (!json_object_object_get_ex(data, "name", &o)) {
- CTX_ERROR(job->ctx, "Job does not have a name\n");
+ ERROR(job->ctx, "Job does not have a name\n");
return -EINVAL;
}
// Store the name
r = pakfire_string_set(job->name, json_object_get_string(o));
if (r) {
- CTX_ERROR(job->ctx, "Could not store name: %m\n");
+ ERROR(job->ctx, "Could not store name: %m\n");
return r;
}
// Fetch the arch
if (!json_object_object_get_ex(data, "arch", &o)) {
- CTX_ERROR(job->ctx, "Job does not have an architecture\n");
+ ERROR(job->ctx, "Job does not have an architecture\n");
return -EINVAL;
}
// Store the arch
r = pakfire_string_set(job->arch, json_object_get_string(o));
if (r) {
- CTX_ERROR(job->ctx, "Could not store arch: %m\n");
+ ERROR(job->ctx, "Could not store arch: %m\n");
return r;
}
if (json_object_object_get_ex(ccache, "path", &o)) {
r = pakfire_string_set(job->ccache_path, json_object_get_string(o));
if (r) {
- CTX_ERROR(job->ctx, "Could not store the ccache path: %m\n");
+ ERROR(job->ctx, "Could not store the ccache path: %m\n");
return r;
}
// Fetch the configuration
if (!json_object_object_get_ex(data, "conf", &o)) {
- CTX_ERROR(job->ctx, "Job does not have a configuration\n");
+ ERROR(job->ctx, "Job does not have a configuration\n");
return -EINVAL;
}
// Store the configuration
r = pakfire_string_set(job->conf, json_object_get_string(o));
if (r) {
- CTX_ERROR(job->ctx, "Could not store the configuration: %m\n");
+ ERROR(job->ctx, "Could not store the configuration: %m\n");
return r;
}
// Fetch the package URL
if (!json_object_object_get_ex(data, "pkg", &o)) {
- CTX_ERROR(job->ctx, "Job does not have a package URL\n");
+ ERROR(job->ctx, "Job does not have a package URL\n");
return -EINVAL;
}
// Store the package URL
r = pakfire_string_set(job->pkg, json_object_get_string(o));
if (r) {
- CTX_ERROR(job->ctx, "Could not store the package URL: %m\n");
+ ERROR(job->ctx, "Could not store the package URL: %m\n");
return r;
}
- CTX_DEBUG(job->ctx, "Job parsing completed\n");
+ DEBUG(job->ctx, "Job parsing completed\n");
// Format the Job ID as string
uuid_unparse_lower(job->job_id, job_id);
- CTX_INFO(job->ctx, "Received a new job:\n");
- CTX_INFO(job->ctx, " ID : %s\n", job_id);
- CTX_INFO(job->ctx, " Name : %s\n", job->name);
- CTX_INFO(job->ctx, " Arch : %s\n", job->arch);
+ INFO(job->ctx, "Received a new job:\n");
+ INFO(job->ctx, " ID : %s\n", job_id);
+ INFO(job->ctx, " Name : %s\n", job->name);
+ INFO(job->ctx, " Arch : %s\n", job->arch);
return 0;
}
switch (si->si_code) {
case CLD_EXITED:
- CTX_DEBUG(job->ctx, "Job %s has exited with status code %d\n",
+ DEBUG(job->ctx, "Job %s has exited with status code %d\n",
job_id, si->si_status);
// Update state
break;
case CLD_KILLED:
- CTX_ERROR(job->ctx, "Job %s has been killed by signal %d\n",
+ ERROR(job->ctx, "Job %s has been killed by signal %d\n",
job_id, si->si_signo);
// Update state
// Bail if we don't have a control connection
if (!job->control) {
- CTX_DEBUG(job->ctx, "Cannot send log message because the control connection is down\n");
+ DEBUG(job->ctx, "Cannot send log message because the control connection is down\n");
return 0;
}
// Create a new JSON object
data = json_object_new_object();
if (!data) {
- CTX_ERROR(job->ctx, "Could not create a new JSON object: %m\n");
+ ERROR(job->ctx, "Could not create a new JSON object: %m\n");
r = -errno;
goto ERROR;
}
// Send the message
r = pakfire_xfer_send_message(job->control, m, length);
if (r) {
- CTX_ERROR(job->ctx, "Could not send log message: %s\n", strerror(-r));
+ ERROR(job->ctx, "Could not send log message: %s\n", strerror(-r));
goto ERROR;
}
// Register the PID file descriptor
r = sd_event_add_child_pidfd(job->loop, NULL, job->pidfd, WEXITED, pakfire_job_exited, job);
if (r < 0) {
- CTX_DEBUG(job->ctx, "Could not register the job with the event loop: %s\n", strerror(-r));
+ DEBUG(job->ctx, "Could not register the job with the event loop: %s\n", strerror(-r));
return r;
}
// Fetch our PID
pid_t pid = getpid();
- CTX_DEBUG(job->ctx, "Launched job child as PID %d\n", pid);
+ DEBUG(job->ctx, "Launched job child as PID %d\n", pid);
// Format the job ID as string
uuid_unparse(job->job_id, job_id);
// Replace the context with a new one
r = pakfire_ctx_create(&ctx, NULL);
if (r < 0) {
- CTX_ERROR(ctx, "Could not create a new context: %s\n", strerror(-r));
+ ERROR(ctx, "Could not create a new context: %s\n", strerror(-r));
goto ERROR;
}
// Map the configuration
conf = fmemopen(job->conf, strlen(job->conf), "r");
if (!conf) {
- CTX_ERROR(ctx, "Could not map the configuration into memory: %m\n");
+ ERROR(ctx, "Could not map the configuration into memory: %m\n");
r = -errno;
goto ERROR;
}
// Create a new Pakfire instance
r = pakfire_create(&pakfire, ctx, NULL, job->arch, conf, PAKFIRE_FLAGS_BUILD);
if (r) {
- CTX_ERROR(ctx, "Could not initialize Pakfire: %m\n");
+ ERROR(ctx, "Could not initialize Pakfire: %m\n");
r = -errno;
goto ERROR;
}
// Create a new build environment
r = pakfire_build_create(&build, pakfire, job_id, build_flags);
if (r) {
- CTX_ERROR(ctx, "Could not setup the build environment: %m\n");
+ ERROR(ctx, "Could not setup the build environment: %m\n");
r = -errno;
goto ERROR;
}
// XXX THIS NEEDS TO BE PREFIXED WITH THE BASE PATH
r = pakfire_build_set_ccache_path(build, job->ccache_path);
if (r) {
- CTX_ERROR(ctx, "Could not set ccache path: %m\n");
+ ERROR(ctx, "Could not set ccache path: %m\n");
r = -errno;
goto ERROR;
}
// Format the job ID as string
uuid_unparse(job->job_id, job_id);
- CTX_DEBUG(job->ctx, "Launching job %s\n", job_id);
+ DEBUG(job->ctx, "Launching job %s\n", job_id);
// Update state
job->state = PAKFIRE_JOB_STATE_LAUNCHED;
// Setup standard output
r = pakfire_log_stream_create(&job->log.stdout, job->ctx, pakfire_job_stdout, job);
if (r < 0) {
- CTX_ERROR(job->ctx, "Could not setup standard output: %s\n", strerror(-r));
+ ERROR(job->ctx, "Could not setup standard output: %s\n", strerror(-r));
return -errno;
}
// Setup standard error
r = pakfire_log_stream_create(&job->log.stderr, job->ctx, pakfire_job_stderr, job);
if (r < 0) {
- CTX_ERROR(job->ctx, "Could not setup standard error: %s\n", strerror(-r));
+ ERROR(job->ctx, "Could not setup standard error: %s\n", strerror(-r));
return -errno;
}
// Fork this process
pid = clone3(&args, sizeof(args));
if (pid < 0) {
- CTX_ERROR(job->ctx, "Could not clone: %m\n");
+ ERROR(job->ctx, "Could not clone: %m\n");
return -errno;
job->control = NULL;
}
- CTX_INFO(job->ctx, "Will attempt to reconnect in %u second(s)\n",
+ INFO(job->ctx, "Will attempt to reconnect in %u second(s)\n",
job->reconnect_holdoff / 1000000);
// Set the reconnection timer
r = sd_event_source_set_time_relative(job->connect_timer, job->reconnect_holdoff);
if (r < 0) {
- CTX_ERROR(job->ctx, "Could not set the reconnection timer: %s\n", strerror(-r));
+ ERROR(job->ctx, "Could not set the reconnection timer: %s\n", strerror(-r));
return r;
}
// Activate the timer
r = sd_event_source_set_enabled(job->connect_timer, SD_EVENT_ONESHOT);
if (r < 0) {
- CTX_ERROR(job->ctx, "Could not activate the connect timer: %s\n", strerror(-r));
+ ERROR(job->ctx, "Could not activate the connect timer: %s\n", strerror(-r));
return r;
}
static int pakfire_job_connected(struct pakfire_xfer* xfer, void* data) {
struct pakfire_job* job = data;
- CTX_DEBUG(job->ctx, "Connected!\n");
+ DEBUG(job->ctx, "Connected!\n");
// Store a reference to the control connection
job->control = pakfire_xfer_ref(xfer);
// Format the job ID as string
uuid_unparse(job->job_id, job_id);
- CTX_INFO(job->ctx, "Connecting to job %s...\n", job_id);
+ INFO(job->ctx, "Connecting to job %s...\n", job_id);
// Fetch a reference to the HTTP client
client = pakfire_daemon_httpclient(job->daemon);
// Fetch a reference to the event loop
j->loop = pakfire_daemon_loop(daemon);
if (!j->loop) {
- CTX_ERROR(j->ctx, "Could not fetch the event loop: %m\n");
+ ERROR(j->ctx, "Could not fetch the event loop: %m\n");
r = -errno;
goto ERROR;
}
r = sd_event_add_time_relative(j->loop, &j->connect_timer,
CLOCK_MONOTONIC, 0, 0, pakfire_job_connect, j);
if (r < 0) {
- CTX_ERROR(j->ctx, "Could not register the connection timer: %s\n", strerror(-r));
+ ERROR(j->ctx, "Could not register the connection timer: %s\n", strerror(-r));
goto ERROR;
}
// Send a signal to the child process
r = pidfd_send_signal(job->pidfd, signal, NULL, 0);
if (r) {
- CTX_ERROR(job->ctx, "Could not terminate job: %m\n");
+ ERROR(job->ctx, "Could not terminate job: %m\n");
return r;
}
break;
default:
- CTX_ERROR(k->ctx, "Unsupported key algorithm %u\n", algo);
+ ERROR(k->ctx, "Unsupported key algorithm %u\n", algo);
r = -ENOTSUP;
goto ERROR;
}
break;
default:
- CTX_ERROR(ctx, "Invalid key algorithm %u\n", algo);
+ ERROR(ctx, "Invalid key algorithm %u\n", algo);
return -EINVAL;
}
// Generate a random key ID
r = RAND_bytes((unsigned char*)&key_id, sizeof(key_id));
if (r < 0) {
- CTX_ERROR(ctx, "Could not generate the key ID\n");
+ ERROR(ctx, "Could not generate the key ID\n");
r = -EINVAL;
goto ERROR;
}
// Setup the context
pctx = EVP_PKEY_CTX_new_id(id, NULL);
if (!pctx) {
- CTX_ERROR(ctx, "Could not allocate the OpenSSL context: %m\n");
+ ERROR(ctx, "Could not allocate the OpenSSL context: %m\n");
r = -ENOMEM;
goto ERROR;
}
if (r < 1) {
ERR_error_string_n(r, error, sizeof(error));
- CTX_ERROR(ctx, "Could not prepare the context: %s\n", error);
+ ERROR(ctx, "Could not prepare the context: %s\n", error);
r = -EINVAL;
goto ERROR;
}
if (r < 1) {
ERR_error_string_n(r, error, sizeof(error));
- CTX_ERROR(ctx, "Could not generate the key: %s\n", error);
+ ERROR(ctx, "Could not generate the key: %s\n", error);
r = -EINVAL;
goto ERROR;
}
// Check the signature algorithm
if (buffer->sig_algo[0] != 'E' || buffer->sig_algo[1] != 'd') {
- CTX_ERROR(ctx, "Unsupported signature algorithm\n");
+ ERROR(ctx, "Unsupported signature algorithm\n");
r = -ENOTSUP;
goto ERROR;
}
// Check the KDF algorithm
if (buffer->kdf_algo[0] != 'B' || buffer->kdf_algo[1] != 'K') {
- CTX_ERROR(ctx, "Unsupported KDF algorithm\n");
+ ERROR(ctx, "Unsupported KDF algorithm\n");
r = -ENOTSUP;
goto ERROR;
}
// We don't support encrypted keys here
if (buffer->kdf_rounds) {
- CTX_ERROR(ctx, "Encrypted keys are not supported\n");
+ ERROR(ctx, "Encrypted keys are not supported\n");
r = -ENOTSUP;
goto ERROR;
}
// Compute a SHA512 checksum over the key material
r = EVP_Digest(&buffer->keys, sizeof(buffer->keys), checksum, &length, EVP_sha512(), NULL);
if (r < 0) {
- CTX_ERROR(ctx, "Could not compute the checksum: %m\n");
+ ERROR(ctx, "Could not compute the checksum: %m\n");
goto ERROR;
}
// Compare the checksum
if (memcmp(buffer->checksum, checksum, sizeof(buffer->checksum)) != 0) {
- CTX_ERROR(ctx, "Checksum mismatch\n");
+ ERROR(ctx, "Checksum mismatch\n");
r = -EINVAL;
goto ERROR;
}
if (!pkey) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "Could not load secret key: %s\n", error);
+ ERROR(ctx, "Could not load secret key: %s\n", error);
r = -EINVAL;
goto ERROR;
}
// Check the signature algorithm
if (buffer->sig_algo[0] != 'E' || buffer->sig_algo[1] != 'd') {
- CTX_ERROR(ctx, "Unsupported signature algorithm\n");
+ ERROR(ctx, "Unsupported signature algorithm\n");
r = -ENOTSUP;
goto ERROR;
}
if (!pkey) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "Could not load public key: %s\n", error);
+ ERROR(ctx, "Could not load public key: %s\n", error);
r = -EINVAL;
goto ERROR;
}
// The first line must start with "untrusted comment:"
case 1:
if (!pakfire_string_startswith(line, "untrusted comment: ")) {
- CTX_ERROR(ctx, "The first line must start with 'untrusted comment: '"
+ ERROR(ctx, "The first line must start with 'untrusted comment: '"
" and not %s\n", line);
r = -EINVAL;
goto ERROR;
// Copy the comment
r = pakfire_string_set(comment, line + strlen("untrusted comment: "));
if (r < 0) {
- CTX_ERROR(ctx, "Could not copy comment: %m\n");
+ ERROR(ctx, "Could not copy comment: %m\n");
goto ERROR;
}
// Decode the key
r = pakfire_b64decode(ctx, &buffer, &buffer_length, line);
if (r) {
- CTX_ERROR(ctx, "Could not decode the key: %m\n");
+ ERROR(ctx, "Could not decode the key: %m\n");
r = -EINVAL;
goto ERROR;
}
// Unknown key
default:
- CTX_ERROR(ctx, "Unsupported key type\n");
+ ERROR(ctx, "Unsupported key type\n");
r = -ENOTSUP;
goto ERROR;
}
// Map the data to a file
f = fmemopen((char*)data, length, "r");
if (!f) {
- CTX_ERROR(ctx, "Could not map the key to file: %m\n");
+ ERROR(ctx, "Could not map the key to file: %m\n");
r = -errno;
goto ERROR;
}
if (r < 0) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(key->ctx, "Could not extract the public key: %s\n", error);
+ ERROR(key->ctx, "Could not extract the public key: %s\n", error);
return -EINVAL;
}
if (l > length) {
- CTX_ERROR(key->ctx, "The buffer was too small to write the public key\n");
+ ERROR(key->ctx, "The buffer was too small to write the public key\n");
return -ENOBUFS;
}
if (r < 0) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(key->ctx, "Could not extract the secret key: %s\n", error);
+ ERROR(key->ctx, "Could not extract the secret key: %s\n", error);
return -EINVAL;
}
if (l > length) {
- CTX_ERROR(key->ctx, "The buffer was too small to write the secret key\n");
+ ERROR(key->ctx, "The buffer was too small to write the secret key\n");
return -ENOBUFS;
}
break;
default:
- CTX_ERROR(key->ctx, "Unknown algorithm\n");
+ ERROR(key->ctx, "Unknown algorithm\n");
return -ENOTSUP;
}
// Generate a salt
r = RAND_bytes(buffer->kdf_salt, sizeof(buffer->kdf_salt));
if (r < 1) {
- CTX_ERROR(key->ctx, "Could not generate salt\n");
+ ERROR(key->ctx, "Could not generate salt\n");
return -EINVAL;
}
// Write the public key
r = pakfire_key_get_public_key(key, buffer->keys.public, sizeof(buffer->keys.public));
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not export the public key: %m\n");
+ ERROR(key->ctx, "Could not export the public key: %m\n");
return r;
}
// Write the secret key
r = pakfire_key_get_secret_key(key, buffer->keys.secret, sizeof(buffer->keys.secret));
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not export the secret key: %m\n");
+ ERROR(key->ctx, "Could not export the secret key: %m\n");
return r;
}
// Compute a SHA512 checksum over the key material
r = EVP_Digest(&buffer->keys, sizeof(buffer->keys), checksum, &length, EVP_sha512(), NULL);
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not compute the checksum: %m\n");
+ ERROR(key->ctx, "Could not compute the checksum: %m\n");
return r;
}
break;
default:
- CTX_ERROR(key->ctx, "Unknown algorithm\n");
+ ERROR(key->ctx, "Unknown algorithm\n");
return -ENOTSUP;
}
// Write the public key
r = pakfire_key_get_public_key(key, buffer->pubkey, sizeof(buffer->pubkey));
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not export the public key: %m\n");
+ ERROR(key->ctx, "Could not export the public key: %m\n");
return r;
}
if (*key->comment) {
r = fprintf(f, "untrusted comment: %s\n", key->comment);
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not write comment: %m\n");
+ ERROR(key->ctx, "Could not write comment: %m\n");
r = 1;
goto ERROR;
}
// Setup the base64 encoder
b64 = BIO_new(BIO_f_base64());
if (!b64) {
- CTX_ERROR(key->ctx, "Could not setup the base64 encoder\n");
+ ERROR(key->ctx, "Could not setup the base64 encoder\n");
r = 1;
goto ERROR;
}
bio = BIO_new_fp(f, BIO_NOCLOSE);
if (!bio) {
- CTX_ERROR(key->ctx, "Could not open BIO\n");
+ ERROR(key->ctx, "Could not open BIO\n");
r = 1;
goto ERROR;
}
// Write the output
r = BIO_write(b64, &public_key, sizeof(public_key));
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not write the public key\n");
+ ERROR(key->ctx, "Could not write the public key\n");
r = 1;
goto ERROR;
}
// Write the output
r = BIO_write(b64, &private_key, sizeof(private_key));
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not write the private key\n");
+ ERROR(key->ctx, "Could not write the private key\n");
goto ERROR;
}
break;
// Allocate a buffer in memory
fd = memfd_create("pakfire-key-dump", MFD_CLOEXEC);
if (fd < 0) {
- CTX_ERROR(key->ctx, "Could not allocate a temporary file: %m\n");
+ ERROR(key->ctx, "Could not allocate a temporary file: %m\n");
r = -errno;
goto ERROR;
}
// Re-open as FILE handle
f = fdopen(fd, "r+");
if (!f) {
- CTX_ERROR(key->ctx, "Could not open file handle for temporary file: %m\n");
+ ERROR(key->ctx, "Could not open file handle for temporary file: %m\n");
r = -errno;
goto ERROR;
}
// Export the public part of the key
r = pakfire_key_export(key, f, PAKFIRE_KEY_EXPORT_MODE_PUBLIC);
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not export key: %m\n");
+ ERROR(key->ctx, "Could not export key: %m\n");
goto ERROR;
}
// Allocate a buffer
buffer = calloc(1, length + 1);
if (!buffer) {
- CTX_ERROR(key->ctx, "Could not allocate buffer of %zu byte(s)\n", length + 1);
+ ERROR(key->ctx, "Could not allocate buffer of %zu byte(s)\n", length + 1);
r = -errno;
goto ERROR;
}
// Read everything into the buffer
size_t bytes_read = fread(buffer, 1, length, f);
if (bytes_read < length) {
- CTX_ERROR(key->ctx, "Could not read back the buffer: %m\n");
+ ERROR(key->ctx, "Could not read back the buffer: %m\n");
r = -errno;
goto ERROR;
}
// Create a message digest context
mdctx = EVP_MD_CTX_new();
if (!mdctx) {
- CTX_ERROR(key->ctx, "Could not initialize the message digest context: %m\n");
+ ERROR(key->ctx, "Could not initialize the message digest context: %m\n");
r = -ENOMEM;
goto ERROR;
}
// Setup the context
r = EVP_DigestSignInit(mdctx, NULL, NULL, NULL, key->pkey);
if (r < 1) {
- CTX_ERROR(key->ctx, "Could not setup context\n");
+ ERROR(key->ctx, "Could not setup context\n");
r = -EINVAL;
goto ERROR;
}
if (r < 1) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(key->ctx, "Could not sign content: %s\n", error);
+ ERROR(key->ctx, "Could not sign content: %s\n", error);
goto ERROR;
}
if (comment) {
r = fprintf(f, "untrusted comment: %s\n", comment);
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not write comment: %m\n");
+ ERROR(key->ctx, "Could not write comment: %m\n");
r = -errno;
goto ERROR;
}
// Write the signature
r = fprintf(f, "%s\n", s);
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not write the signature: %m\n");
+ ERROR(key->ctx, "Could not write the signature: %m\n");
r = -errno;
goto ERROR;
}
// The first line must start with "untrusted comment:"
case 1:
if (!pakfire_string_startswith(line, "untrusted comment:")) {
- CTX_ERROR(key->ctx, "The first line must start with 'untrusted comment:'\n");
+ ERROR(key->ctx, "The first line must start with 'untrusted comment:'\n");
r = -EINVAL;
goto ERROR;
}
// Decode the key
r = pakfire_b64decode(key->ctx, &buffer, &buffer_length, line);
if (r) {
- CTX_ERROR(key->ctx, "Could not decode the signature: %m\n");
+ ERROR(key->ctx, "Could not decode the signature: %m\n");
r = -EINVAL;
goto ERROR;
}
// Check if we support the signature type
if (signature->sig_algo[0] != 'E' || signature->sig_algo[1] != 'd') {
- CTX_ERROR(key->ctx, "Unknown signature type\n");
+ ERROR(key->ctx, "Unknown signature type\n");
r = -ENOTSUP;
goto ERROR;
}
break;
default:
- CTX_ERROR(key->ctx, "Unknown signature type\n");
+ ERROR(key->ctx, "Unknown signature type\n");
r = -ENOTSUP;
goto ERROR;
}
EVP_MD_CTX* mdctx = NULL;
int r;
- CTX_DEBUG(key->ctx, "Verifying signature...\n");
+ DEBUG(key->ctx, "Verifying signature...\n");
// Check the key ID
if (!pakfire_key_id_equals(&key->id, &signature->key_id)) {
- CTX_ERROR(key->ctx, "The signature has been created with a different key\n");
+ ERROR(key->ctx, "The signature has been created with a different key\n");
r = -EBADMSG;
goto ERROR;
}
// Create message digest context
mdctx = EVP_MD_CTX_new();
if (!mdctx) {
- CTX_ERROR(key->ctx, "Could not create the message digest context\n");
+ ERROR(key->ctx, "Could not create the message digest context\n");
r = -ENOMEM;
goto ERROR;
}
// Setup the context for verification
r = EVP_DigestVerifyInit(mdctx, NULL, NULL, NULL, key->pkey);
if (r < 1) {
- CTX_ERROR(key->ctx, "Could not setup the verification context\n");
+ ERROR(key->ctx, "Could not setup the verification context\n");
goto ERROR;
}
switch (r) {
// Fail
case 0:
- CTX_ERROR(key->ctx, "Signature verification failed\n");
+ ERROR(key->ctx, "Signature verification failed\n");
r = -EBADMSG;
break;
// Success
case 1:
- CTX_DEBUG(key->ctx, "Signature verification successful\n");
+ DEBUG(key->ctx, "Signature verification successful\n");
r = 0;
break;
// Error
default:
- CTX_ERROR(key->ctx, "Could not perform signature verification\n");
+ ERROR(key->ctx, "Could not perform signature verification\n");
r = -ENOTSUP;
goto ERROR;
}
// Read the signature
r = pakfire_key_read_signature(key, &signature, f);
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not read signature: %m\n");
+ ERROR(key->ctx, "Could not read signature: %m\n");
return r;
}
// Verify signature
r = pakfire_key_verify_signature(key, &signature, data, length);
if (r < 0) {
- CTX_ERROR(key->ctx, "Could not verify signature: %m\n");
+ ERROR(key->ctx, "Could not verify signature: %m\n");
return r;
}
TAILQ_INSERT_TAIL(&linter->results, result, nodes);
// Log the result
- CTX_DEBUG(linter->ctx, "%s: %s",
+ DEBUG(linter->ctx, "%s: %s",
pakfire_archive_get_path(linter->archive), result->comment);
// Call the callback
r = linter->result_callback(linter->ctx, linter->archive, linter->pkg,
priority, result->comment, linter->result_data);
if (r < 0) {
- CTX_ERROR(linter->ctx, "Linter result callback failed: %s\n", strerror(-r));
+ ERROR(linter->ctx, "Linter result callback failed: %s\n", strerror(-r));
return r;
}
}
// Fetch the package
r = pakfire_archive_make_package(l->archive, NULL, &l->pkg);
if (r < 0) {
- CTX_ERROR(l->ctx, "Could not open the package in %s: %s\n",
+ ERROR(l->ctx, "Could not open the package in %s: %s\n",
pakfire_archive_get_path(l->archive), strerror(-r));
goto ERROR;
}
static int pakfire_linter_init_libelf(struct pakfire_linter* linter) {
// Initialize libelf
if (elf_version(EV_CURRENT) == EV_NONE) {
- CTX_ERROR(linter->ctx, "Could not initialize libelf: %s\n", elf_errmsg(-1));
+ ERROR(linter->ctx, "Could not initialize libelf: %s\n", elf_errmsg(-1));
return -EINVAL;
}
// Parse the ELF header
elf = elf_begin(fd, ELF_C_READ, NULL);
if (!elf) {
- CTX_ERROR(linter->ctx, "Could not open ELF file: %s\n", elf_errmsg(-1));
+ ERROR(linter->ctx, "Could not open ELF file: %s\n", elf_errmsg(-1));
r = -EINVAL;
goto ERROR;
}
// Parse the ELF header
elf = elf_begin(fd, ELF_C_READ, NULL);
if (!elf) {
- CTX_ERROR(linter->ctx, "Could not open ELF file: %s\n", elf_errmsg(-1));
+ ERROR(linter->ctx, "Could not open ELF file: %s\n", elf_errmsg(-1));
r = -EINVAL;
goto ERROR;
}
break;
default:
- CTX_ERROR(linter->ctx, "%s is not an ELF object\n", pakfire_file_get_path(file));
+ ERROR(linter->ctx, "%s is not an ELF object\n", pakfire_file_get_path(file));
r = -EINVAL;
goto ERROR;
}
// Fetch the ELF header
if (!gelf_getehdr(elf, &ehdr)) {
- CTX_ERROR(linter->ctx, "Could not parse ELF header: %s\n", elf_errmsg(-1));
+ ERROR(linter->ctx, "Could not parse ELF header: %s\n", elf_errmsg(-1));
return -EINVAL;
}
// Allocate a new buffer
fd = memfd_create(path, MFD_ALLOW_SEALING|MFD_CLOEXEC);
if (fd < 0) {
- CTX_ERROR(linter->ctx, "memfd_create() failed: %m\n");
+ ERROR(linter->ctx, "memfd_create() failed: %m\n");
r = -errno;
goto ERROR;
}
// Tell the kernel how large the file would be
r = ftruncate(fd, size);
if (r < 0) {
- CTX_ERROR(linter->ctx, "fallocate() failed: %m\n");
+ ERROR(linter->ctx, "fallocate() failed: %m\n");
r = -errno;
goto ERROR;
}
// Read the payload into the file descriptor
r = archive_read_data_into_fd(a, fd);
if (r) {
- CTX_ERROR(linter->ctx, "Could not read %s: %s\n", path, archive_error_string(a));
+ ERROR(linter->ctx, "Could not read %s: %s\n", path, archive_error_string(a));
r = -errno;
goto ERROR;
}
// Check how much data we have read
off_t offset = lseek(fd, 0, SEEK_CUR);
if (offset < 0) {
- CTX_ERROR(linter->ctx, "lseek() failed: %m\n");
+ ERROR(linter->ctx, "lseek() failed: %m\n");
r = -errno;
goto ERROR;
}
- CTX_DEBUG(linter->ctx, "Read %jd byte(s)\n", offset);
+ DEBUG(linter->ctx, "Read %jd byte(s)\n", offset);
// Check if we didn't read too little data
if ((size_t)offset < size) {
// Rewind
offset = lseek(fd, 0, SEEK_SET);
if (offset) {
- CTX_ERROR(linter->ctx, "Could not rewind: %m\n");
+ ERROR(linter->ctx, "Could not rewind: %m\n");
r = -errno;
goto ERROR;
}
r = fcntl(fd, F_ADD_SEALS,
F_SEAL_SEAL|F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_FUTURE_WRITE);
if (r < 0) {
- CTX_ERROR(linter->ctx, "Could not seal the file: %m\n");
+ ERROR(linter->ctx, "Could not seal the file: %m\n");
r = -errno;
goto ERROR;
}
// Fetch path
const char* path = pakfire_file_get_path(file);
- CTX_DEBUG(linter->ctx, "Checking payload of %s\n", path);
+ DEBUG(linter->ctx, "Checking payload of %s\n", path);
// Read the file
r = pakfire_linter_read_file(linter, file, a);
if (r < 0)
goto ERROR;
- CTX_DEBUG(linter->ctx, "Linting %s...\n", pakfire_file_get_path(file));
+ DEBUG(linter->ctx, "Linting %s...\n", pakfire_file_get_path(file));
// Source Packages
if (pakfire_package_is_source(linter->pkg)) {
// Create a new pipe
r = pipe2(s->pipe, O_CLOEXEC);
if (r < 0) {
- CTX_ERROR(s->ctx, "Could not create a pipe: %m\n");
+ ERROR(s->ctx, "Could not create a pipe: %m\n");
r = -errno;
goto ERROR;
}
// Log a message if we don't have a callback
if (!stream->callback) {
- CTX_ERROR(stream->ctx, "Log stream has no callback set\n");
+ ERROR(stream->ctx, "Log stream has no callback set\n");
return -EINVAL;
}
r = sd_event_add_io(loop, &stream->event, stream->pipe[0],
EPOLLIN|EPOLLHUP, __pakfire_log_stream, stream);
if (r < 0) {
- CTX_ERROR(stream->ctx, "Could not register fd %d: %s\n", stream->pipe[0], strerror(-r));
+ ERROR(stream->ctx, "Could not register fd %d: %s\n", stream->pipe[0], strerror(-r));
return r;
}
}
void pakfire_mirror_mark_as_broken(struct pakfire_mirror* mirror) {
- CTX_DEBUG(mirror->ctx, "Mirror %s has been marked as broken\n", mirror->url);
+ DEBUG(mirror->ctx, "Mirror %s has been marked as broken\n", mirror->url);
mirror->is_broken = 1;
}
r = json_object_object_get_ex(root, "type", &typeobj);
if (!r) {
- CTX_ERROR(list->ctx, "mirrorlist does not have a 'type' attribute\n");
+ ERROR(list->ctx, "mirrorlist does not have a 'type' attribute\n");
goto ERROR;
}
const char* type = json_object_get_string(typeobj);
if (!type) {
- CTX_ERROR(list->ctx, "mirrorlist has an empty or unknown 'type' attribute\n");
+ ERROR(list->ctx, "mirrorlist has an empty or unknown 'type' attribute\n");
goto ERROR;
}
if (strcmp(type, "mirrorlist") != 0) {
- CTX_ERROR(list->ctx, "Unexpected type: %s\n", type);
+ ERROR(list->ctx, "Unexpected type: %s\n", type);
goto ERROR;
}
return 1;
}
- CTX_DEBUG(list->ctx, "Reading mirrorlist from %s\n", path);
+ DEBUG(list->ctx, "Reading mirrorlist from %s\n", path);
struct json_object* json = pakfire_json_parse_from_file(list->ctx, path);
if (!json) {
if (errno == ENOENT)
return 0;
- CTX_ERROR(list->ctx, "Could not parse mirrorlist from %s: %m\n", path);
+ ERROR(list->ctx, "Could not parse mirrorlist from %s: %m\n", path);
return 1;
}
// Add the new mirrors
r = json_object_object_get_ex(json, "mirrors", &mirrors);
if (!r) {
- CTX_DEBUG(list->ctx, "Mirrorlist has no mirrors\n");
+ DEBUG(list->ctx, "Mirrorlist has no mirrors\n");
r = 0;
goto ERROR;
}
// Add the mirror to the downloader
r = pakfire_mirrorlist_add_mirror_from_url(list, url);
if (r) {
- CTX_ERROR(list->ctx, "Could not add mirror %s: %m\n", url);
+ ERROR(list->ctx, "Could not add mirror %s: %m\n", url);
goto ERROR;
}
}
};
int pakfire_mount_change_propagation(struct pakfire_ctx* ctx, const char* path, int propagation) {
- CTX_DEBUG(ctx, "Changing mount propagation on %s\n", path);
+ DEBUG(ctx, "Changing mount propagation on %s\n", path);
int r = mount(NULL, path, NULL, propagation|MS_REC, NULL);
if (r)
- CTX_ERROR(ctx, "Failed to change mount propagation on %s: %m\n", path);
+ ERROR(ctx, "Failed to change mount propagation on %s: %m\n", path);
return r;
}
break;
default:
- CTX_ERROR(ctx, "Could not determine whether %s is a mountpoint: %m\n", path);
+ ERROR(ctx, "Could not determine whether %s is a mountpoint: %m\n", path);
return r;
}
// Bind-mount to self
r = mount(path, path, NULL, MS_BIND|MS_REC, NULL);
if (r) {
- CTX_ERROR(ctx, "Could not make %s a mountpoint: %m\n", path);
+ ERROR(ctx, "Could not make %s a mountpoint: %m\n", path);
return r;
}
return 1;
}
- CTX_DEBUG(ctx, "Mounting %s from %s (%s - %s)\n", target, source, fstype, options);
+ DEBUG(ctx, "Mounting %s from %s (%s - %s)\n", target, source, fstype, options);
// Perform mount()
int r = mount(source, target, fstype, mflags, data);
if (r) {
- CTX_ERROR(ctx, "Could not mount %s: %m\n", target);
+ ERROR(ctx, "Could not mount %s: %m\n", target);
}
return r;
struct pakfire_ctx* ctx = data;
// Send the line to the logger
- CTX_DEBUG(ctx, " %.*s", (int)length, line);
+ DEBUG(ctx, " %.*s", (int)length, line);
return 0;
}
int pakfire_mount_list(struct pakfire_ctx* ctx) {
- CTX_DEBUG(ctx, "Mountpoints:\n");
+ DEBUG(ctx, "Mountpoints:\n");
return pakfire_parse_file("/proc/self/mounts", __pakfire_mount_list, ctx);
}
// Create device nodes
for (const struct pakfire_devnode* devnode = devnodes; devnode->path; devnode++) {
- CTX_DEBUG(ctx, "Creating device node %s\n", devnode->path);
+ DEBUG(ctx, "Creating device node %s\n", devnode->path);
// Check if flags match
if (devnode->flags && !(flags & devnode->flags))
goto MOUNT;
// Otherwise log an error and end
- CTX_ERROR(ctx, "Could not create %s: %m\n", devnode->path);
+ ERROR(ctx, "Could not create %s: %m\n", devnode->path);
return r;
MOUNT:
// Create an empty file
r = pakfire_touch(path, 0444);
if (r) {
- CTX_ERROR(ctx, "Could not create %s: %m\n", path);
+ ERROR(ctx, "Could not create %s: %m\n", path);
return r;
}
// Create symlinks
for (const struct pakfire_symlink* s = symlinks; s->target; s++) {
- CTX_DEBUG(ctx, "Creating symlink %s -> %s\n", s->path, s->target);
+ DEBUG(ctx, "Creating symlink %s -> %s\n", s->path, s->target);
int r = pakfire_path(pakfire, path, "%s", s->path);
if (r)
r = symlink(s->target, path);
if (r) {
- CTX_ERROR(ctx, "Could not create symlink %s: %m\n", s->path);
+ ERROR(ctx, "Could not create symlink %s: %m\n", s->path);
return r;
}
}
if (!interpreter)
return 0;
- CTX_DEBUG(ctx, "Mounting interpreter %s for %s\n", interpreter, arch);
+ DEBUG(ctx, "Mounting interpreter %s for %s\n", interpreter, arch);
// Where to mount this?
int r = pakfire_path(pakfire, target, "%s", interpreter);
r = pakfire_mount(ctx, interpreter, target, NULL, MS_BIND|MS_RDONLY, NULL);
if (r)
- CTX_ERROR(ctx, "Could not mount interpreter %s to %s: %m\n", interpreter, target);
+ ERROR(ctx, "Could not mount interpreter %s to %s: %m\n", interpreter, target);
return r;
}
if (!pakfire_path_exists(target)) {
r = pakfire_mkdir(target, 0755);
if (r) {
- CTX_ERROR(ctx, "Could not create %s: %m\n", target);
+ ERROR(ctx, "Could not create %s: %m\n", target);
return r;
}
}
if (r)
return r;
- CTX_DEBUG(ctx, "Bind-mounting %s to %s\n", src, mountpoint);
+ DEBUG(ctx, "Bind-mounting %s to %s\n", src, mountpoint);
r = stat(src, &st);
if (r < 0) {
- CTX_ERROR(ctx, "Could not stat %s: %m\n", src);
+ ERROR(ctx, "Could not stat %s: %m\n", src);
return 1;
}
// Allocate a new solvable
Id id = pakfire_repo_add_solvable(repo);
if (!id) {
- CTX_ERROR(ctx, "Could not allocate a solvable: %m\n");
+ ERROR(ctx, "Could not allocate a solvable: %m\n");
r = 1;
goto ERROR;
}
// Set the name
r = pakfire_package_set_string(*package, PAKFIRE_PKG_NAME, name);
if (r) {
- CTX_ERROR(ctx, "Could not set package name '%s': %m\n", name);
+ ERROR(ctx, "Could not set package name '%s': %m\n", name);
goto ERROR;
}
// Set EVR
r = pakfire_package_set_string(*package, PAKFIRE_PKG_EVR, evr);
if (r) {
- CTX_ERROR(ctx, "Could not set package EVR '%s': %m\n", evr);
+ ERROR(ctx, "Could not set package EVR '%s': %m\n", evr);
goto ERROR;
}
// Set arch
r = pakfire_package_set_string(*package, PAKFIRE_PKG_ARCH, arch);
if (r) {
- CTX_ERROR(ctx, "Could not set package arch '%s': %m\n", arch);
+ ERROR(ctx, "Could not set package arch '%s': %m\n", arch);
goto ERROR;
}
// Add self-provides
r = pakfire_package_add_self_provides(*package);
if (r) {
- CTX_ERROR(ctx, "Could not create self-provides: %m\n");
+ ERROR(ctx, "Could not create self-provides: %m\n");
goto ERROR;
}
// Fetch the filename
const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
if (!filename) {
- CTX_ERROR(pkg->ctx, "Could not fetch filename for %s: %m\n", nevra);
+ ERROR(pkg->ctx, "Could not fetch filename for %s: %m\n", nevra);
return 1;
}
// Fetch UUID
const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
if (!uuid) {
- CTX_ERROR(pkg->ctx, "Could not fetch UUID for %s: %m\n", nevra);
+ ERROR(pkg->ctx, "Could not fetch UUID for %s: %m\n", nevra);
return 1;
}
// Open archive
r = pakfire_archive_open(&archive, pkg->pakfire, path);
if (r) {
- CTX_ERROR(pkg->ctx, "Could not open archive for %s (at %s): %m\n",
+ ERROR(pkg->ctx, "Could not open archive for %s (at %s): %m\n",
pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA), path);
goto ERROR;
}
// Fetch repodata
struct pakfire_repo* repo = pakfire_package_get_repo(pkg);
if (!repo) {
- CTX_ERROR(pkg->ctx, "Could not find repository for %s: %m\n",
+ ERROR(pkg->ctx, "Could not find repository for %s: %m\n",
pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA));
return 1;
}
// Fetch the filelist
filelist = pakfire_package_get_filelist(pkg);
if (!filelist) {
- CTX_ERROR(pkg->ctx, "Could not fetch package filelist\n");
+ ERROR(pkg->ctx, "Could not fetch package filelist\n");
r = 1;
goto ERROR;
}
// Create a new JSON array
object = json_object_new_array();
if (!object) {
- CTX_ERROR(pkg->ctx, "Could not create a JSON array\n");
+ ERROR(pkg->ctx, "Could not create a JSON array\n");
r = 1;
goto ERROR;
}
const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR);
if (!name || !evr) {
- CTX_ERROR(ctx, "Could not fetch package information: %m\n");
+ ERROR(ctx, "Could not fetch package information: %m\n");
return 1;
}
// Add package information to the list
r = pakfire_json_add_string(object, name, evr);
if (r) {
- CTX_ERROR(ctx, "Could not add package to packages list: %m\n");
+ ERROR(ctx, "Could not add package to packages list: %m\n");
return r;
}
// Create a new JSON array
object = json_object_new_object();
if (!object) {
- CTX_ERROR(pkg->ctx, "Could not create a new JSON object: %m\n");
+ ERROR(pkg->ctx, "Could not create a new JSON object: %m\n");
r = 1;
goto ERROR;
}
// Fetch the installed repository
repo = pakfire_get_installed_repo(pkg->pakfire);
if (!repo) {
- CTX_ERROR(pkg->ctx, "Could not fetch the installed repository: %m\n");
+ ERROR(pkg->ctx, "Could not fetch the installed repository: %m\n");
r = 1;
goto ERROR;
}
// Fetch all installed packages
r = pakfire_repo_to_packagelist(repo, packages);
if (r) {
- CTX_ERROR(pkg->ctx, "Could not fetch packages from installed repository: %m\n");
+ ERROR(pkg->ctx, "Could not fetch packages from installed repository: %m\n");
goto ERROR;
}
r = pakfire_transaction_request_package(transaction,
PAKFIRE_JOB_INSTALL, pkg, PAKFIRE_JOB_ESSENTIAL);
if (r) {
- CTX_ERROR(pkg->ctx, "Could not add package %s to the request\n", nevra);
+ ERROR(pkg->ctx, "Could not add package %s to the request\n", nevra);
goto ERROR;
}
// Solve the transaction
r = pakfire_transaction_solve(transaction, PAKFIRE_TRANSACTION_WITHOUT_RECOMMENDED, &p);
if (r) {
- CTX_DEBUG(pkg->ctx, "Could not install %s:\n%s\n", nevra, p);
+ DEBUG(pkg->ctx, "Could not install %s:\n%s\n", nevra, p);
// Copy the problem string
if (p)
// Allocate a new element
element = calloc(1, sizeof *element);
if (!element) {
- CTX_ERROR(list->ctx, "Could not allocate a new packagelist element: %m\n");
+ ERROR(list->ctx, "Could not allocate a new packagelist element: %m\n");
return 1;
}
// Set distribution
const char* tag = pakfire_get_distro_tag(p->pakfire);
if (!tag) {
- CTX_ERROR(p->ctx, "Distribution tag is not configured: %m\n");
+ ERROR(p->ctx, "Distribution tag is not configured: %m\n");
goto ERROR;
}
// Fetch the hostname
r = gethostname(hostname, sizeof(hostname));
if (r) {
- CTX_ERROR(p->ctx, "Could not determine the hostname: %m\n");
+ ERROR(p->ctx, "Could not determine the hostname: %m\n");
goto ERROR;
}
// Set build host
r = pakfire_package_set_string(pkg, PAKFIRE_PKG_BUILD_HOST, hostname);
if (r) {
- CTX_ERROR(p->ctx, "Could not set the hostname: %s\n", strerror(r));
+ ERROR(p->ctx, "Could not set the hostname: %s\n", strerror(r));
goto ERROR;
}
// Create a new file
struct archive_entry* entry = pakfire_packager_create_file(packager, filename, size, mode);
if (!entry) {
- CTX_ERROR(packager->ctx, "Could not create file '%s'\n", filename);
+ ERROR(packager->ctx, "Could not create file '%s'\n", filename);
return 1;
}
// This is the end of the header
int r = archive_write_header(a, entry);
if (r) {
- CTX_ERROR(packager->ctx, "Error writing header: %s\n", archive_error_string(a));
+ ERROR(packager->ctx, "Error writing header: %s\n", archive_error_string(a));
goto ERROR;
}
// Write content
r = archive_write_data(a, buffer, strlen(buffer));
if (r < 0) {
- CTX_ERROR(packager->ctx, "Error writing data: %s\n", archive_error_string(a));
+ ERROR(packager->ctx, "Error writing data: %s\n", archive_error_string(a));
goto ERROR;
}
struct archive* a) {
const char buffer[] = TO_STRING(PACKAGE_FORMAT) "\n";
- CTX_DEBUG(packager->ctx, "Writing package format\n");
+ DEBUG(packager->ctx, "Writing package format\n");
int r = pakfire_packager_write_file_from_buffer(packager, a,
"pakfire-format", 0444, buffer);
if (!buffer)
return 1;
- CTX_DEBUG(packager->ctx, "Generated package metadata:\n%s\n", buffer);
+ DEBUG(packager->ctx, "Generated package metadata:\n%s\n", buffer);
// Write buffer
int r = pakfire_packager_write_file_from_buffer(packager, a,
// Fetch type
const char* type = pakfire_scriptlet_get_type(scriptlet);
- CTX_DEBUG(packager->ctx, "Writing scriptlet '%s' to package\n", type);
+ DEBUG(packager->ctx, "Writing scriptlet '%s' to package\n", type);
// Make filename
r = pakfire_string_format(filename, ".scriptlets/%s", type);
// Start with the format file
r = pakfire_packager_write_format(packager, a);
if (r) {
- CTX_ERROR(packager->ctx, "Could not add format file to archive: %s\n",
+ ERROR(packager->ctx, "Could not add format file to archive: %s\n",
archive_error_string(a));
goto ERROR;
}
// Write the metadata
r = pakfire_packager_write_metadata(packager, a);
if (r) {
- CTX_ERROR(packager->ctx, "Could not add metadata file to archive: %s\n",
+ ERROR(packager->ctx, "Could not add metadata file to archive: %s\n",
archive_error_string(a));
goto ERROR;
}
for (unsigned int i = 0; i < packager->num_scriptlets; i++) {
r = pakfire_packager_write_scriptlet(packager, a, packager->scriptlets[i]);
if (r) {
- CTX_ERROR(packager->ctx, "Could not add scriptlet to the archive: %m\n");
+ ERROR(packager->ctx, "Could not add scriptlet to the archive: %m\n");
goto ERROR;
}
}
// Get the filename of the package
const char* filename = pakfire_packager_filename(packager);
if (!filename) {
- CTX_ERROR(packager->ctx, "Could not generate filename for package: %m\n");
+ ERROR(packager->ctx, "Could not generate filename for package: %m\n");
r = 1;
goto ERROR;
}
// Write the finished package
r = pakfire_packager_finish(packager, f);
if (r) {
- CTX_ERROR(packager->ctx, "pakfire_packager_finish() failed: %m\n");
+ ERROR(packager->ctx, "pakfire_packager_finish() failed: %m\n");
goto ERROR;
}
// Move the temporary file to destination
r = rename(tmppath, path);
if (r) {
- CTX_ERROR(packager->ctx, "Could not move %s to %s: %m\n", tmppath, path);
+ ERROR(packager->ctx, "Could not move %s to %s: %m\n", tmppath, path);
goto ERROR;
}
- CTX_DEBUG(packager->ctx, "Package written to %s\n", path);
+ DEBUG(packager->ctx, "Package written to %s\n", path);
// Store result path if requested
if (result) {
// Files cannot have an empty path
if (!path || !*path) {
- CTX_ERROR(packager->ctx, "Cannot add a file with an empty path\n");
+ ERROR(packager->ctx, "Cannot add a file with an empty path\n");
errno = EPERM;
return 1;
// Hidden files cannot be added
} else if (*path == '.') {
- CTX_ERROR(packager->ctx, "Hidden files cannot be added to a package: %s\n", path);
+ ERROR(packager->ctx, "Hidden files cannot be added to a package: %s\n", path);
errno = EPERM;
return 1;
}
- CTX_DEBUG(packager->ctx, "Adding file to payload: %s\n", path);
+ DEBUG(packager->ctx, "Adding file to payload: %s\n", path);
// Detect the MIME type
r = pakfire_file_detect_mimetype(file);
// Read everything
r = archive_read_disk_entry_from_file(packager->reader, entry, -1, NULL);
if (r) {
- CTX_ERROR(packager->ctx, "Could not read %s: %s\n",
+ ERROR(packager->ctx, "Could not read %s: %s\n",
sourcepath, archive_error_string(packager->reader));
r = -errno;
goto ERROR;
// Create a new file object from the archive entry
r = pakfire_file_create_from_archive_entry(&file, packager->pakfire, entry);
if (r < 0) {
- CTX_ERROR(packager->ctx, "Could not create file object: %s\n", strerror(-r));
+ ERROR(packager->ctx, "Could not create file object: %s\n", strerror(-r));
goto ERROR;
}
// Check if the ID is in range
if (id > subid->length) {
- CTX_ERROR(pakfire->ctx, "Mapped ID is out of range. Setting to %u\n", subid->id);
+ 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) {
- CTX_ERROR(pakfire->ctx, "Mapped ID is out of range. Setting to %u\n", subid->id);
+ 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;
- CTX_DEBUG(pakfire->ctx, "pool: %s", s);
+ 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);
- CTX_DEBUG(pakfire->ctx, "Namespace callback called for %s(%s)\n", namespace, name);
+ 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) {
- CTX_ERROR(pakfire->ctx, "uname() failed: %m\n");
+ ERROR(pakfire->ctx, "uname() failed: %m\n");
return r;
}
- CTX_DEBUG(pakfire->ctx, "Locking running kernel %s\n", utsname.release);
+ DEBUG(pakfire->ctx, "Locking running kernel %s\n", utsname.release);
r = pakfire_string_format(buffer, "kernel(%s)", utsname.release);
if (r)
if (repo) {
r = pakfire_repo_clean(repo, PAKFIRE_REPO_CLEAN_FLAGS_DESTROY);
if (r)
- CTX_ERROR(pakfire->ctx, "Could not cleanup %s repository: %m\n", PAKFIRE_REPO_COMMANDLINE);
+ ERROR(pakfire->ctx, "Could not cleanup %s repository: %m\n", PAKFIRE_REPO_COMMANDLINE);
pakfire_repo_unref(repo);
}
if (pakfire->snapshot) {
r = pakfire_snapshot_umount(pakfire->snapshot);
if (r)
- CTX_ERROR(pakfire->ctx, "Could not umount the snapshot: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not umount the snapshot: %s\n", strerror(-r));
pakfire_snapshot_unref(pakfire->snapshot);
}
if (pakfire->internal_flags & PAKFIRE_UMOUNT_PATH) {
r = umount2(pakfire->path, 0);
if (r)
- CTX_ERROR(pakfire->ctx, "Could not umount ramdisk at %s: %m\n", pakfire->path);
+ ERROR(pakfire->ctx, "Could not umount ramdisk at %s: %m\n", pakfire->path);
}
// Destroy path
if (pakfire->internal_flags & PAKFIRE_DESTROY_ON_FREE) {
- CTX_DEBUG(pakfire->ctx, "Destroying %s\n", pakfire->path);
+ DEBUG(pakfire->ctx, "Destroying %s\n", pakfire->path);
// Destroy the temporary directory
r = pakfire_rmtree(pakfire->path, 0);
if (r)
- CTX_ERROR(pakfire->ctx, "Could not destroy %s: %s\n", pakfire->path, strerror(-r));
+ ERROR(pakfire->ctx, "Could not destroy %s: %s\n", pakfire->path, strerror(-r));
}
pakfire_repo_free_all(pakfire);
// We must be root in order to operate in /
if (pakfire->user.uid) {
- CTX_ERROR(pakfire->ctx, "Must be running as root on /\n");
+ ERROR(pakfire->ctx, "Must be running as root on /\n");
return -EPERM;
}
if (r)
return r;
- CTX_DEBUG(pakfire->ctx, "Reading repository configuration from %s\n", path);
+ DEBUG(pakfire->ctx, "Reading repository configuration from %s\n", path);
// Open path
DIR* dir = opendir(path);
return 0;
default:
- CTX_ERROR(pakfire->ctx, "Could not open %s: %m\n", path);
+ ERROR(pakfire->ctx, "Could not open %s: %m\n", path);
return -errno;
}
}
if (name) {
r = pakfire_string_set(pakfire->distro.name, name);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro name: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro name: %s\n", strerror(-r));
return r;
}
}
if (id) {
r = pakfire_string_set(pakfire->distro.id, id);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro ID: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro ID: %s\n", strerror(-r));
return r;
}
}
if (version_id) {
r = pakfire_string_set(pakfire->distro.version_id, version_id);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro version ID: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro version ID: %s\n", strerror(-r));
return r;
}
}
if (codename) {
r = pakfire_string_set(pakfire->distro.version_codename, codename);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro codename: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro codename: %s\n", strerror(-r));
return r;
}
}
r = pakfire_string_format(pakfire->distro.version, "%s (%s)",
pakfire->distro.version_id, pakfire->distro.version_codename);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro version: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro version: %s\n", strerror(-r));
return r;
}
} else {
r = pakfire_string_set(pakfire->distro.version, pakfire->distro.version_id);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro version: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro version: %s\n", strerror(-r));
return r;
}
}
r = pakfire_string_format(pakfire->distro.pretty_name, "%s %s",
pakfire->distro.name, pakfire->distro.version);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro pretty name: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro pretty name: %s\n", strerror(-r));
return r;
}
if (vendor) {
r = pakfire_string_set(pakfire->distro.vendor, vendor);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro vendor: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro vendor: %s\n", strerror(-r));
return r;
}
}
if (slogan) {
r = pakfire_string_set(pakfire->distro.slogan, slogan);
if (r < 0) {
- CTX_ERROR(pakfire->ctx, "Could not set distro slogan: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not set distro slogan: %s\n", strerror(-r));
return r;
}
}
return 0;
default:
- CTX_ERROR(pakfire->ctx, "Could not read /etc/os-release: %s\n", strerror(-r));
+ ERROR(pakfire->ctx, "Could not read /etc/os-release: %s\n", strerror(-r));
break;
}
}
if (path) {
// Check that we don't have path set when using snapshots
if (flags & PAKFIRE_USE_SNAPSHOT) {
- CTX_ERROR(ctx, "Cannot use path with snapshots\n");
+ ERROR(ctx, "Cannot use path with snapshots\n");
r = -EINVAL;
goto ERROR;
}
// Path must be absolute
if (!pakfire_string_startswith(path, "/")) {
- CTX_ERROR(ctx, "Invalid path: %s\n", path);
+ ERROR(ctx, "Invalid path: %s\n", path);
r = -EINVAL;
goto ERROR;
}
// Determine the effective architecture
p->arches.effective = pakfire_arch_is_supported_by_host(arch);
if (!p->arches.effective) {
- CTX_ERROR(p->ctx, "Unsupported architecture: %s\n", arch);
+ ERROR(p->ctx, "Unsupported architecture: %s\n", arch);
r = -ENOTSUP;
goto ERROR;
}
// Setup user/group
r = pakfire_setup_user(p);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not parse user information: %s\n", strerror(-r));
+ ERROR(p->ctx, "Could not parse user information: %s\n", strerror(-r));
goto ERROR;
}
if (conf) {
r = pakfire_config_read(p->config, conf);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not read configuration: %s\n", strerror(-r));
+ ERROR(p->ctx, "Could not read configuration: %s\n", strerror(-r));
goto ERROR;
}
}
// Import distro configuration
r = pakfire_config_import_distro(p);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not parse distribution from configuration: %s\n", strerror(-r));
+ ERROR(p->ctx, "Could not parse distribution from configuration: %s\n", strerror(-r));
goto ERROR;
}
// Set cache path
r = pakfire_set_cache_path(p);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not set cache path: %m\n");
+ ERROR(p->ctx, "Could not set cache path: %m\n");
goto ERROR;
}
// Find the most recent snapshot
r = pakfire_snapshot_find(&p->snapshot, p);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not find a snapshot: %s\n", strerror(-r));
+ ERROR(p->ctx, "Could not find a snapshot: %s\n", strerror(-r));
goto ERROR;
}
}
if (p->snapshot) {
r = pakfire_snapshot_mount(p->snapshot, path);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not mount snapshot: %s\n", strerror(-r));
+ ERROR(p->ctx, "Could not mount snapshot: %s\n", strerror(-r));
goto ERROR;
}
} else {
r = mount("pakfire_root", path, "tmpfs", 0, NULL);
if (r) {
- CTX_ERROR(p->ctx, "Could not mount tmpfs: %m\n");
+ ERROR(p->ctx, "Could not mount tmpfs: %m\n");
r = -errno;
goto ERROR;
}
goto ERROR;
}
- 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));
+ DEBUG(p->ctx, "Pakfire initialized at %p\n", p);
+ DEBUG(p->ctx, " user = %s (%u)\n", p->user.name, p->user.uid);
+ DEBUG(p->ctx, " group = %s (%u)\n", p->group.name, p->group.gid);
+ DEBUG(p->ctx, " arch = %s (%s)\n", pakfire_get_arch(p), pakfire_get_effective_arch(p));
+ DEBUG(p->ctx, " path = %s\n", pakfire_get_path(p));
if (p->user.subuids.id)
- CTX_DEBUG(p->ctx, " subuid = %u (%zu)\n", p->user.subuids.id, p->user.subuids.length);
+ DEBUG(p->ctx, " subuid = %u (%zu)\n", p->user.subuids.id, p->user.subuids.length);
if (p->group.subgids.id)
- CTX_DEBUG(p->ctx, " subgid = %u (%zu)\n", p->group.subgids.id, p->group.subgids.length);
+ DEBUG(p->ctx, " subgid = %u (%zu)\n", p->group.subgids.id, p->group.subgids.length);
// Dump distribution configuration
- 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);
+ DEBUG(p->ctx, " Distribution: %s\n", p->distro.pretty_name);
+ DEBUG(p->ctx, " name = %s\n", p->distro.name);
+ DEBUG(p->ctx, " id = %s\n", p->distro.id);
+ DEBUG(p->ctx, " version = %s\n", p->distro.version);
+ DEBUG(p->ctx, " version_id = %s\n", p->distro.version_id);
if (*p->distro.version_codename)
- CTX_DEBUG(p->ctx, " codename = %s\n", p->distro.version_codename);
+ DEBUG(p->ctx, " codename = %s\n", p->distro.version_codename);
if (*p->distro.vendor)
- CTX_DEBUG(p->ctx, " vendor = %s\n", p->distro.vendor);
+ DEBUG(p->ctx, " vendor = %s\n", p->distro.vendor);
if (*p->distro.slogan)
- CTX_DEBUG(p->ctx, " slogan = %s\n", p->distro.slogan);
+ DEBUG(p->ctx, " slogan = %s\n", p->distro.slogan);
// Check if the distribution has been configured
if (!*p->distro.id || !*p->distro.version_id) {
- CTX_ERROR(p->ctx, "Invalid distribution configuration\n");
+ ERROR(p->ctx, "Invalid distribution configuration\n");
r = -EINVAL;
goto ERROR;
}
// Check if path is set
if (!*pakfire->path) {
- CTX_ERROR(pakfire->ctx, "pakfire_path() called without path being set\n");
+ ERROR(pakfire->ctx, "pakfire_path() called without path being set\n");
return -ENOTSUP;
}
// Find the commandline repository
repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_COMMANDLINE);
if (!repo) {
- CTX_ERROR(pakfire->ctx, "Could not find the commandline repository: %m\n");
+ ERROR(pakfire->ctx, "Could not find the commandline repository: %m\n");
return 1;
}
if (uid == 0)
return "root";
- CTX_DEBUG(pakfire->ctx, "Looking up name for UID %ld\n", uid);
+ 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) {
- CTX_ERROR(pakfire->ctx, "Could not retrieve uname for %ld: %m\n", uid);
+ ERROR(pakfire->ctx, "Could not retrieve uname for %ld: %m\n", uid);
return 0;
}
- CTX_DEBUG(pakfire->ctx, "Mapping UID %ld to %s\n", uid, entry->pw_name);
+ DEBUG(pakfire->ctx, "Mapping UID %ld to %s\n", uid, entry->pw_name);
return entry->pw_name;
}
if (gid == 0)
return "root";
- CTX_DEBUG(pakfire->ctx, "Looking up name for GID %ld\n", gid);
+ 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) {
- CTX_ERROR(pakfire->ctx, "Could not retrieve gname for %ld: %m\n", gid);
+ ERROR(pakfire->ctx, "Could not retrieve gname for %ld: %m\n", gid);
return 0;
}
- CTX_DEBUG(pakfire->ctx, "Mapping GID %ld to %s\n", gid, entry->gr_name);
+ DEBUG(pakfire->ctx, "Mapping GID %ld to %s\n", gid, entry->gr_name);
return entry->gr_name;
}
// Create a new reader
reader = archive_read_disk_new();
if (!reader) {
- CTX_ERROR(pakfire->ctx, "Could not set up reader: %m\n");
+ ERROR(pakfire->ctx, "Could not set up reader: %m\n");
return NULL;
}
// Do not read fflags
r = archive_read_disk_set_behavior(reader, ARCHIVE_READDISK_NO_FFLAGS);
if (r) {
- CTX_ERROR(pakfire->ctx, "Could not change behavior of reader: %s\n",
+ ERROR(pakfire->ctx, "Could not change behavior of reader: %s\n",
archive_error_string(reader));
goto ERROR;
}
if (strcmp(name, "root") == 0)
goto ERROR;
- CTX_DEBUG(pakfire->ctx, "Looking up UID for '%s' (%ld)\n", name, uid);
+ 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) {
- CTX_ERROR(pakfire->ctx, "Could not retrieve UID for '%s': %m\n", name);
+ ERROR(pakfire->ctx, "Could not retrieve UID for '%s': %m\n", name);
goto ERROR;
}
- CTX_DEBUG(pakfire->ctx, "Mapping %s to UID %u\n", name, entry->pw_uid);
+ 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)
goto ERROR;
- CTX_DEBUG(pakfire->ctx, "Looking up GID for '%s' (%ld)\n", name, gid);
+ 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) {
- CTX_ERROR(pakfire->ctx, "Could not retrieve GID for '%s': %m\n", name);
+ ERROR(pakfire->ctx, "Could not retrieve GID for '%s': %m\n", name);
goto ERROR;
}
- CTX_DEBUG(pakfire->ctx, "Mapping %s to GID %u\n", name, entry->gr_gid);
+ DEBUG(pakfire->ctx, "Mapping %s to GID %u\n", name, entry->gr_gid);
return pakfire_map_id(pakfire, &pakfire->group.subgids, entry->gr_gid);
// Create a new writer
pakfire->writer = archive_write_disk_new();
if (!pakfire->writer) {
- CTX_ERROR(pakfire->ctx, "Could not set up writer: %m\n");
+ ERROR(pakfire->ctx, "Could not set up writer: %m\n");
return NULL;
}
#ifdef PAKFIRE_DEBUG_PARSER
if (*namespace)
- CTX_DEBUG(parser->ctx, "%p: Looking up %s.%s\n", parser, namespace, name);
+ DEBUG(parser->ctx, "%p: Looking up %s.%s\n", parser, namespace, name);
else
- CTX_DEBUG(parser->ctx, "%p: Looking up %s\n", parser, name);
+ DEBUG(parser->ctx, "%p: Looking up %s\n", parser, name);
#endif /* PAKFIRE_DEBUG_PARSER */
struct pakfire_parser_declaration* d;
// Return if namespace and name match
if ((strcmp(d->namespace, namespace) == 0) && (strcmp(d->name, name) == 0)) {
#ifdef PAKFIRE_DEBUG_PARSER
- CTX_DEBUG(parser->ctx, "%p: Found result = %s\n", parser, d->value);
+ DEBUG(parser->ctx, "%p: Found result = %s\n", parser, d->value);
#endif /* PAKFIRE_DEBUG_PARSER */
return d;
}
#ifdef PAKFIRE_DEBUG_PARSER
- CTX_DEBUG(parser->ctx, "%p: Nothing found\n", parser);
+ DEBUG(parser->ctx, "%p: Nothing found\n", parser);
#endif /* PAKFIRE_DEBUG_PARSER */
return NULL;
if (flags)
d->flags = flags;
- CTX_DEBUG(parser->ctx, "%p: Updated declaration: %s.%s = %s\n",
+ DEBUG(parser->ctx, "%p: Updated declaration: %s.%s = %s\n",
parser, d->namespace, d->name, d->value);
// All done
// Import flags
d->flags = flags;
- CTX_DEBUG(parser->ctx, "%p: New declaration (%u): %s.%s %s= %s\n",
+ DEBUG(parser->ctx, "%p: New declaration (%u): %s.%s %s= %s\n",
parser,
d->flags,
d->namespace,
static int pakfire_parser_find_template(struct pakfire_parser* parser,
char* template, const size_t length, const char* namespace) {
- CTX_DEBUG(parser->ctx, "Looking up template in namespace '%s'\n", namespace);
+ DEBUG(parser->ctx, "Looking up template in namespace '%s'\n", namespace);
struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(
parser, namespace, "template");
// Fetch the value of the current declaration
const char* old_value = pakfire_parser_get_raw(parser, namespace, name);
- CTX_DEBUG(parser->ctx, "%p: Old value for %s.%s = %s\n",
+ DEBUG(parser->ctx, "%p: Old value for %s.%s = %s\n",
parser, namespace, name, old_value);
// Set the new value when there is no old one
PCRE2_UCHAR* pattern = NULL;
PCRE2_SIZE pattern_length;
- CTX_DEBUG(parser->ctx, "Searching for commands in:\n%s\n", *buffer);
+ DEBUG(parser->ctx, "Searching for commands in:\n%s\n", *buffer);
// Allocate memory for results
pcre2_match_data* match = pcre2_match_data_create_from_pattern(
// End loop when we have expanded all variables
if (r == PCRE2_ERROR_NOMATCH) {
- CTX_DEBUG(parser->ctx, "No (more) matches found\n");
+ DEBUG(parser->ctx, "No (more) matches found\n");
r = 0;
break;
}
goto ERROR;
#ifdef PAKFIRE_DEBUG_PARSER
- CTX_DEBUG(parser->ctx, "Expanding command: %s\n", command);
+ DEBUG(parser->ctx, "Expanding command: %s\n", command);
#endif /* PAKFIRE_DEBUG_PARSER */
// Update argv
r = pakfire_jail_run(parser->pakfire, argv, 0, &output, &length);
if (r) {
// Just log this and continue
- CTX_DEBUG(parser->ctx, "Command '%s' failed with return code %d\n", command, r);
+ DEBUG(parser->ctx, "Command '%s' failed with return code %d\n", command, r);
}
// Strip newline from output
// End loop when we have expanded all variables
if (r == PCRE2_ERROR_NOMATCH) {
- CTX_DEBUG(parser->ctx, "No (more) matches found in: %s\n", *buffer);
+ DEBUG(parser->ctx, "No (more) matches found in: %s\n", *buffer);
r = 0;
break;
}
goto ERROR;
#ifdef PAKFIRE_DEBUG_PARSER
- CTX_DEBUG(parser->ctx, "Expanding variable: %s\n", variable);
+ DEBUG(parser->ctx, "Expanding variable: %s\n", variable);
#endif /* PAKFIRE_DEBUG_PARSER */
// Search for a declaration of this variable
// Is this a recursive pattern?
if (repl && pakfire_string_matches(repl, (const char*)pattern)) {
- CTX_DEBUG(parser->ctx, "Recursion detected in %s\n", pattern);
+ DEBUG(parser->ctx, "Recursion detected in %s\n", pattern);
// Move up one step and lookup there
if (namespace && *namespace) {
#ifdef PAKFIRE_DEBUG_PARSER
// What is its value?
if (repl) {
- CTX_DEBUG(parser->ctx, "Replacing %%{%s} with '%s'\n", variable, repl);
+ DEBUG(parser->ctx, "Replacing %%{%s} with '%s'\n", variable, repl);
} else {
- CTX_DEBUG(parser->ctx, "Replacing %%{%s} with an empty string\n", variable);
+ DEBUG(parser->ctx, "Replacing %%{%s} with an empty string\n", variable);
}
#endif /* PAKFIRE_DEBUG_PARSER */
// Compile all regular expressions
int r = pakfire_parser_compile_regexes(parser);
if (r) {
- CTX_DEBUG(parser->ctx, "Could not compile regular expressions: %m\n");
+ DEBUG(parser->ctx, "Could not compile regular expressions: %m\n");
goto ERROR;
}
// Expand all variables
r = pakfire_parser_expand_variables(parser, namespace, &buffer);
if (r) {
- CTX_DEBUG(parser->ctx, "Failed to expand variables in '%s': %m\n", value);
+ DEBUG(parser->ctx, "Failed to expand variables in '%s': %m\n", value);
goto ERROR;
}
if (parser->flags & PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS) {
r = pakfire_parser_expand_commands(parser, &buffer);
if (r) {
- CTX_DEBUG(parser->ctx, "Failed to expand commands in '%s': %m\n", value);
+ DEBUG(parser->ctx, "Failed to expand commands in '%s': %m\n", value);
goto ERROR;
}
}
// Check for any errors
else if (r > 0) {
- CTX_ERROR(parser->ctx, "fnmatch failed: %m\n");
+ ERROR(parser->ctx, "fnmatch failed: %m\n");
if (namespaces)
free(namespaces);
char* value = NULL;
int r;
- CTX_DEBUG(parser1->ctx, "Merging parsers %p and %p\n", parser1, parser2);
+ DEBUG(parser1->ctx, "Merging parsers %p and %p\n", parser1, parser2);
if (!parser2) {
errno = EINVAL;
int pakfire_parser_read_file(struct pakfire_parser* parser, const char* path,
struct pakfire_parser_error** error) {
- CTX_DEBUG(parser->ctx, "Parsing %s...\n", path);
+ DEBUG(parser->ctx, "Parsing %s...\n", path);
FILE* f = fopen(path, "r");
if (!f)
else
parser->namespace = NULL;
- CTX_DEBUG(parser->ctx, "%p: Set namespace to: %s\n", parser, parser->namespace);
+ DEBUG(parser->ctx, "%p: Set namespace to: %s\n", parser, parser->namespace);
return 0;
}
char* deps = NULL;
char* build_arches = NULL;
- CTX_DEBUG(parser->ctx, "Building package from namespace '%s'\n", namespace);
+ DEBUG(parser->ctx, "Building package from namespace '%s'\n", namespace);
// Fetch name
name = pakfire_parser_get(parser, namespace, "name");
if (!name || !*name) {
- CTX_ERROR(parser->ctx, "Name is empty\n");
+ ERROR(parser->ctx, "Name is empty\n");
goto CLEANUP;
}
// Fetch EVR
evr = pakfire_parser_get(parser, namespace, "evr");
if (!evr || !*evr) {
- CTX_ERROR(parser->ctx, "EVR is empty\n");
+ ERROR(parser->ctx, "EVR is empty\n");
goto CLEANUP;
}
if (!arch)
goto CLEANUP;
} else {
- CTX_ERROR(parser->ctx, "Arch is empty\n");
+ ERROR(parser->ctx, "Arch is empty\n");
goto CLEANUP;
}
}
// Create a new package object
r = pakfire_package_create(pkg, parser->pakfire, repo, name, evr, arch);
if (r) {
- CTX_ERROR(parser->ctx, "Could not create package: %m\n");
+ ERROR(parser->ctx, "Could not create package: %m\n");
goto CLEANUP;
}
// Assign a new UUID to this package
char* uuid = pakfire_generate_uuid();
if (!uuid) {
- CTX_ERROR(parser->ctx, "Generating a UUID failed: %m\n");
+ ERROR(parser->ctx, "Generating a UUID failed: %m\n");
goto CLEANUP;
}
free(value);
if (r) {
- CTX_ERROR(parser->ctx, "Could not set %s: %m\n", a->name);
+ ERROR(parser->ctx, "Could not set %s: %m\n", a->name);
goto CLEANUP;
}
}
CLEANUP:
if (r)
- CTX_ERROR(parser->ctx, "Could not create package: %m\n");
+ ERROR(parser->ctx, "Could not create package: %m\n");
if (name)
free(name);
struct pakfire_parser_error** error, const char* s) {
const struct pakfire_parser_state* state = yyget_extra(scanner);
- CTX_ERROR(ctx, "Error (line %u): %s\n", state->lineno, s);
+ ERROR(ctx, "Error (line %u): %s\n", state->lineno, s);
// Create a new error object
if (error) {
int r = pakfire_parser_error_create(error, *parser, NULL, state->lineno, s);
if (r) {
- CTX_ERROR(ctx, "Could not create error object: %s\n", strerror(errno));
+ ERROR(ctx, "Could not create error object: %s\n", strerror(errno));
}
}
}
struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
#ifdef ENABLE_DEBUG
- CTX_DEBUG(ctx, "Parsing the following data (%zu):\n%.*s\n", len, (int)len, data);
+ DEBUG(ctx, "Parsing the following data (%zu):\n%.*s\n", len, (int)len, data);
// Save start time
clock_t t_start = clock();
// Log what we have in the parent parser now
dump = pakfire_parser_dump(parent);
if (dump)
- CTX_DEBUG(ctx, "Status of the parser %p:\n%s\n", parent, dump);
+ DEBUG(ctx, "Status of the parser %p:\n%s\n", parent, dump);
// Log time we needed to parse data
- CTX_DEBUG(ctx, "Parser finished in %.4fms\n",
+ DEBUG(ctx, "Parser finished in %.4fms\n",
(double)(t_end - t_start) * 1000 / CLOCKS_PER_SEC);
#endif
const char* val1, const char* val2, struct pakfire_parser* if_block, struct pakfire_parser* else_block) {
switch (op) {
case OP_EQUALS:
- CTX_DEBUG(ctx, "Evaluating if statement: %s == %s?\n", val1, val2);
+ DEBUG(ctx, "Evaluating if statement: %s == %s?\n", val1, val2);
break;
}
struct pakfire_parser* parent = pakfire_parser_get_parent(if_block);
- CTX_DEBUG(ctx, " parent = %p, if = %p, else = %p\n", parent, if_block, else_block);
+ DEBUG(ctx, " parent = %p, if = %p, else = %p\n", parent, if_block, else_block);
// Expand values
char* v1 = pakfire_parser_expand(parent, NULL, val1);
switch (op) {
case OP_EQUALS:
- CTX_DEBUG(ctx, " '%s' == '%s'?\n", v1, v2);
+ DEBUG(ctx, " '%s' == '%s'?\n", v1, v2);
if (strcmp(v1, v2) == 0)
result = if_block;
return solutions;
ERROR:
- CTX_ERROR(problem->ctx, "Could not import solutions: %s\n", strerror(r));
+ ERROR(problem->ctx, "Could not import solutions: %s\n", strerror(r));
if (solutions) {
for (struct pakfire_solution** s = solutions; *s; s++)
// Log the title
if (title)
- CTX_INFO(ctx, "%s\n", title);
+ INFO(ctx, "%s\n", title);
return 0;
}
// Stat the buffer
r = fstat(pty->stdout.fd, &buffer);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not stat the output buffer: %m\n");
+ ERROR(pty->ctx, "Could not stat the output buffer: %m\n");
return -errno;
}
- CTX_DEBUG(pty->ctx, "Read %jd byte(s) of output\n", buffer.st_size);
+ DEBUG(pty->ctx, "Read %jd byte(s) of output\n", buffer.st_size);
// Don't try to map an empty buffer
if (!buffer.st_size)
// Map the output into memory
pty->output.iov_base = mmap(NULL, buffer.st_size, PROT_READ, MAP_SHARED, pty->stdout.fd, 0);
if (pty->output.iov_base == MAP_FAILED) {
- CTX_ERROR(pty->ctx, "Could not map the output into memory: %m\n");
+ ERROR(pty->ctx, "Could not map the output into memory: %m\n");
return -errno;
}
// Stat the first file descriptor
r = fstat(fd1, &stat1);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not stat fd %d: %m\n", fd1);
+ ERROR(pty->ctx, "Could not stat fd %d: %m\n", fd1);
return -errno;
}
// Stat the second file descriptor
r = fstat(fd2, &stat2);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not stat fd %d: %m\n", fd2);
+ ERROR(pty->ctx, "Could not stat fd %d: %m\n", fd2);
return -errno;
}
// Fetch the flags
flags = fcntl(stdio->fd, F_GETFL, 0);
if (flags < 0) {
- CTX_ERROR(pty->ctx, "Could not set flags for file descriptor %d: %s\n",
+ ERROR(pty->ctx, "Could not set flags for file descriptor %d: %s\n",
stdio->fd, strerror(errno));
return -errno;
}
// Turn on non-blocking mode again
r = fcntl(stdio->fd, F_SETFL, flags & ~O_NONBLOCK);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not set flags for file descriptor %d: %s\n",
+ ERROR(pty->ctx, "Could not set flags for file descriptor %d: %s\n",
stdio->fd, strerror(errno));
return -errno;
}
if (stdio->attrs_saved) {
r = tcsetattr(stdio->fd, TCSANOW, &stdio->attrs);
if (r) {
- CTX_ERROR(pty->ctx, "Could not restore terminal attributes for %d, ignoring: %s\n",
+ ERROR(pty->ctx, "Could not restore terminal attributes for %d, ignoring: %s\n",
stdio->fd, strerror(errno));
return -errno;
}
return 0;
default:
- CTX_ERROR(pty->ctx, "Could not fetch terminal attributes from fd %d: %s\n",
+ ERROR(pty->ctx, "Could not fetch terminal attributes from fd %d: %s\n",
stdio->fd, strerror(errno));
return -errno;
// Is there anything in the input buffer?
r = ioctl(pty->master.fd, TIOCINQ, &q);
if (r < 0) {
- CTX_DEBUG(pty->ctx, "TIOCINQ failed on master fd %d: %m\n", pty->master.fd);
+ DEBUG(pty->ctx, "TIOCINQ failed on master fd %d: %m\n", pty->master.fd);
return -errno;
}
// Is there anything in the output buffer?
r = ioctl(pty->master.fd, TIOCOUTQ, &q);
if (r < 0) {
- CTX_DEBUG(pty->ctx, "TIOCOUTQ failed on master fd %d: %m\n", pty->master.fd);
+ DEBUG(pty->ctx, "TIOCOUTQ failed on master fd %d: %m\n", pty->master.fd);
return -errno;
}
if (pakfire_pty_has_flag(pty, PAKFIRE_PTY_CAPTURE_OUTPUT)) {
r = pakfire_pty_store_output(pty);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not store output: %s\n", strerror(-r));
+ ERROR(pty->ctx, "Could not store output: %s\n", strerror(-r));
return r;
}
}
// Send EOF (Ctrl-D)
r = write(fd, &eof, sizeof(eof));
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not write EOF: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Could not write EOF: %s\n", strerror(errno));
return -errno;
}
if (!pakfire_pty_buffer_is_full(pty, stdio))
return -ENOMSG;
- CTX_DEBUG(pty->ctx, "Buffer is full. Sending all content\n");
+ DEBUG(pty->ctx, "Buffer is full. Sending all content\n");
eol = stdio->buffer + stdio->buffered - 1;
}
((pty->master.io & PAKFIRE_PTY_READY_TO_READ) && !pakfire_pty_buffer_is_full(pty, &pty->stdout)) ||
((pty->stdout.io & PAKFIRE_PTY_READY_TO_WRITE) && pakfire_pty_buffer_has_data(pty, &pty->stdout))
) {
- // CTX_DEBUG(pty->ctx, "PTY forward stdin=%x %zu, stdout=%x %zu, %x\n",
+ // DEBUG(pty->ctx, "PTY forward stdin=%x %zu, stdout=%x %zu, %x\n",
// pty->stdin.io, pty->stdin.buffered, pty->stdout.io, pty->stdout.buffered, pty->master.io);
// Read from standard input
break;
default:
- CTX_ERROR(pty->ctx, "Failed reading from standard input: %s\n",
+ ERROR(pty->ctx, "Failed reading from standard input: %s\n",
strerror(-r));
goto ERROR;
}
// EOF?
} else if (r == 0) {
- CTX_DEBUG(pty->ctx, "Received EOF from standard input\n");
+ DEBUG(pty->ctx, "Received EOF from standard input\n");
// We are done reading
pty->stdin.io &= ~PAKFIRE_PTY_READY_TO_READ;
break;
default:
- CTX_ERROR(pty->ctx, "Failed writing to the PTY: %s\n", strerror(-r));
+ ERROR(pty->ctx, "Failed writing to the PTY: %s\n", strerror(-r));
goto ERROR;
}
}
break;
default:
- CTX_ERROR(pty->ctx, "Failed reading from the PTY: %s\n", strerror(-r));
+ ERROR(pty->ctx, "Failed reading from the PTY: %s\n", strerror(-r));
goto ERROR;
}
}
return 0;
default:
- CTX_ERROR(pty->ctx, "Failed writing to standard output: %s\n", strerror(-r));
+ ERROR(pty->ctx, "Failed writing to standard output: %s\n", strerror(-r));
goto ERROR;
}
}
int same;
int r;
- CTX_DEBUG(pty->ctx, "Enabling raw mode\n");
+ DEBUG(pty->ctx, "Enabling raw mode\n");
r = pakfire_pty_same_inode(pty, pty->stdin.fd, pty->stdout.fd);
if (r < 0)
// Restore the attributes
r = tcsetattr(pty->stdin.fd, TCSANOW, &raw_attrs);
if (r) {
- CTX_ERROR(pty->ctx, "Could not restore terminal attributes for fd %d: %s\n",
+ ERROR(pty->ctx, "Could not restore terminal attributes for fd %d: %s\n",
pty->stdin.fd, strerror(errno));
return -errno;
}
// Restore the attributes
r = tcsetattr(pty->stdout.fd, TCSANOW, &raw_attrs);
if (r) {
- CTX_ERROR(pty->ctx, "Could not restore terminal attributes for fd %d: %s\n",
+ ERROR(pty->ctx, "Could not restore terminal attributes for fd %d: %s\n",
pty->stdout.fd, strerror(errno));
return -errno;
}
if (fd < 0)
return fd;
- CTX_DEBUG(pty->ctx, "Re-opened %s as fd %d\n", path, fd);
+ DEBUG(pty->ctx, "Re-opened %s as fd %d\n", path, fd);
// Try to re-apply the offset to the new file descriptor
if (offset > 0) {
r = lseek(fd, offset, SEEK_SET);
if (r < 0)
- CTX_DEBUG(pty->ctx, "Failed to apply offset: %m\n");
+ DEBUG(pty->ctx, "Failed to apply offset: %m\n");
}
return fd;
struct winsize size;
int r;
- CTX_DEBUG(pty->ctx, "Setting up PTY Forwarding...\n");
+ DEBUG(pty->ctx, "Setting up PTY Forwarding...\n");
// Mark as forwarding
pty->state = PAKFIRE_PTY_STATE_FORWARDING;
if (pty->flags & PAKFIRE_PTY_CONNECT_STDIN) {
pty->stdin.fd = pakfire_pty_reopen(pty, STDIN_FILENO, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (pty->stdin.fd < 0) {
- CTX_DEBUG(pty->ctx, "Could not re-open standard input: %s. Ignoring.\n", strerror(-pty->stdin.fd));
+ DEBUG(pty->ctx, "Could not re-open standard input: %s. Ignoring.\n", strerror(-pty->stdin.fd));
// Use the original file descriptor
pty->stdin.fd = STDIN_FILENO;
if (pakfire_pty_has_flag(pty, PAKFIRE_PTY_CAPTURE_OUTPUT)) {
pty->stdout.fd = memfd_create("pty-output", MFD_CLOEXEC);
if (pty->stdout.fd < 0) {
- CTX_ERROR(pty->ctx, "Could not create the output buffer: %m\n");
+ ERROR(pty->ctx, "Could not create the output buffer: %m\n");
return -errno;
}
} else if (pty->flags & PAKFIRE_PTY_CONNECT_STDOUT) {
pty->stdout.fd = pakfire_pty_reopen(pty, STDOUT_FILENO, O_WRONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (pty->stdout.fd < 0) {
- CTX_DEBUG(pty->ctx, "Could not re-open standard output: %s. Ignoring.\n", strerror(-pty->stdout.fd));
+ DEBUG(pty->ctx, "Could not re-open standard output: %s. Ignoring.\n", strerror(-pty->stdout.fd));
// Use the original file descriptor
pty->stdout.fd = STDOUT_FILENO;
// Fetch dimensions
r = ioctl(pty->stdout.fd, TIOCGWINSZ, &size);
if (r) {
- CTX_ERROR(pty->ctx, "Failed to determine terminal dimensions: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Failed to determine terminal dimensions: %s\n", strerror(errno));
return -errno;
}
// Set dimensions
r = ioctl(pty->master.fd, TIOCSWINSZ, &size);
if (r) {
- CTX_ERROR(pty->ctx, "Failed setting dimensions: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Failed setting dimensions: %s\n", strerror(errno));
return -errno;
}
}
break;
default:
- CTX_ERROR(pty->ctx,
+ ERROR(pty->ctx,
"Could not add standard output to the event loop: %s\n", strerror(-r));
return r;
}
char buffer[CMSG_SPACE(payload_length)];
int r;
- CTX_DEBUG(pty->ctx, "Sending fd %d to parent\n", pty->master.fd);
+ DEBUG(pty->ctx, "Sending fd %d to parent\n", pty->master.fd);
// Header
struct msghdr msg = {
// Send the message
r = sendmsg(pty->socket[1], &msg, 0);
if (r) {
- CTX_ERROR(pty->ctx, "Could not send file descriptor: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Could not send file descriptor: %s\n", strerror(errno));
return -errno;
}
// Receive the message
r = recvmsg(pty->socket[0], &msg, 0);
if (r) {
- CTX_ERROR(pty->ctx, "Could not receive file descriptor: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Could not receive file descriptor: %s\n", strerror(errno));
return -errno;
}
// Store the file descriptor
pty->master.fd = *((int*)CMSG_DATA(cmsg));
- CTX_DEBUG(pty->ctx, "Received fd %d from socket %d\n", pty->master.fd, pty->socket[0]);
+ DEBUG(pty->ctx, "Received fd %d from socket %d\n", pty->master.fd, pty->socket[0]);
// We can close the socket now
close(pty->socket[0]);
r = sd_event_add_io(pty->loop, &pty->master.event,
pty->master.fd, EPOLLIN|EPOLLOUT|EPOLLET, pakfire_pty_master, pty);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not add the master file descriptor: %s\n", strerror(-r));
+ ERROR(pty->ctx, "Could not add the master file descriptor: %s\n", strerror(-r));
return r;
}
// Create a UNIX domain socket
r = socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, p->socket);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not create a UNIX socket: %m\n");
+ ERROR(p->ctx, "Could not create a UNIX socket: %m\n");
r = -errno;
goto ERROR;
}
r = sd_event_add_io(p->loop, NULL, p->socket[0], EPOLLIN|EPOLLHUP,
pakfire_pty_setup, p);
if (r < 0) {
- CTX_ERROR(p->ctx, "Could not listen to socket: %s\n", strerror(-r));
+ ERROR(p->ctx, "Could not listen to socket: %s\n", strerror(-r));
r = -errno;
goto ERROR;
}
// Open a new terminal
fd = open("/dev/console", O_RDWR|O_NOCTTY);
if (fd < 0) {
- CTX_ERROR(pty->ctx, "Failed to open a new terminal: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Failed to open a new terminal: %s\n", strerror(errno));
return -errno;
}
- CTX_DEBUG(pty->ctx, "Opened a new terminal %d\n", fd);
+ DEBUG(pty->ctx, "Opened a new terminal %d\n", fd);
// Connect the new terminal to standard input
r = dup2(fd, STDIN_FILENO);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Failed to open standard input: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Failed to open standard input: %s\n", strerror(errno));
return -errno;
}
// Connect the new terminal to standard output
r = dup2(fd, STDOUT_FILENO);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Failed to open standard output: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Failed to open standard output: %s\n", strerror(errno));
return -errno;
}
// Connect the new terminal to standard error
r = dup2(fd, STDERR_FILENO);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Failed to open standard error: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Failed to open standard error: %s\n", strerror(errno));
return -errno;
}
if (r)
return -r;
- CTX_DEBUG(pty->ctx, "Allocated console at %s (%d)\n", pty->path, pty->master.fd);
+ DEBUG(pty->ctx, "Allocated console at %s (%d)\n", pty->path, pty->master.fd);
// Unlock the master device
r = unlockpt(pty->master.fd);
if (r) {
- CTX_ERROR(pty->ctx, "Could not unlock the PTY: %s\n", strerror(errno));
+ ERROR(pty->ctx, "Could not unlock the PTY: %s\n", strerror(errno));
return -errno;
}
r = sd_event_add_signal(pty->loop, &pty->sigwinch_event,
SIGWINCH|SD_EVENT_SIGNAL_PROCMASK, pakfire_pty_SIGWINCH, pty);
if (r < 0) {
- CTX_ERROR(pty->ctx, "Could not register SIGWINCH: %s\n", strerror(-r));
+ ERROR(pty->ctx, "Could not register SIGWINCH: %s\n", strerror(-r));
return r;
}
r = subid_init(PACKAGE_NAME, stderr);
if (r) {
- CTX_ERROR(ctx, "Could not setup subid: %m\n");
+ ERROR(ctx, "Could not setup subid: %m\n");
goto ERROR;
}
count = callback(owner, &ranges);
if (count < 0) {
- CTX_ERROR(ctx, "Could not fetch subids for %s: %m\n", owner);
+ ERROR(ctx, "Could not fetch subids for %s: %m\n", owner);
goto ERROR;
}
// Check if length is greater than zero
if (subid->length == 0) {
- CTX_DEBUG(ctx, "Length equals zero: %s\n", line);
+ DEBUG(ctx, "Length equals zero: %s\n", line);
r = 1;
goto ERROR;
}
free(line);
if (!r)
- CTX_DEBUG(ctx, "Parsed SUBID entry: name=%s, id=%u, length=%zu\n",
+ DEBUG(ctx, "Parsed SUBID entry: name=%s, id=%u, length=%zu\n",
subid->name, subid->id, subid->length);
if (ctx)
struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
- CTX_DEBUG(ctx, "Fetching SUBID from %s for %s\n", path, owner);
+ DEBUG(ctx, "Fetching SUBID from %s for %s\n", path, owner);
// Open /etc/subuid
FILE* f = fopen(path, "r");
break;
default:
- CTX_ERROR(ctx, "Could not open %s: %m\n", path);
+ ERROR(ctx, "Could not open %s: %m\n", path);
break;
}
}
// No match found
- CTX_DEBUG(ctx, "No match found for %s\n", owner);
+ DEBUG(ctx, "No match found for %s\n", owner);
r = 1;
END:
#ifdef ENABLE_DEBUG
if (strcmp(url, buffer) != 0) {
- CTX_DEBUG(repo->ctx, "Repository URL updated:");
- CTX_DEBUG(repo->ctx, " From: %s\n", url);
- CTX_DEBUG(repo->ctx, " To : %s\n", buffer);
+ DEBUG(repo->ctx, "Repository URL updated:");
+ DEBUG(repo->ctx, " From: %s\n", url);
+ DEBUG(repo->ctx, " To : %s\n", buffer);
}
#endif
// Import the key
r = pakfire_key_import_from_string(&repo->key, repo->ctx, data, strlen(data));
if (r < 0) {
- CTX_ERROR(repo->ctx, "Could not import key for repository '%s': %s\n",
+ ERROR(repo->ctx, "Could not import key for repository '%s': %s\n",
pakfire_repo_get_name(repo), strerror(-r));
goto ERROR;
}
// If the key could be successfully imported, we will store it in the appdata
r = pakfire_string_set(repo->appdata->key, data);
if (r < 0) {
- CTX_ERROR(repo->ctx, "Could not copy the key to appdata: %s\n", strerror(-r));
+ ERROR(repo->ctx, "Could not copy the key to appdata: %s\n", strerror(-r));
goto ERROR;
}
// Fetch context
struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
- CTX_DEBUG(ctx, "Creating repository %s\n", name);
+ DEBUG(ctx, "Creating repository %s\n", name);
// Create a new repository
r = pakfire_repo_create(&repo, pakfire, name);
if (r) {
- CTX_ERROR(ctx, "Could not create repository '%s': %m\n", name);
+ ERROR(ctx, "Could not create repository '%s': %m\n", name);
goto ERROR;
}
int r = pakfire_mirrorlist_create(&repo->mirrorlist, repo->ctx);
if (r < 0) {
- CTX_ERROR(repo->ctx, "Could not create mirrorlist: %s\n", strerror(-r));
+ ERROR(repo->ctx, "Could not create mirrorlist: %s\n", strerror(-r));
return NULL;
}
// Read the mirrorlist
r = pakfire_mirrorlist_read(repo->mirrorlist, repo->appdata->mirrorlist);
if (r < 0) {
- CTX_ERROR(repo->ctx, "Could not read mirrorlist %s: %s\n",
+ ERROR(repo->ctx, "Could not read mirrorlist %s: %s\n",
repo->appdata->mirrorlist, strerror(-r));
// Destroy what we have created
// Do nothing if the file already exists
if (pakfire_path_exists(path)) {
- CTX_DEBUG(repo->ctx, "Database %s already present. Skipping download\n", filename);
+ DEBUG(repo->ctx, "Database %s already present. Skipping download\n", filename);
return 0;
}
FILE* f = NULL;
int r;
- CTX_DEBUG(repo->ctx, "Read package database from %s...\n", path);
+ DEBUG(repo->ctx, "Read package database from %s...\n", path);
// Open the database file
f = fopen(path, "r");
if (!f) {
- CTX_ERROR(repo->ctx, "Could not open package database at %s: %m\n", path);
+ ERROR(repo->ctx, "Could not open package database at %s: %m\n", path);
r = 1;
goto ERROR;
}
char database_path[PATH_MAX];
int r;
- CTX_DEBUG(repo->ctx, "Reading repository metadata from %s...\n", path);
+ DEBUG(repo->ctx, "Reading repository metadata from %s...\n", path);
struct json_object* json = pakfire_json_parse_from_file(repo->ctx, path);
if (!json) {
case ENOENT:
// If the repository is local, we will just scan it
if (pakfire_repo_is_local(repo)) {
- CTX_DEBUG(repo->ctx, "No metadata available on local repository."
+ DEBUG(repo->ctx, "No metadata available on local repository."
" Falling back to scan...\n");
return pakfire_repo_scan(repo, 0);
break;
}
- CTX_ERROR(repo->ctx, "Could not parse metadata from %s: %m\n", path);
+ ERROR(repo->ctx, "Could not parse metadata from %s: %m\n", path);
return 1;
}
// Search for the database name
int found = json_object_object_get_ex(json, "database", &database);
if (!found) {
- CTX_ERROR(repo->ctx, "Could not read database name from metadata\n");
+ ERROR(repo->ctx, "Could not read database name from metadata\n");
r = 1;
goto ERROR;
}
time_t age = pakfire_path_age(repo->appdata->mirrorlist);
if (age > 0 && age < REFRESH_AGE_MIRRORLIST) {
- CTX_DEBUG(repo->ctx, "Skip refreshing mirrorlist which is %lds old\n", age);
+ DEBUG(repo->ctx, "Skip refreshing mirrorlist which is %lds old\n", age);
return 0;
}
}
// Replace any variables in the URL
url = pakfire_repo_url_replace(repo, repo->appdata->mirrorlist_url);
if (!url) {
- CTX_ERROR(repo->ctx, "Could not expend the mirror list URL: %m\n");
+ ERROR(repo->ctx, "Could not expend the mirror list URL: %m\n");
r = -errno;
goto ERROR;
}
time_t age = pakfire_path_age(path);
if (age > 0 && age < refresh) {
- CTX_DEBUG(repo->ctx, "Skip refreshing metadata which is %lds old\n", age);
+ DEBUG(repo->ctx, "Skip refreshing metadata which is %lds old\n", age);
return 0;
}
}
// Allocate a libsolv repository
rep->repo = repo_create(pool, name);
if (!rep->repo) {
- CTX_ERROR(rep->ctx, "Could not allocate repo: %m\n");
+ ERROR(rep->ctx, "Could not allocate repo: %m\n");
goto ERROR;
}
// Allocate repository appdata
rep->appdata = rep->repo->appdata = pakfire_repo_setup_appdata(rep);
if (!rep->appdata) {
- CTX_ERROR(rep->ctx, "Could not setup repository appdata for %s\n", name);
+ ERROR(rep->ctx, "Could not setup repository appdata for %s\n", name);
goto ERROR;
}
if (description) {
r = pakfire_config_set(config, section, "description", description);
if (r) {
- CTX_ERROR(repo->ctx, "Could not set description: %m\n");
+ ERROR(repo->ctx, "Could not set description: %m\n");
goto ERROR;
}
}
if (!pakfire_repo_get_enabled(repo)) {
r = pakfire_config_set(config, section, "enabled", "0");
if (r) {
- CTX_ERROR(repo->ctx, "Could not set enabled: %m\n");
+ ERROR(repo->ctx, "Could not set enabled: %m\n");
goto ERROR;
}
}
if (baseurl) {
r = pakfire_config_set(config, section, "baseurl", baseurl);
if (r) {
- CTX_ERROR(repo->ctx, "Could not set base URL: %m\n");
+ ERROR(repo->ctx, "Could not set base URL: %m\n");
goto ERROR;
}
}
free(refresh);
if (r) {
- CTX_ERROR(repo->ctx, "Could not set refresh interval: %m\n");
+ ERROR(repo->ctx, "Could not set refresh interval: %m\n");
goto ERROR;
}
}
if (mirrorlist) {
r = pakfire_config_set(config, section, "mirrors", mirrorlist);
if (r) {
- CTX_ERROR(repo->ctx, "Could not set mirrors: %m\n");
+ ERROR(repo->ctx, "Could not set mirrors: %m\n");
goto ERROR;
}
}
if (key) {
r = pakfire_key_export(key, f, PAKFIRE_KEY_EXPORT_MODE_PUBLIC);
if (r) {
- CTX_ERROR(repo->ctx, "Could not export the key: %m\n");
+ ERROR(repo->ctx, "Could not export the key: %m\n");
goto ERROR;
}
if (buffer) {
r = pakfire_config_set_format(config, section, "key", "%.*s", (int)length, buffer);
if (r) {
- CTX_ERROR(repo->ctx, "Could not set key: %m\n");
+ ERROR(repo->ctx, "Could not set key: %m\n");
goto ERROR;
}
}
if (priority) {
r = pakfire_config_set_format(config, section, "priority", "%u", priority);
if (r) {
- CTX_ERROR(repo->ctx, "Could not set priority: %m\n");
+ ERROR(repo->ctx, "Could not set priority: %m\n");
goto ERROR;
}
}
// Where do we store the package?
cache_path = pakfire_package_get_string(pkg, PAKFIRE_PKG_CACHE_PATH);
if (!cache_path) {
- CTX_ERROR(repo->ctx, "Could not retrieve package cache path for %s: %m\n", nevra);
+ ERROR(repo->ctx, "Could not retrieve package cache path for %s: %m\n", nevra);
goto ERROR;
}
// Where do we find the package on the server?
url = pakfire_package_get_string(pkg, PAKFIRE_PKG_PATH);
if (!url) {
- CTX_ERROR(repo->ctx, "Could not retrieve package path for %s: %m\n", nevra);
+ ERROR(repo->ctx, "Could not retrieve package path for %s: %m\n", nevra);
goto ERROR;
}
// Retrieve package digest
digest = pakfire_package_get_digest(pkg, &digest_type, &digest_length);
if (!digest) {
- CTX_ERROR(repo->ctx, "Package %s has no digest set: %m\n", nevra);
+ ERROR(repo->ctx, "Package %s has no digest set: %m\n", nevra);
goto ERROR;
}
if (pakfire_string_is_url(path)) {
r = pakfire_repo_download(repo, path, package);
if (r)
- CTX_ERROR(repo->ctx, "Could not download %s\n", path);
+ ERROR(repo->ctx, "Could not download %s\n", path);
return r;
}
goto ERROR;
}
- CTX_DEBUG(repo->ctx, "Added %s to repository '%s'\n",
+ DEBUG(repo->ctx, "Added %s to repository '%s'\n",
nevra, pakfire_repo_get_name(repo));
ERROR:
// Create another repodata section for meta information
meta = repo_add_repodata(repo->repo, 0);
if (!meta) {
- CTX_ERROR(repo->ctx, "Could not create meta repodata: %m\n");
+ ERROR(repo->ctx, "Could not create meta repodata: %m\n");
r = -errno;
goto ERROR;
}
// Flush buffers
r = fflush(f);
if (r) {
- CTX_ERROR(repo->ctx, "Could not flush after writing repository: %m\n");
+ ERROR(repo->ctx, "Could not flush after writing repository: %m\n");
goto ERROR;
}
if (prefix && !pakfire_string_startswith(path, prefix))
goto NEXT;
- CTX_DEBUG(repo->ctx, "Removing %s at %s\n", nevra, path);
+ DEBUG(repo->ctx, "Removing %s at %s\n", nevra, path);
// Delete the file
r = unlink(path);
if (r) {
- CTX_ERROR(repo->ctx, "Could not unlink %s at %s: %m\n", nevra, path);
+ ERROR(repo->ctx, "Could not unlink %s at %s: %m\n", nevra, path);
}
NEXT:
struct pakfire_package* package = NULL;
int r;
- CTX_DEBUG(repo->ctx, "Scanning %s...\n", path);
+ DEBUG(repo->ctx, "Scanning %s...\n", path);
// Open archive
r = pakfire_archive_open(&archive, repo->pakfire, path);
// Do nothing if this repository is not enabled
int enabled = pakfire_repo_get_enabled(repo);
if (!enabled) {
- CTX_DEBUG(repo->ctx, "Skip refreshing repository '%s'\n", name);
+ DEBUG(repo->ctx, "Skip refreshing repository '%s'\n", name);
return 0;
}
// Refresh mirrorlist
r = pakfire_repo_refresh_mirrorlist(repo, force);
if (r) {
- CTX_ERROR(repo->ctx, "Could not refresh mirrorlist, but will continue anyways...\n");
+ ERROR(repo->ctx, "Could not refresh mirrorlist, but will continue anyways...\n");
}
// Refresh metadata
// Open the signature file for writing
s = fopen(signature_path, "w");
if (!s) {
- CTX_ERROR(repo->ctx, "Could not open %s for writing: %m\n", signature_path);
+ ERROR(repo->ctx, "Could not open %s for writing: %m\n", signature_path);
r = 1;
goto ERROR;
}
// Open the database for reading
f = fopen(database_path, "r");
if (!f) {
- CTX_ERROR(repo->ctx, "Could not open %s for reading: %m\n", database_path);
+ ERROR(repo->ctx, "Could not open %s for reading: %m\n", database_path);
r = 1;
goto ERROR;
}
// Create the signature
r = pakfire_key_signf(key, s, f, "Database Signature");
if (r) {
- CTX_ERROR(repo->ctx, "Could not sign the database: %m\n");
+ ERROR(repo->ctx, "Could not sign the database: %m\n");
goto ERROR;
}
// Create a temporary file to write to
FILE* f = pakfire_mktemp(tmp, 0644);
if (!f) {
- CTX_ERROR(repo->ctx, "Could not open temporary file for writing: %m\n");
+ ERROR(repo->ctx, "Could not open temporary file for writing: %m\n");
return 1;
}
// Initialize the output being compressed
f = pakfire_zstdfopen(f, "w");
if (!f) {
- CTX_ERROR(repo->ctx, "Could not initialize compression: %m\n");
+ ERROR(repo->ctx, "Could not initialize compression: %m\n");
return 1;
}
// Write the SOLV database to the temporary file
r = pakfire_repo_write_solv(repo, f, 0);
if (r) {
- CTX_ERROR(repo->ctx, "Could not write SOLV data: %m\n");
+ ERROR(repo->ctx, "Could not write SOLV data: %m\n");
goto ERROR;
}
// Create a filename for the database file
r = __pakfire_strftime_now(filename, length, "%Y-%m-%d-%H%M.%s.solv.zst");
if (r) {
- CTX_ERROR(repo->ctx, "Could not format database filename: %m\n");
+ ERROR(repo->ctx, "Could not format database filename: %m\n");
goto ERROR;
}
// Make final database path
r = pakfire_string_format(database, "%s/repodata/%s", path, filename);
if (r) {
- CTX_ERROR(repo->ctx, "Could not join database path: %m\n");
+ ERROR(repo->ctx, "Could not join database path: %m\n");
goto ERROR;
}
// Link database to its destination
r = link(tmp, database);
if (r) {
- CTX_ERROR(repo->ctx, "Could not link database %s: %m\n", database);
+ ERROR(repo->ctx, "Could not link database %s: %m\n", database);
goto ERROR;
}
if (key) {
r = pakfire_repo_sign_database(repo, key, database);
if (r) {
- CTX_ERROR(repo->ctx, "Could not sign the database: %m\n");
+ ERROR(repo->ctx, "Could not sign the database: %m\n");
goto ERROR;
}
}
// Compose JSON object
repomd = json_object_new_object();
if (!repomd) {
- CTX_ERROR(repo->ctx, "Could not allocate a new JSON object: %m\n");
+ ERROR(repo->ctx, "Could not allocate a new JSON object: %m\n");
r = 1;
goto ERROR;
}
// Set version
struct json_object* repomd_version = json_object_new_int64(0);
if (!repomd_version) {
- CTX_ERROR(repo->ctx, "Could not create version: %m\n");
+ ERROR(repo->ctx, "Could not create version: %m\n");
r = 1;
goto ERROR;
}
r = json_object_object_add(repomd, "version", repomd_version);
if (r) {
- CTX_ERROR(repo->ctx, "Could not add version to repomd.json: %m\n");
+ ERROR(repo->ctx, "Could not add version to repomd.json: %m\n");
goto ERROR;
}
// Set revision
struct json_object* repomd_revision = json_object_new_int64(revision);
if (!repomd_revision) {
- CTX_ERROR(repo->ctx, "Could not create revision: %m\n");
+ ERROR(repo->ctx, "Could not create revision: %m\n");
r = 1;
goto ERROR;
}
r = json_object_object_add(repomd, "revision", repomd_revision);
if (r) {
- CTX_ERROR(repo->ctx, "Could not add revision to repomd.json: %m\n");
+ ERROR(repo->ctx, "Could not add revision to repomd.json: %m\n");
goto ERROR;
}
// Set database
struct json_object* repomd_database = json_object_new_string(database);
if (!repomd_database) {
- CTX_ERROR(repo->ctx, "Could not create database string: %m\n");
+ ERROR(repo->ctx, "Could not create database string: %m\n");
r = 1;
goto ERROR;
}
r = json_object_object_add(repomd, "database", repomd_database);
if (r) {
- CTX_ERROR(repo->ctx, "Could not add database to repomd.json: %m\n");
+ ERROR(repo->ctx, "Could not add database to repomd.json: %m\n");
goto ERROR;
}
// Open repomd.json for writing
f = fopen(repomd_path, "w");
if (!f) {
- CTX_ERROR(repo->ctx, "Could not open %s for writing: %m\n", repomd_path);
+ ERROR(repo->ctx, "Could not open %s for writing: %m\n", repomd_path);
r = 1;
goto ERROR;
}
// Write out repomd.json
r = json_object_to_fd(fileno(f), repomd, JSON_C_TO_STRING_PRETTY);
if (r) {
- CTX_ERROR(repo->ctx, "Could not write repomd.json: %m\n");
+ ERROR(repo->ctx, "Could not write repomd.json: %m\n");
goto ERROR;
}
// Create a new temporary repository at path
r = pakfire_repo_create(&repo, pakfire, "tmp");
if (r) {
- CTX_ERROR(ctx, "Could not create a temporary repository: %m\n");
+ ERROR(ctx, "Could not create a temporary repository: %m\n");
goto ERROR;
}
// Set baseurl to path
r = pakfire_repo_set_baseurl(repo, baseurl);
if (r) {
- CTX_ERROR(ctx, "Could not set baseurl %s: %m\n", baseurl);
+ ERROR(ctx, "Could not set baseurl %s: %m\n", baseurl);
goto ERROR;
}
// Find everything that is already part of the repository
r = pakfire_repo_scan(repo, 0);
if (r) {
- CTX_ERROR(ctx, "Could not refresh repository: %m\n");
+ ERROR(ctx, "Could not refresh repository: %m\n");
goto ERROR;
}
char destination_path[PATH_MAX];
char repo_path[PATH_MAX];
- CTX_DEBUG(ctx, "Adding %zu file(s) to the repository\n", num_files);
+ DEBUG(ctx, "Adding %zu file(s) to the repository\n", num_files);
// Add more files
if (files) {
for (const char** file = files; *file; file++) {
- CTX_DEBUG(ctx, "Adding %s to repository...\n", *file);
+ DEBUG(ctx, "Adding %s to repository...\n", *file);
// Open source archive
r = pakfire_archive_open(&archive, pakfire, *file);
if (r) {
- CTX_ERROR(ctx, "Could not open %s: %m\n", *file);
+ ERROR(ctx, "Could not open %s: %m\n", *file);
goto OUT;
}
// Add package metadata
r = pakfire_repo_add_archive(repo, archive, &package);
if (r) {
- CTX_ERROR(ctx, "Could not add %s to the repository: %m\n", *file);
+ ERROR(ctx, "Could not add %s to the repository: %m\n", *file);
goto OUT;
}
// Fetch the UUID
uuid = pakfire_package_get_string(package, PAKFIRE_PKG_UUID);
if (!uuid) {
- CTX_ERROR(ctx, "Could not retrieve the UUID of %s: %m\n", *file);
+ ERROR(ctx, "Could not retrieve the UUID of %s: %m\n", *file);
r = -EINVAL;
goto OUT;
}
// Fetch the filename
filename = pakfire_package_get_string(package, PAKFIRE_PKG_FILENAME);
if (!filename) {
- CTX_ERROR(ctx, "Could not retrieve filename of %s: %m\n", *file);
+ ERROR(ctx, "Could not retrieve filename of %s: %m\n", *file);
r = -EINVAL;
goto OUT;
}
// Copying archive to destination
r = pakfire_archive_link_or_copy(archive, destination_path);
if (r) {
- CTX_ERROR(ctx, "Could not copy archive to %s: %m\n", destination_path);
+ ERROR(ctx, "Could not copy archive to %s: %m\n", destination_path);
goto OUT;
}
if (pakfire_scriptlet_is_shell_script(scriptlet))
return pakfire_jail_run_script(pakfire, scriptlet->data, scriptlet->size, NULL, 0);
- CTX_ERROR(scriptlet->ctx, "Scriptlet is of an unknown kind\n");
+ ERROR(scriptlet->ctx, "Scriptlet is of an unknown kind\n");
return -ENOTSUP;
}
// Lock the snapshot
r = flock(s->fd, LOCK_SH);
if (r < 0) {
- CTX_ERROR(s->ctx, "Could not lock %s: %m\n", s->path);
+ ERROR(s->ctx, "Could not lock %s: %m\n", s->path);
r = -errno;
goto ERROR;
}
// List what we have found
for (int i = 0; i < num_paths; i++) {
- CTX_DEBUG(ctx, "Found snapshot: %s\n", paths[i]->d_name);
+ DEBUG(ctx, "Found snapshot: %s\n", paths[i]->d_name);
}
// Build the path to the snapshot
if (r < 0)
goto ERROR;
- CTX_DEBUG(ctx, "Selecting snapshot %s\n", path);
+ DEBUG(ctx, "Selecting snapshot %s\n", path);
// Open the snapshot
r = pakfire_snapshot_create(snapshot, ctx, path);
int fsfd = -EBADF;
int r;
- CTX_DEBUG(snapshot->ctx, "Mounting snapshot %s to %s\n", snapshot->path, path);
+ DEBUG(snapshot->ctx, "Mounting snapshot %s to %s\n", snapshot->path, path);
// Mount the tmpfs
r = pakfire_snapshot_mount_tmpfs(snapshot);
// Check if the snapshot is mounted
switch (snapshot->state) {
case PAKFIRE_SNAPSHOT_MOUNTED:
- CTX_DEBUG(snapshot->ctx, "Snapshot is mounted\n");
+ DEBUG(snapshot->ctx, "Snapshot is mounted\n");
return -EBUSY;
default:
if (r < 0) {
switch (errno) {
case EWOULDBLOCK:
- CTX_DEBUG(snapshot->ctx, "Snapshot %s is used elsewhere\n", snapshot->path);
+ DEBUG(snapshot->ctx, "Snapshot %s is used elsewhere\n", snapshot->path);
return -EBUSY;
default:
- CTX_DEBUG(snapshot->ctx,
+ DEBUG(snapshot->ctx,
"Could not acquire an exclusive lock on %s: %m\n", snapshot->path);
break;
}
}
- CTX_INFO(snapshot->ctx, "Destroying snapshot %s\n", snapshot->path);
+ INFO(snapshot->ctx, "Destroying snapshot %s\n", snapshot->path);
// Remove all files
r = pakfire_rmtree(snapshot->path, 0);
if (r < 0) {
- CTX_ERROR(snapshot->ctx, "Could not destroy snapshot %s: %s\n",
+ ERROR(snapshot->ctx, "Could not destroy snapshot %s: %s\n",
snapshot->path, strerror(-r));
return r;
}
// Clone the Pakfire instance
r = pakfire_clone(&p, pakfire, tmp);
if (r < 0) {
- CTX_ERROR(ctx, "Could not clone pakfire: %s\n", strerror(-r));
+ ERROR(ctx, "Could not clone pakfire: %s\n", strerror(-r));
goto ERROR;
}
// Move the snapshot to its final place
r = rename(tmp, snapshot_path);
if (r < 0) {
- CTX_ERROR(ctx, "Could not move the snapshot to %s: %m\n", snapshot_path);
+ ERROR(ctx, "Could not move the snapshot to %s: %m\n", snapshot_path);
r = -errno;
goto ERROR;
}
struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
- CTX_DEBUG(ctx, "Cleaning up snapshots...\n");
+ DEBUG(ctx, "Cleaning up snapshots...\n");
// Make the path
r = pakfire_cache_path(pakfire, path, "%s", "snapshots");
goto ERROR;
default:
- CTX_ERROR(ctx, "Could not initialize DWARF context: %s\n", dwarf_errmsg(-1));
+ ERROR(ctx, "Could not initialize DWARF context: %s\n", dwarf_errmsg(-1));
r = -errno;
goto ERROR;
}
// Fetch the source files
r = dwarf_getsrcfiles(die, &files, &count);
if (r < 0) {
- CTX_ERROR(ctx, "Could not fetch the source files: %s\n", dwarf_errmsg(-1));
+ ERROR(ctx, "Could not fetch the source files: %s\n", dwarf_errmsg(-1));
r = -errno;
goto ERROR;
}
if (pakfire_string_startswith(basename, "<") && pakfire_string_endswith(basename, ">"))
continue;
- CTX_DEBUG(ctx, "Found source file: %s\n", filename);
+ DEBUG(ctx, "Found source file: %s\n", filename);
// Copy the file
r = pakfire_stripper_copy_source_file(stripper, filename);
if (r < 0) {
- CTX_ERROR(ctx, "Could not copy source file %s: %s\n", filename, strerror(-r));
+ ERROR(ctx, "Could not copy source file %s: %s\n", filename, strerror(-r));
goto ERROR;
}
}
return PAKFIRE_STEP_DOWNGRADED;
default:
- CTX_ERROR(transaction->ctx,
+ ERROR(transaction->ctx,
"Unhandled step type 0x%x. Ignoring.\n", (unsigned int)type);
return PAKFIRE_STEP_UNKNOWN;
// Clone the transaction to keep a copy of it
transaction->transaction = solver_create_transaction(transaction->solver);
if (!transaction->transaction) {
- CTX_ERROR(transaction->ctx, "Could not create transaction from solver: %m\n");
+ ERROR(transaction->ctx, "Could not create transaction from solver: %m\n");
return 1;
}
transaction->userinstalled = calloc(userinstalled.count + 1, sizeof(*transaction->userinstalled));
if (!transaction->userinstalled) {
- CTX_ERROR(transaction->ctx, "Could not allocate userinstalled: %m\n");
+ ERROR(transaction->ctx, "Could not allocate userinstalled: %m\n");
r = -errno;
goto ERROR;
}
// Allocate a new solver
transaction->solver = solver_create(pool);
if (!transaction->solver) {
- CTX_ERROR(transaction->ctx, "Could not allocate solver: %m\n");
+ ERROR(transaction->ctx, "Could not allocate solver: %m\n");
return -errno;
}
return problems;
ERROR:
- CTX_ERROR(transaction->ctx, "Could not import problems: %s\n", strerror(r));
+ ERROR(transaction->ctx, "Could not import problems: %s\n", strerror(r));
if (problems) {
for (struct pakfire_problem** p = problems; *p; p++)
const char* selection = pool_selection2str(pool, &transaction->jobs, 0);
if (selection)
- CTX_DEBUG(transaction->ctx, "Solving: %s\n", selection);
+ DEBUG(transaction->ctx, "Solving: %s\n", selection);
RETRY:
// Save time when we starting solving
// Save time when we finished solving
solving_end = clock();
- CTX_DEBUG(transaction->ctx, "Solved request in %.4fms\n",
+ DEBUG(transaction->ctx, "Solved request in %.4fms\n",
(double)(solving_end - solving_start) * 1000 / CLOCKS_PER_SEC);
switch (r) {
p = pakfire_transaction_get_problem_string(transaction, flags);
if (p) {
- CTX_DEBUG(transaction->ctx,
+ DEBUG(transaction->ctx,
"Could not solve request: %s\n%s\n", selection, p);
// Return the problems
queue_push2(&jobs, SOLVER_SOLVABLE_PROVIDES, id);
}
- CTX_DEBUG(transaction->ctx, "Found %d match(es) for '%s'\n", jobs.count / 2, what);
+ DEBUG(transaction->ctx, "Found %d match(es) for '%s'\n", jobs.count / 2, what);
// Set action and global flags
for (int i = 0; i < jobs.count; i += 2) {
}
if (s)
- CTX_DEBUG(transaction->ctx, "%s", s);
+ DEBUG(transaction->ctx, "%s", s);
ERROR:
queue_free(&classes);
// Nothing to do if this step does not have an archive
if (!archive) {
- CTX_DEBUG(transaction->ctx, "Package %s requires no archive\n", nevra);
+ DEBUG(transaction->ctx, "Package %s requires no archive\n", nevra);
return 0;
}
// Fetch digest from package
const unsigned char* expected_digest = pakfire_package_get_digest(pkg, &digest_type, &length);
if (!expected_digest) {
- CTX_DEBUG(transaction->ctx, "Package %s has no digest\n", nevra);
+ DEBUG(transaction->ctx, "Package %s has no digest\n", nevra);
return 0;
}
// Extract payload
int r = pakfire_archive_extract(archive, NULL, 0);
if (r) {
- CTX_ERROR(transaction->ctx, "Could not extract package %s: %m\n",
+ ERROR(transaction->ctx, "Could not extract package %s: %m\n",
nevra);
return r;
}
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
const enum pakfire_steps type = pakfire_transaction_get_step_type(transaction, pkg);
- CTX_DEBUG(transaction->ctx, "Running %s (%s) for %s\n",
+ DEBUG(transaction->ctx, "Running %s (%s) for %s\n",
pakfire_action_type_string(action), pakfire_step_type_string(type), nevra);
int r = 0;
}
if (r)
- CTX_ERROR(transaction->ctx, "Step %s (%u) for %s has failed: %m\n",
+ ERROR(transaction->ctx, "Step %s (%u) for %s has failed: %m\n",
pakfire_action_type_string(action), type, nevra);
return r;
// End loop if action was unsuccessful
if (r) {
- CTX_DEBUG(transaction->ctx, "Step %u failed: %m\n", i);
+ DEBUG(transaction->ctx, "Step %u failed: %m\n", i);
break;
}
}
// Create the symlink
r = symlink(dst, link);
if (r) {
- CTX_DEBUG(ctx, "Could not create symlink %s to %s: %m\n", dst, link);
+ DEBUG(ctx, "Could not create symlink %s to %s: %m\n", dst, link);
return r;
}
- CTX_DEBUG(ctx, "Created symlink %s --> %s\n", link, dst);
+ DEBUG(ctx, "Created symlink %s --> %s\n", link, dst);
return 0;
}
struct pakfire_db* db;
int r;
- CTX_DEBUG(transaction->ctx, "Running Transaction %p\n", transaction);
+ DEBUG(transaction->ctx, "Running Transaction %p\n", transaction);
// Open all archives
r = pakfire_transaction_open_archives(transaction);
// Open the database
r = pakfire_db_open(&db, transaction->pakfire, PAKFIRE_DB_READWRITE);
if (r) {
- CTX_ERROR(transaction->ctx, "Could not open the database\n");
+ ERROR(transaction->ctx, "Could not open the database\n");
return r;
}
if (r)
goto ERROR;
- CTX_DEBUG(transaction->ctx, "The transaction has finished successfully\n");
+ DEBUG(transaction->ctx, "The transaction has finished successfully\n");
// Reload database for next transaction
// Initialize the HTTP client
r = pakfire_httpclient_create(&httpclient, transaction->ctx, NULL);
if (r) {
- CTX_ERROR(transaction->ctx, "Could not initialize HTTP client: %m\n");
+ ERROR(transaction->ctx, "Could not initialize HTTP client: %m\n");
return 1;
}
if (r) {
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
- CTX_ERROR(transaction->ctx, "Could not add download to queue: %s: %m\n", nevra);
+ ERROR(transaction->ctx, "Could not add download to queue: %s: %m\n", nevra);
goto ERROR;
}
}
// Skip running an empty transaction
if (!transaction->num) {
- CTX_DEBUG(transaction->ctx, "Empty transaction. Skipping...\n");
+ DEBUG(transaction->ctx, "Empty transaction. Skipping...\n");
return 0;
}
// Check if we should continue
r = pakfire_ctx_confirm(transaction->ctx, transaction->pakfire, dump, _("Is this okay?"));
if (r) {
- CTX_ERROR(transaction->ctx, "Transaction aborted upon user request\n");
+ ERROR(transaction->ctx, "Transaction aborted upon user request\n");
goto ERROR;
}
const char* files[transaction->num + 1];
unsigned int num = 0;
- CTX_DEBUG(transaction->ctx, "Writing transaction to %s...\n", path);
+ DEBUG(transaction->ctx, "Writing transaction to %s...\n", path);
// Open all archives
r = pakfire_transaction_open_archives(transaction);
if (r)
return r;
- CTX_DEBUG(ctx, "Creating symlink %s -> %s (%s)\n", target, linkpath, path);
+ DEBUG(ctx, "Creating symlink %s -> %s (%s)\n", target, linkpath, path);
// Create the symlink
r = symlink(path, linkpath);
if (r) {
- CTX_ERROR(ctx, "Could not create symlink %s (%s): %m\n", linkpath, path);
+ ERROR(ctx, "Could not create symlink %s (%s): %m\n", linkpath, path);
return r;
}
// Create tokener
tokener = json_tokener_new();
if (!tokener) {
- CTX_ERROR(ctx, "Could not allocate JSON tokener: %m\n");
+ ERROR(ctx, "Could not allocate JSON tokener: %m\n");
goto ERROR;
}
if (!json) {
enum json_tokener_error error = json_tokener_get_error(tokener);
- CTX_ERROR(ctx, "JSON parsing error: %s\n", json_tokener_error_desc(error));
+ ERROR(ctx, "JSON parsing error: %s\n", json_tokener_error_desc(error));
goto ERROR;
}
// Log what we have parsed
- CTX_DEBUG(ctx, "Parsed JSON:\n%s\n",
+ DEBUG(ctx, "Parsed JSON:\n%s\n",
json_object_to_json_string_ext(json,
JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY)
);
// Fetch current configuration
r = getrlimit(RLIMIT_NOFILE, &rl);
if (r < 0) {
- CTX_ERROR(ctx, "Could not read RLIMIT_NOFILE: %m\n");
+ ERROR(ctx, "Could not read RLIMIT_NOFILE: %m\n");
return -errno;
}
// Set the new limit
r = setrlimit(RLIMIT_NOFILE, &rl);
if (r < 0) {
- CTX_ERROR(ctx, "Could not set RLIMIT_NOFILE to %lu: %m\n", rl.rlim_cur);
+ ERROR(ctx, "Could not set RLIMIT_NOFILE to %lu: %m\n", rl.rlim_cur);
return -errno;
}
- CTX_DEBUG(ctx, "RLIMIT_NOFILE set to %d\n", limit);
+ DEBUG(ctx, "RLIMIT_NOFILE set to %d\n", limit);
return 0;
}
if (!*regex) {
pcre2_get_error_message(pcre2_errno, errmsg, sizeof(errmsg));
- CTX_ERROR(ctx, "PCRE2 compilation failed for '%s' at offset %zu: %s\n",
+ ERROR(ctx, "PCRE2 compilation failed for '%s' at offset %zu: %s\n",
pattern, pcre2_offset, errmsg);
return 1;
}
pcre2_errno = pcre2_jit_compile(*regex, PCRE2_JIT_COMPLETE);
if (pcre2_errno) {
pcre2_get_error_message(pcre2_errno, errmsg, sizeof(errmsg));
- CTX_ERROR(ctx, "Enabling JIT on '%s' failed: %s\n", pattern, errmsg);
+ ERROR(ctx, "Enabling JIT on '%s' failed: %s\n", pattern, errmsg);
return 1;
}
if (!b64) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "Could not initialize the base64 encoder: %s\n", error);
+ ERROR(ctx, "Could not initialize the base64 encoder: %s\n", error);
r = 1;
goto ERROR;
}
if (!bio) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "Could not initialize memory buffer: %s\n", error);
+ ERROR(ctx, "Could not initialize memory buffer: %s\n", error);
r = 1;
goto ERROR;
}
if (r < 1) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "%s\n", error);
+ ERROR(ctx, "%s\n", error);
r = 1;
goto ERROR;
}
// Copy the output to the heap
*output = strndup(p, l);
if (!*output) {
- CTX_ERROR(ctx, "Could not copy base64 encoded string to heap: %m\n");
+ ERROR(ctx, "Could not copy base64 encoded string to heap: %m\n");
r = 1;
goto ERROR;
}
if (!b64) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "Could not initialize the base64 decoder: %s\n", error);
+ ERROR(ctx, "Could not initialize the base64 decoder: %s\n", error);
r = 1;
goto ERROR;
}
if (!bio) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "Could not initialize memory buffer: %s\n", error);
+ ERROR(ctx, "Could not initialize memory buffer: %s\n", error);
r = 1;
goto ERROR;
}
if (bytes_read < 0) {
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
- CTX_ERROR(ctx, "Could not read data: %s\n", error);
+ ERROR(ctx, "Could not read data: %s\n", error);
r = -EINVAL;
goto ERROR;
// Allocate an output buffer
p = pakfire_realloc(p, *length);
if (!p) {
- CTX_ERROR(ctx, "Could not allocate buffer: %m\n");
+ ERROR(ctx, "Could not allocate buffer: %m\n");
r = -errno;
goto ERROR;
}
// Check for any errors
if (ferror(src)) {
- CTX_ERROR(ctx, "Could not read data: %m\n");
+ ERROR(ctx, "Could not read data: %m\n");
return 1;
}
// Write the data
bytes_written = fwrite(buffer, 1, bytes_read, dst);
if (bytes_written < bytes_read) {
- CTX_ERROR(ctx, "Could not write data: %m\n");
+ ERROR(ctx, "Could not write data: %m\n");
return 1;
}
}
switch (type) {
case CURLINFO_TEXT:
- CTX_DEBUG(ctx, "cURL: %.*s", (int)size, data);
+ DEBUG(ctx, "cURL: %.*s", (int)size, data);
break;
// Log headers
case CURLINFO_HEADER_IN:
- CTX_DEBUG(ctx, "cURL: < %.*s", (int)size, data);
+ DEBUG(ctx, "cURL: < %.*s", (int)size, data);
break;
case CURLINFO_HEADER_OUT:
- CTX_DEBUG(ctx, "cURL: > %.*s", (int)size, data);
+ DEBUG(ctx, "cURL: > %.*s", (int)size, data);
break;
// Ignore everything else
if (xfer->evp) {
r = EVP_DigestUpdate(xfer->evp, data, nmemb);
if (r != 1) {
- CTX_ERROR(ctx, "EVP_DigestUpdate failed: %s\n",
+ ERROR(ctx, "EVP_DigestUpdate failed: %s\n",
ERR_error_string(ERR_get_error(), NULL));
return 0;
}
// Configure the share handle
r = curl_easy_setopt(xfer->handle, CURLOPT_SHARE, share);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not configure cURL share handle: %s\n",
+ ERROR(xfer->ctx, "Could not configure cURL share handle: %s\n",
curl_easy_strerror(r));
return r;
}
// Fail if the context is flagged as offline
if (pakfire_ctx_has_flag(ctx, PAKFIRE_CTX_OFFLINE)) {
- CTX_ERROR(ctx, "Cannot initialize a transfer in offline mode\n");
+ ERROR(ctx, "Cannot initialize a transfer in offline mode\n");
return -EPERM;
}
xfer->mime = curl_mime_init(xfer->handle);
if (!xfer->mime) {
- CTX_ERROR(xfer->ctx, "Could not allocate the MIME object: %s\n",
+ ERROR(xfer->ctx, "Could not allocate the MIME object: %s\n",
strerror(errno));
r = -errno;
goto ERROR;
// Allocate another MIME part
part = curl_mime_addpart(xfer->mime);
if (!part) {
- CTX_ERROR(xfer->ctx, "Could not allocate MIME part: %s\n",
+ ERROR(xfer->ctx, "Could not allocate MIME part: %s\n",
strerror(errno));
r = errno;
goto ERROR;
// Set the key
r = curl_mime_name(part, key);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not set parameter key (%s): %s\n",
+ ERROR(xfer->ctx, "Could not set parameter key (%s): %s\n",
key, curl_easy_strerror(r));
goto ERROR;
}
// Set the data
r = curl_mime_data(part, buffer, CURL_ZERO_TERMINATED);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not set parameter data (%s): %s\n",
+ ERROR(xfer->ctx, "Could not set parameter data (%s): %s\n",
key, curl_easy_strerror(r));
goto ERROR;
}
// Open a memory stream
f = open_memstream(buffer, length);
if (!f) {
- CTX_ERROR(xfer->ctx, "Could not open memory stream: %s\n", strerror(errno));
+ ERROR(xfer->ctx, "Could not open memory stream: %s\n", strerror(errno));
return -errno;
}
// Create a temporary file
f = pakfire_mktemp(xfer->tmpfile, 0600);
if (!f) {
- CTX_ERROR(xfer->ctx, "Could not open temporary file for %s: %s\n",
+ ERROR(xfer->ctx, "Could not open temporary file for %s: %s\n",
path, strerror(errno));
return -errno;
}
return pakfire_xfer_allocate_tmpfile_legacy(xfer, path);
default:
- CTX_ERROR(xfer->ctx, "Could not open temporary file in %s: %s\n",
+ ERROR(xfer->ctx, "Could not open temporary file in %s: %s\n",
dirname, strerror(errno));
return -errno;
}
static int pakfire_xfer_fail(struct pakfire_xfer* xfer, int code) {
int r;
- CTX_DEBUG(xfer->ctx, "Xfer failed: %s\n", curl_easy_strerror(code));
+ DEBUG(xfer->ctx, "Xfer failed: %s\n", curl_easy_strerror(code));
// Throw away any downloaded data
if (xfer->fin) {
// No mirror found
if (!xfer->mirror) {
- CTX_ERROR(xfer->ctx, "No mirrors left to try\n");
+ ERROR(xfer->ctx, "No mirrors left to try\n");
// No mirrors left
return ENOENT;
}
- CTX_DEBUG(xfer->ctx, "Selected mirror %s\n", pakfire_mirror_get_url(xfer->mirror));
+ DEBUG(xfer->ctx, "Selected mirror %s\n", pakfire_mirror_get_url(xfer->mirror));
return 0;
}
// Otherwise, we resize the buffer
xfer->buffer.data = pakfire_realloc(xfer->buffer.data, size);
if (!xfer->buffer.data) {
- CTX_ERROR(xfer->ctx, "Could not allocate memory: %m\n");
+ ERROR(xfer->ctx, "Could not allocate memory: %m\n");
return -errno;
}
return pakfire_xfer_fail(xfer, PAKFIRE_XFER_TRANSPORT_ERROR);
default:
- CTX_ERROR(xfer->ctx, "Could not read from WebSocket: %s\n", curl_easy_strerror(r));
+ ERROR(xfer->ctx, "Could not read from WebSocket: %s\n", curl_easy_strerror(r));
return r;
}
- CTX_DEBUG(xfer->ctx, "Read %zu byte(s) from WebSocket\n", bytes_received);
+ DEBUG(xfer->ctx, "Read %zu byte(s) from WebSocket\n", bytes_received);
// If we have not received anything, we will wait for being called again
if (!bytes_received)
if (meta->flags & CURLWS_CONT)
return pakfire_xfer_socket_recv(xfer);
- CTX_DEBUG(xfer->ctx, "We have received a message of %zu byte(s)\n", xfer->buffer.size);
+ DEBUG(xfer->ctx, "We have received a message of %zu byte(s)\n", xfer->buffer.size);
if (meta->flags & CURLWS_TEXT) {
- CTX_DEBUG(xfer->ctx, "The message is a text\n");
+ DEBUG(xfer->ctx, "The message is a text\n");
} else if (meta->flags & CURLWS_BINARY) {
- CTX_DEBUG(xfer->ctx, "The message is binary\n");
+ DEBUG(xfer->ctx, "The message is binary\n");
}
// Once we have received the entire message we call the callback
// Fetch the socket
r = curl_easy_getinfo(xfer->handle, CURLINFO_ACTIVESOCKET, &socket);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not fetch the socket: %s\n", curl_easy_strerror(r));
+ ERROR(xfer->ctx, "Could not fetch the socket: %s\n", curl_easy_strerror(r));
goto ERROR;
}
- CTX_DEBUG(xfer->ctx, "Connection is using socket %d\n", socket);
+ DEBUG(xfer->ctx, "Connection is using socket %d\n", socket);
// Check what callbacks we have
if (xfer->callbacks.recv)
// Register a callback with the event loop
r = sd_event_add_io(loop, &xfer->event, socket, events, __pakfire_xfer_socket, xfer);
if (r < 0) {
- CTX_ERROR(xfer->ctx, "Could not register socket %d: %s\n", socket, strerror(-r));
+ ERROR(xfer->ctx, "Could not register socket %d: %s\n", socket, strerror(-r));
goto ERROR;
}
- CTX_DEBUG(xfer->ctx, "WebSocket registered with event loop\n");
+ DEBUG(xfer->ctx, "WebSocket registered with event loop\n");
// Call the open callback
if (xfer->callbacks.open) {
if (!*xfer->path)
return 0;
- CTX_DEBUG(xfer->ctx, "Download successful. Storing result in %s\n", xfer->path);
+ DEBUG(xfer->ctx, "Download successful. Storing result in %s\n", xfer->path);
int fd = fileno(xfer->fin);
if (*xfer->tmpfile) {
r = link(xfer->tmpfile, xfer->path);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not link destination file %s: %m\n", xfer->path);
+ ERROR(xfer->ctx, "Could not link destination file %s: %m\n", xfer->path);
return r;
}
} else {
r = linkat(fd, "", AT_FDCWD, xfer->path, AT_EMPTY_PATH);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not link destination file %s: %m\n", xfer->path);
+ ERROR(xfer->ctx, "Could not link destination file %s: %m\n", xfer->path);
return r;
}
}
return r;
// Log the result
- CTX_DEBUG(xfer->ctx, "cURL xfer done: %d - %s\n", code, curl_easy_strerror(code));
+ DEBUG(xfer->ctx, "cURL xfer done: %d - %s\n", code, curl_easy_strerror(code));
if (*xfer->error)
- CTX_DEBUG(xfer->ctx, " Error: %s\n", xfer->error);
+ DEBUG(xfer->ctx, " Error: %s\n", xfer->error);
// Protocol
curl_easy_getinfo(h, CURLINFO_SCHEME, &scheme);
// Effective URL
curl_easy_getinfo(h, CURLINFO_EFFECTIVE_URL, &xfer->effective_url);
if (xfer->effective_url)
- CTX_DEBUG(xfer->ctx, " Effective URL: %s\n", xfer->effective_url);
+ DEBUG(xfer->ctx, " Effective URL: %s\n", xfer->effective_url);
// Response code
curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &response_code);
if (response_code)
- CTX_DEBUG(xfer->ctx, " Response code: %ld\n", response_code);
+ DEBUG(xfer->ctx, " Response code: %ld\n", response_code);
// HTTP Version
curl_easy_getinfo(h, CURLINFO_HTTP_VERSION, &http_version);
if (http_version)
- CTX_DEBUG(xfer->ctx, " HTTP Version: %s\n", curl_http_version(http_version));
+ DEBUG(xfer->ctx, " HTTP Version: %s\n", curl_http_version(http_version));
// Total Times
curl_easy_getinfo(h, CURLINFO_TOTAL_TIME, &total_time);
- CTX_DEBUG(xfer->ctx, " Total Time: %.2fs\n", total_time);
+ DEBUG(xfer->ctx, " Total Time: %.2fs\n", total_time);
// Download Size
r = curl_easy_getinfo(h, CURLINFO_SIZE_DOWNLOAD_T, &download_size);
return r;
if (download_size)
- CTX_DEBUG(xfer->ctx, " Download Size: %ld bytes\n", download_size);
+ DEBUG(xfer->ctx, " Download Size: %ld bytes\n", download_size);
// Download Speed
r = curl_easy_getinfo(h, CURLINFO_SPEED_DOWNLOAD_T, &download_speed);
return r;
if (download_speed)
- CTX_DEBUG(xfer->ctx, " Download Speed: %ld bps\n", download_speed);
+ DEBUG(xfer->ctx, " Download Speed: %ld bps\n", download_speed);
// Upload Size
r = curl_easy_getinfo(h, CURLINFO_SIZE_UPLOAD_T, &upload_size);
return r;
if (upload_size)
- CTX_DEBUG(xfer->ctx, " Upload Size: %ld bytes\n", upload_size);
+ DEBUG(xfer->ctx, " Upload Size: %ld bytes\n", upload_size);
// Upload Speed
r = curl_easy_getinfo(h, CURLINFO_SPEED_UPLOAD_T, &upload_speed);
return r;
if (upload_speed)
- CTX_DEBUG(xfer->ctx, " Upload Speed: %ld bps\n", upload_speed);
+ DEBUG(xfer->ctx, " Upload Speed: %ld bps\n", upload_speed);
// Check if digests match
if (xfer->evp) {
// Finish message digest computation
r = EVP_DigestFinal_ex(xfer->evp, xfer->computed_digest, &xfer->computed_digest_length);
if (r != 1) {
- CTX_ERROR(xfer->ctx, "Could not finish message digest computation: %s\n",
+ ERROR(xfer->ctx, "Could not finish message digest computation: %s\n",
ERR_error_string(ERR_get_error(), NULL));
return 1;
}
// Message Digest
char* hexdigest = __pakfire_hexlify(xfer->computed_digest, xfer->computed_digest_length);
if (hexdigest) {
- CTX_DEBUG(xfer->ctx, " Message Digest: %s\n", hexdigest);
+ DEBUG(xfer->ctx, " Message Digest: %s\n", hexdigest);
free(hexdigest);
}
char* expected_hexdigest = __pakfire_hexlify(xfer->expected_digest,
xfer->expected_digest_length);
- CTX_ERROR(xfer->ctx, "Download checksum for %s didn't match:\n", xfer->effective_url);
- CTX_ERROR(xfer->ctx, " Expected: %s\n", expected_hexdigest);
- CTX_ERROR(xfer->ctx, " Computed: %s\n", computed_hexdigest);
+ ERROR(xfer->ctx, "Download checksum for %s didn't match:\n", xfer->effective_url);
+ ERROR(xfer->ctx, " Expected: %s\n", expected_hexdigest);
+ ERROR(xfer->ctx, " Computed: %s\n", computed_hexdigest);
if (computed_hexdigest)
free(computed_hexdigest);
// Fail if we could not set the URL
} else {
- CTX_ERROR(xfer->ctx, "Invalid xfer %s\n", xfer->url);
+ ERROR(xfer->ctx, "Invalid xfer %s\n", xfer->url);
r = -EINVAL;
goto ERROR;
}
if (xfer->direction == PAKFIRE_XFER_SOCKET) {
r = curl_url_set(xfer->fullurl, CURLUPART_SCHEME, "wss", 0);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not change to WebSocket: %s\n", curl_url_strerror(r));
+ ERROR(xfer->ctx, "Could not change to WebSocket: %s\n", curl_url_strerror(r));
goto ERROR;
}
}
// Set the URL
r = curl_easy_setopt(xfer->handle, CURLOPT_CURLU, xfer->fullurl);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not set the URL: %s\n", curl_easy_strerror(r));
+ ERROR(xfer->ctx, "Could not set the URL: %s\n", curl_easy_strerror(r));
goto ERROR;
}
// Let cURL know that we are uploading things
r = curl_easy_setopt(xfer->handle, CURLOPT_UPLOAD, 1L);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not enable upload\n");
+ ERROR(xfer->ctx, "Could not enable upload\n");
return r;
}
r = curl_easy_setopt(xfer->handle,
CURLOPT_INFILESIZE_LARGE, (curl_off_t)xfer->expected_size);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not set upload size\n");
+ ERROR(xfer->ctx, "Could not set upload size\n");
return r;
}
}
// Ask cURL to connect and let us handle the rest
r = curl_easy_setopt(xfer->handle, CURLOPT_CONNECT_ONLY, 2L);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not enable CONNECT_ONLY\n");
+ ERROR(xfer->ctx, "Could not enable CONNECT_ONLY\n");
return r;
}
// Compose the URL
r = pakfire_xfer_prepare_url(xfer);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not compose URL: %m\n");
+ ERROR(xfer->ctx, "Could not compose URL: %m\n");
return r;
}
if (xfer->headers) {
r = curl_easy_setopt(xfer->handle, CURLOPT_HTTPHEADER, xfer->headers);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not set headers: %s\n", curl_easy_strerror(r));
+ ERROR(xfer->ctx, "Could not set headers: %s\n", curl_easy_strerror(r));
return r;
}
}
if (xfer->mime) {
r = curl_easy_setopt(xfer->handle, CURLOPT_MIMEPOST, xfer->mime);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not set POST payload: %s\n", curl_easy_strerror(r));
+ ERROR(xfer->ctx, "Could not set POST payload: %s\n", curl_easy_strerror(r));
return r;
}
}
// Request SPNEGO
r = curl_easy_setopt(xfer->handle, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not enable SPNEGO\n");
+ ERROR(xfer->ctx, "Could not enable SPNEGO\n");
return r;
}
// Set an empty username
r = curl_easy_setopt(xfer->handle, CURLOPT_USERPWD, ":");
if (r) {
- CTX_ERROR(xfer->ctx, "Could not set username\n");
+ ERROR(xfer->ctx, "Could not set username\n");
return r;
}
}
if (xfer->md) {
xfer->evp = EVP_MD_CTX_new();
if (!xfer->evp) {
- CTX_ERROR(xfer->ctx, "Could not create EVP context: %m\n");
+ ERROR(xfer->ctx, "Could not create EVP context: %m\n");
return 1;
}
// Initialize the EVP context
r = EVP_DigestInit_ex(xfer->evp, xfer->md, NULL);
if (r != 1) {
- CTX_ERROR(xfer->ctx, "Could not initialize EVP context: %s\n",
+ ERROR(xfer->ctx, "Could not initialize EVP context: %s\n",
ERR_error_string(ERR_get_error(), NULL));
return 1;
}
// Send the message
r = curl_ws_send(xfer->handle, message, length, &bytes_sent, 0, CURLWS_TEXT);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not send message: %s\n", curl_easy_strerror(r));
+ ERROR(xfer->ctx, "Could not send message: %s\n", curl_easy_strerror(r));
return r;
}
// Log success
- CTX_DEBUG(xfer->ctx,
+ DEBUG(xfer->ctx,
"Successfully sent a WebSocket message of %zu byte(s)\n", bytes_sent);
return 0;
// Prepare the xfer
r = pakfire_xfer_prepare(xfer, NULL, flags);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not prepare xfer %s: %s\n",
+ ERROR(xfer->ctx, "Could not prepare xfer %s: %s\n",
xfer->url, strerror(-r));
return r;
}
m = json_object_get_string(message);
// Log the error
- CTX_ERROR(xfer->ctx, "%s responded with error %u (%s):\n %s\n",
+ ERROR(xfer->ctx, "%s responded with error %u (%s):\n %s\n",
url, c, strerror(c), m);
return -c;
// Check if we received any data
if (!length) {
- CTX_ERROR(xfer->ctx, "Received an empty response\n");
+ ERROR(xfer->ctx, "Received an empty response\n");
r = -EBADMSG;
goto ERROR;
}
// Parse the buffer
o = pakfire_json_parse(xfer->ctx, buffer, length);
if (!o) {
- CTX_ERROR(xfer->ctx, "Could not parse the response\n");
+ ERROR(xfer->ctx, "Could not parse the response\n");
r = -EBADMSG;
goto ERROR;
}
// Check if the response is a dictionary
if (!json_object_is_type(o, json_type_object)) {
- CTX_ERROR(xfer->ctx, "The received object is not a JSON dict\n");
+ ERROR(xfer->ctx, "The received object is not a JSON dict\n");
r = -EBADMSG;
goto ERROR;
}
// Parse the response
r = pakfire_xfer_parse_api_response(xfer, buffer, length, response);
if (r) {
- CTX_ERROR(xfer->ctx, "Could not parse the API response: %s\n", strerror(-r));
+ ERROR(xfer->ctx, "Could not parse the API response: %s\n", strerror(-r));
goto ERROR;
}