diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-05-11 15:24:53 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-05-11 15:34:45 -0400 |
| commit | b7a60c5bed989a52a53b8b697203f55367f55a89 (patch) | |
| tree | 993173328bdf96eb469c2412241f202cdbc5cf53 | |
| parent | 58d3ca17dcd3f8b3aeb50b8e4f24afc76d33ff26 (diff) | |
| download | stasis-b7a60c5bed989a52a53b8b697203f55367f55a89.tar.gz | |
Replace msg, perror, and fprintf with SYS message macrosuse-sys-macros
40 files changed, 315 insertions, 297 deletions
diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c index 8a222c1..b902a8a 100644 --- a/src/cli/stasis/stasis_main.c +++ b/src/cli/stasis/stasis_main.c @@ -25,7 +25,7 @@ static void setup_sysconfdir() { globals.sysconfdir = realpath(stasis_sysconfdir_tmp, NULL); if (!globals.sysconfdir) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "Unable to resolve path to configuration directory: %s\n", stasis_sysconfdir_tmp); + SYSERROR("Unable to resolve path to configuration directory: %s", stasis_sysconfdir_tmp); exit(1); } } @@ -57,15 +57,14 @@ static void configure_stasis_ini(struct Delivery *ctx, char **config_input) { if (!access(cfgfile, F_OK | R_OK)) { *config_input = strdup(cfgfile); } else { - msg(STASIS_MSG_WARN, "STASIS global configuration is not readable, or does not exist: %s", cfgfile); + SYSWARN("STASIS global configuration is not readable, or does not exist: %s", cfgfile); } } SYSDEBUG("Reading STASIS global configuration: %s", *config_input); ctx->_stasis_ini_fp.cfg = ini_open(*config_input); if (!ctx->_stasis_ini_fp.cfg) { - msg(STASIS_MSG_ERROR, "Failed to read global config file: %s, %s\n", *config_input, strerror(errno)); - SYSERROR("Failed to read global config file: %s", *config_input); + SYSERROR("Failed to read global config file: %s, %s", *config_input, strerror(errno)); exit(1); } ctx->_stasis_ini_fp.cfg_path = strdup(*config_input); @@ -80,7 +79,7 @@ static void configure_delivery_ini(struct Delivery *ctx, char **delivery_input) msg(STASIS_MSG_L2, "Reading STASIS delivery configuration: %s\n", *delivery_input); ctx->_stasis_ini_fp.delivery = ini_open(*delivery_input); if (!ctx->_stasis_ini_fp.delivery) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to read delivery file: %s, %s\n", *delivery_input, strerror(errno)); + SYSERROR("Failed to read delivery file: %s, %s", *delivery_input, strerror(errno)); exit(1); } ctx->_stasis_ini_fp.delivery_path = strdup(*delivery_input); @@ -89,13 +88,13 @@ static void configure_delivery_ini(struct Delivery *ctx, char **delivery_input) static void configure_delivery_context(struct Delivery *ctx) { msg(STASIS_MSG_L2, "Bootstrapping delivery context\n"); if (bootstrap_build_info(ctx)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to bootstrap delivery context\n"); + SYSERROR("Failed to bootstrap delivery context"); exit(1); } msg(STASIS_MSG_L2, "Initializing delivery context\n"); if (delivery_init(ctx, INI_READ_RENDER)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to initialize delivery context\n"); + SYSERROR("Failed to initialize delivery context"); exit(1); } } @@ -103,7 +102,7 @@ static void configure_delivery_context(struct Delivery *ctx) { static void configure_jfrog_cli(struct Delivery *ctx) { msg(STASIS_MSG_L2, "Configuring JFrog CLI\n"); if (delivery_init_artifactory(ctx)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "JFrog CLI configuration failed\n"); + SYSERROR("JFrog CLI configuration failed"); exit(1); } } @@ -112,7 +111,7 @@ static void check_release_history(struct Delivery *ctx) { // Safety gate: Avoid clobbering a delivered release unless the user wants that behavior msg(STASIS_MSG_L2, "Checking release history\n"); if (!globals.enable_overwrite && delivery_exists(ctx) == DELIVERY_FOUND) { - msg(STASIS_MSG_ERROR, "Refusing to overwrite release: %s\nUse --overwrite to enable release clobbering.\n", ctx->info.release_name); + SYSERROR("Refusing to overwrite release: %s\nUse --overwrite to enable release clobbering.", ctx->info.release_name); exit(1); } @@ -123,7 +122,7 @@ static void check_conda_install_prefix(const struct Delivery *ctx) { // if path is "/" then, die // or if empty string, die if (!strcmp(ctx->storage.conda_install_prefix, DIR_SEP) || !strlen(ctx->storage.conda_install_prefix)) { - fprintf(stderr, "error: ctx.storage.conda_install_prefix is malformed!\n"); + SYSERROR("error: ctx.storage.conda_install_prefix is malformed!"); exit(1); } } @@ -135,14 +134,14 @@ static void sync_release_history(struct Delivery *ctx) { if (ctx->meta.rc > 1) { msg(STASIS_MSG_L1, "Syncing delivery artifacts for %s\n", ctx->info.build_name); if (delivery_series_sync(ctx) != 0) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Unable to sync artifacts for %s\n", ctx->info.build_name); - msg(STASIS_MSG_L3, "Case #1:\n" - "\tIf this is a new 'version', and 'rc' is greater " - "than 1, then no previous deliveries exist remotely. " - "Reset 'rc' to 1.\n"); - msg(STASIS_MSG_L3, "Case #2:\n" - "\tThe Artifactory server %s is unreachable, or the credentials used " - "are invalid.\n", globals.jfrog.url); + SYSERROR("Unable to sync artifacts for %s", ctx->info.build_name); + SYSERROR("Case #1:\n" + "\tIf this is a new 'version', and 'rc' is greater " + "than 1, then no previous deliveries exist remotely. " + "Reset 'rc' to 1."); + SYSERROR("Case #2:\n" + "\tThe Artifactory server %s is unreachable, or the credentials used " + "are invalid.", globals.jfrog.url); // No continue-on-error check. Without the previous delivery nothing can be done. exit(1); } @@ -157,13 +156,10 @@ static void check_conda_prefix_length(const struct Delivery *ctx) { const size_t prefix_len_max = 127; msg(STASIS_MSG_L2, "Checking length of conda installation prefix\n"); if (!strcmp(ctx->system.platform[DELIVERY_PLATFORM], "Linux") && prefix_len > prefix_len_max) { - msg(STASIS_MSG_L3 | STASIS_MSG_ERROR, - "The shebang, '#!%s/bin/python\\n' is too long (%zu > %zu).\n", + SYSERROR("The shebang, '#!%s/bin/python\\n' is too long (%zu > %zu).", ctx->storage.conda_install_prefix, prefix_len, prefix_len_max); - msg(STASIS_MSG_L3 | STASIS_MSG_ERROR, - "Conda's workaround to handle long path names does not work consistently within STASIS.\n"); - msg(STASIS_MSG_L3 | STASIS_MSG_ERROR, - "Please try again from a different, \"shorter\", directory.\n"); + SYSERROR("Conda's workaround to handle long path names does not work consistently within STASIS."); + SYSERROR("Please try again from a different, \"shorter\", directory."); exit(1); } } @@ -173,7 +169,7 @@ static void setup_conda(struct Delivery *ctx, char *installer_url, const size_t delivery_get_conda_installer_url(ctx, installer_url, maxlen); msg(STASIS_MSG_L2, "Downloading: %s\n", installer_url); if (delivery_get_conda_installer(ctx, installer_url)) { - msg(STASIS_MSG_ERROR, "download failed: %s\n", installer_url); + SYSERROR("download failed: %s", installer_url); exit(1); } @@ -217,7 +213,7 @@ static void configure_conda_base(struct Delivery *ctx, char *envs[]) { // Does a base.yml exist in the mission directory? // If not, do nothing. Otherwise, use the base.yml in the mission directory. if (access(mission_base_orig, F_OK) < 0) { - msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "Mission does not provide a base.yml"); + SYSWARN("Mission does not provide a base.yml"); } else { msg(STASIS_MSG_L2, "Using base environment configuration: %s\n", mission_base_orig); if (asprintf(&mission_base, "%s/%s-base.yml", ctx->storage.tmpdir, ctx->info.release_name) < 0) { @@ -239,18 +235,18 @@ static void configure_conda_base(struct Delivery *ctx, char *envs[]) { // If based_on was populated above, or defined in the configuration: install its packages. if (!isempty(ctx->meta.based_on)) { if (conda_env_exists(ctx->storage.conda_install_prefix, env) && conda_env_remove(env)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "failed to remove %s environment: %s\n", title); + SYSERROR("failed to remove %s environment: %s", title); exit(1); } if (conda_env_create_from_uri(env, ctx->meta.based_on, ctx->meta.python)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "unable to install %s environment using configuration file\n", title); + SYSERROR("unable to install %s environment using configuration file", title); exit(1); } } else { // Otherwise, create the environments with the requested Python version and move on if (conda_env_create(env, ctx->meta.python, NULL)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "failed to create %s environment\n", title); + SYSERROR("failed to create %s environment", title); exit(1); } } @@ -282,7 +278,7 @@ static void configure_conda_purge(struct Delivery *ctx, char *envs[]) { const int manager_flag = pkg_manager_use[i]; msg(STASIS_MSG_L2, "Purging %s packages from %s\n", manager_str, env); if (delivery_purge_packages(ctx, env, manager_flag)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "unable to purge requested %s packages from %s\n", manager_str, env); + SYSERROR("unable to purge requested %s packages from %s", manager_str, env); exit(1); } } @@ -294,7 +290,7 @@ static void setup_activate_test_env(const struct Delivery *ctx, const char *env_ // Activate test environment msg(STASIS_MSG_L1, "Activating test environment\n"); if (conda_activate(ctx->storage.conda_install_prefix, env_name_testing)) { - fprintf(stderr, "failed to activate test environment\n"); + SYSERROR("failed to activate test environment"); exit(1); } } @@ -302,11 +298,11 @@ static void setup_activate_test_env(const struct Delivery *ctx, const char *env_ static void configure_tool_versions(struct Delivery *ctx) { if (delivery_gather_tool_versions(ctx)) { if (!ctx->conda.tool_version) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Could not determine conda version\n"); + SYSERROR("Could not determine conda version"); exit(1); } if (!ctx->conda.tool_build_version) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Could not determine conda-build version\n"); + SYSERROR("Could not determine conda-build version"); exit(1); } } @@ -315,11 +311,11 @@ static void configure_tool_versions(struct Delivery *ctx) { static void install_packaging_tools() { msg(STASIS_MSG_L1, "Installing packaging tool(s)\n"); if (pip_exec("install build")) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "'build' tool installation failed\n"); + SYSERROR("'build' tool installation failed"); exit(1); } if (pip_exec("install cibuildwheel")) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "'cibuildwheel' tool installation failed\n"); + SYSERROR("'cibuildwheel' tool installation failed"); exit(1); } } @@ -331,12 +327,12 @@ static void force_conda_package_reinstallation_on_mismatch(struct Delivery *ctx, for (size_t i = 0; i < conda_package_count; i++) { const char *item = strlist_item(ctx->conda.conda_packages, i); if (!item) { - msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "NULL record in conda package list\n"); + SYSERROR("NULL record in conda package list"); exit(1); } char *pkg_name = strdup(item); if (!pkg_name) { - msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "unable to allocate memory for package name\n"); + SYSERROR("unable to allocate memory for package name"); exit(1); } const char *spec = find_version_spec(pkg_name); @@ -346,7 +342,7 @@ static void force_conda_package_reinstallation_on_mismatch(struct Delivery *ctx, msg(STASIS_MSG_L2, "%s\n", pkg_name); if (delivery_conda_enforce_package_version(ctx, env_name, pkg_name)) { - msg(STASIS_MSG_L3 | STASIS_MSG_ERROR, "Failed to determine conda package version: %s\n", pkg_name); + SYSERROR("Failed to determine conda package version: %s", pkg_name); guard_free(pkg_name); exit(1); } @@ -359,7 +355,7 @@ static void configure_package_overlay(struct Delivery *ctx, const char *env_name if (!isempty(ctx->meta.based_on)) { msg(STASIS_MSG_L1, "Generating package overlay from environment: %s\n", env_name); if (delivery_overlay_packages_from_env(ctx, env_name)) { - msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "%s", "Failed to generate package overlay. Resulting environment integrity cannot be guaranteed.\n"); + SYSERROR("Failed to generate package overlay. Resulting environment integrity cannot be guaranteed."); exit(1); } } @@ -390,7 +386,7 @@ static void run_tests(struct Delivery *ctx) { msg(STASIS_MSG_L2, "Rewriting test results\n"); delivery_fixup_test_results(ctx); } else { - msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Test execution is disabled\n"); + SYSWARN("Test execution is disabled"); } } @@ -465,7 +461,7 @@ static void build_docker(struct Delivery *ctx, const int disabled) { if (want_docker) { if (disabled) { - msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Docker image building is disabled by CLI argument\n"); + SYSWARN("Docker image building is disabled by CLI argument"); } else { char dockerfile[PATH_MAX] = {0}; snprintf(dockerfile, sizeof(dockerfile), "%s/%s", ctx->storage.build_docker_dir, "Dockerfile"); @@ -473,18 +469,18 @@ static void build_docker(struct Delivery *ctx, const int disabled) { if (!access(dockerfile, F_OK)) { msg(STASIS_MSG_L1, "Building Docker image\n"); if (delivery_docker(ctx)) { - msg(STASIS_MSG_L1 | STASIS_MSG_ERROR, "Failed to build docker image!\n"); + SYSERROR("Failed to build docker image!"); COE_CHECK_ABORT(1, "Failed to build docker image"); } } else { - msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Docker image building is disabled. No Dockerfile found in %s\n", ctx->storage.build_docker_dir); + SYSWARN("Docker image building is disabled. No Dockerfile found in %s", ctx->storage.build_docker_dir); } } else { - msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Docker image building is disabled. System configuration error\n"); + SYSWARN("Docker image building is disabled. System configuration error"); } } } else { - msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Docker image building is disabled. deploy:docker is not configured\n"); + SYSWARN("Docker image building is disabled. deploy:docker is not configured"); } } @@ -508,7 +504,7 @@ static void generate_release(struct Delivery *ctx, char *env_name, char *env_nam msg(STASIS_MSG_L1, "Dumping metadata\n"); if (delivery_dump_metadata(ctx)) { - msg(STASIS_MSG_L1 | STASIS_MSG_ERROR, "Metadata dump failed\n"); + SYSERROR("Metadata dump failed"); } } @@ -519,10 +515,10 @@ static void transfer_artifacts(struct Delivery *ctx) { msg(STASIS_MSG_L1, "Uploading artifacts\n"); delivery_artifact_upload(ctx); } else { - msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Artifactory upload is disabled by CLI argument\n"); + SYSWARN("Artifactory upload is disabled by CLI argument"); } } else { - msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Artifactory upload is disabled. deploy:artifactory is not configured\n"); + SYSWARN("Artifactory upload is disabled. deploy:artifactory is not configured"); } } @@ -625,11 +621,11 @@ int main(int argc, char *argv[]) { case OPT_TASK_TIMEOUT: globals.task_timeout = str_to_timeout(optarg); if (globals.task_timeout < 0) { - fprintf(stderr, "Invalid timeout: %s\n", optarg); + SYSERROR("Invalid timeout: %s", optarg); if (globals.task_timeout == STR_TO_TIMEOUT_INVALID_TIME_SCALE) { - fprintf(stderr, "Use format '#s' (seconds), '#m' (minutes), '#h' (hours)\n"); + SYSERROR("Use format '#s' (seconds), '#m' (minutes), '#h' (hours)"); } else if (globals.task_timeout == STR_TO_TIMEOUT_NEGATIVE) { - fprintf(stderr, "Timeout cannot be negative\n"); + SYSERROR("Timeout cannot be negative"); } exit(1); } @@ -640,8 +636,8 @@ int main(int argc, char *argv[]) { globals.pool_status_interval = 1; } else if (globals.pool_status_interval > 60 * 10) { // Possible poor choice alert - fprintf(stderr, "Caution: Excessive pausing between status updates may cause third-party CI/CD" - " jobs to fail if the stdout/stderr streams are idle for too long!\n"); + SYSWARN("Excessive pausing between status updates may cause third-party CI/CD" + " jobs to fail if the stdout/stderr streams are idle for too long!"); } break; case 'U': @@ -705,7 +701,7 @@ int main(int argc, char *argv[]) { } if (!delivery_input) { - fprintf(stderr, "error: a DELIVERY_FILE is required\n"); + SYSERROR("a DELIVERY_FILE is required"); usage(path_basename(argv[0])); exit(1); } diff --git a/src/cli/stasis/system_requirements.c b/src/cli/stasis/system_requirements.c index ebfbffc..02889da 100644 --- a/src/cli/stasis/system_requirements.c +++ b/src/cli/stasis/system_requirements.c @@ -32,7 +32,7 @@ void check_system_requirements(struct Delivery *ctx) { for (size_t i = 0; tools_required[i] != NULL; i++) { msg(STASIS_MSG_L3, "%s: ", tools_required[i]); if (!find_program(tools_required[i])) { - msg(STASIS_MSG_ERROR, "'%s' must be installed.\n", tools_required[i]); + SYSERROR("'%s' must be installed.", tools_required[i]); exit(1); } msg(STASIS_MSG_RESTRICT, "found\n"); @@ -62,7 +62,7 @@ void check_system_requirements(struct Delivery *ctx) { globals.enable_docker = false; } } else { - msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "Docker is broken\n"); + SYSWARN("Docker is broken"); // disable docker builds globals.enable_docker = false; } @@ -77,7 +77,7 @@ void check_system_path() { char *pathvar = NULL; pathvar = getenv("PATH"); if (!pathvar) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "PATH variable is not set. Cannot continue.\n"); + SYSERROR("PATH variable is not set. Cannot continue."); exit(1); } }
\ No newline at end of file diff --git a/src/cli/stasis_indexer/helpers.c b/src/cli/stasis_indexer/helpers.c index 1bb5862..097b0ca 100644 --- a/src/cli/stasis_indexer/helpers.c +++ b/src/cli/stasis_indexer/helpers.c @@ -89,7 +89,7 @@ int get_pandoc_version(size_t *result) { int pandoc_exec(const char *in_file, const char *out_file, const char *css_file, const char *title) { if (!find_program("pandoc")) { - fprintf(stderr, "pandoc is not installed: unable to generate HTML indexes\n"); + SYSWARN("pandoc is not installed: unable to generate HTML indexes"); return 0; } @@ -227,7 +227,7 @@ struct Delivery **get_latest_deliveries(struct Delivery **ctx, size_t nelem, siz struct Delivery **result = calloc(nelem + 1, sizeof(*result)); if (!result) { - fprintf(stderr, "Unable to allocate %zu bytes for result delivery array: %s\n", nelem * sizeof(*result), strerror(errno)); + SYSERROR("Unable to allocate %zu bytes for result delivery array: %s", nelem * sizeof(*result), strerror(errno)); return NULL; } @@ -287,7 +287,7 @@ int get_files(struct StrList **out, const char *path, const char *pattern, ...) } } if (no_match >= strlist_count(list)) { - fprintf(stderr, "no files matching the pattern: %s\n", userpattern); + SYSERROR("no files matching the pattern: %s", userpattern); guard_strlist_free(&list); return -1; } @@ -392,7 +392,7 @@ int write_manifest(const char *path, char **exclude_path, FILE *fp) { struct dirent *rec = NULL; DIR *dp = opendir(path); if (!dp) { - perror(path); + SYSERROR("unable to open directory: %s, %s", path ? path : "NULL", strerror(errno)); return -1; } while ((rec = readdir(dp)) != NULL) { diff --git a/src/cli/stasis_indexer/junitxml_report.c b/src/cli/stasis_indexer/junitxml_report.c index b767179..073bb61 100644 --- a/src/cli/stasis_indexer/junitxml_report.c +++ b/src/cli/stasis_indexer/junitxml_report.c @@ -98,7 +98,7 @@ static int write_report_output(struct Delivery *ctx, FILE *destfp, const char *x junitxml_testsuite_free(&testsuite); fclose(resultfp); } else { - fprintf(stderr, "bad test suite: %s: %s\n", strerror(errno), xmlfilename); + SYSWARN("bad test suite: %s: %s", strerror(errno), xmlfilename); } return 0; } @@ -116,7 +116,7 @@ int indexer_junitxml_report(struct Delivery **ctx, const size_t nelem) { if (!pushd((*ctx)->storage.results_dir)) { FILE *indexfp = fopen(indexfile, "w+"); if (!indexfp) { - fprintf(stderr, "Unable to open %s for writing\n", indexfile); + SYSERROR("Unable to open %s for writing", indexfile); return -1; } printf("Index %s opened for writing\n", indexfile); @@ -157,7 +157,7 @@ int indexer_junitxml_report(struct Delivery **ctx, const size_t nelem) { fclose(indexfp); popd(); } else { - fprintf(stderr, "Unable to enter delivery directory: %s\n", (*ctx)->storage.delivery_dir); + SYSERROR("Unable to enter delivery directory: %s", (*ctx)->storage.delivery_dir); guard_strlist_free(&file_listing); return -1; } diff --git a/src/cli/stasis_indexer/readmes.c b/src/cli/stasis_indexer/readmes.c index d740367..de9e2f2 100644 --- a/src/cli/stasis_indexer/readmes.c +++ b/src/cli/stasis_indexer/readmes.c @@ -16,7 +16,7 @@ int indexer_readmes(struct Delivery **ctx, const size_t nelem) { FILE *indexfp = fopen(indexfile, "w+"); if (!indexfp) { - fprintf(stderr, "Unable to open %s for writing\n", indexfile); + SYSERROR("Unable to open %s for writing", indexfile); return -1; } struct StrList *archs = get_architectures(latest_deliveries, nelem_real); diff --git a/src/cli/stasis_indexer/stasis_indexer_main.c b/src/cli/stasis_indexer/stasis_indexer_main.c index 56be257..2bf72fd 100644 --- a/src/cli/stasis_indexer/stasis_indexer_main.c +++ b/src/cli/stasis_indexer/stasis_indexer_main.c @@ -41,7 +41,7 @@ int indexer_combine_rootdirs(const char *dest, char **rootdirs, const size_t roo srcdir_with_output[sizeof(srcdir_with_output) - 1] = '\0'; if (access(srcdir_bare, F_OK)) { - fprintf(stderr, "%s does not exist\n", srcdir_bare); + SYSWARN("%s does not exist", srcdir_bare); continue; } @@ -98,12 +98,12 @@ int indexer_symlinks(struct Delivery **ctx, const size_t nelem) { if (!access(link_name_spec, F_OK)) { if (unlink(link_name_spec)) { - fprintf(stderr, "Unable to remove spec link: %s\n", link_name_spec); + SYSWARN("Unable to remove spec link: %s", link_name_spec); } } if (!access(link_name_readme, F_OK)) { if (unlink(link_name_readme)) { - fprintf(stderr, "Unable to remove readme link: %s\n", link_name_readme); + SYSWARN("Unable to remove readme link: %s", link_name_readme); } } @@ -111,19 +111,19 @@ int indexer_symlinks(struct Delivery **ctx, const size_t nelem) { printf("%s -> %s\n", file_name_spec, link_name_spec); } if (symlink(file_name_spec, link_name_spec)) { - fprintf(stderr, "Unable to link %s as %s\n", file_name_spec, link_name_spec); + SYSWARN("Unable to link %s as %s", file_name_spec, link_name_spec); } if (globals.verbose) { printf("%s -> %s\n", file_name_readme, link_name_readme); } if (symlink(file_name_readme, link_name_readme)) { - fprintf(stderr, "Unable to link %s as %s\n", file_name_readme, link_name_readme); + SYSWARN("Unable to link %s as %s", file_name_readme, link_name_readme); } } popd(); } else { - fprintf(stderr, "Unable to enter delivery directory: %s\n", (*ctx)->storage.delivery_dir); + SYSERROR("Unable to enter delivery directory: %s", (*ctx)->storage.delivery_dir); guard_free(data); return -1; } @@ -137,7 +137,7 @@ void indexer_init_dirs(struct Delivery *ctx, const char *workdir) { path_store(&ctx->storage.root, PATH_MAX, workdir, ""); path_store(&ctx->storage.tmpdir, PATH_MAX, ctx->storage.root, "tmp"); if (delivery_init_tmpdir(ctx)) { - fprintf(stderr, "Failed to configure temporary storage directory\n"); + SYSERROR("Failed to configure temporary storage directory"); exit(1); } @@ -222,7 +222,7 @@ int main(const int argc, char *argv[]) { while (optind < argc) { if (argv[optind]) { if (access(argv[optind], F_OK) < 0) { - fprintf(stderr, "%s: %s\n", argv[optind], strerror(errno)); + SYSERROR("%s: %s", argv[optind], strerror(errno)); exit(1); } } @@ -248,7 +248,7 @@ int main(const int argc, char *argv[]) { } if (!rootdirs || !rootdirs_total) { - fprintf(stderr, "You must specify at least one STASIS root directory to index\n"); + SYSERROR("You must specify at least one STASIS root directory to index"); exit(1); } @@ -274,7 +274,7 @@ int main(const int argc, char *argv[]) { globals.sysconfdir = realpath(stasis_sysconfdir_tmp, NULL); if (!globals.sysconfdir) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "Unable to resolve path to configuration directory: %s\n", stasis_sysconfdir_tmp); + SYSERROR("Unable to resolve path to configuration directory: %s", stasis_sysconfdir_tmp); exit(1); } diff --git a/src/cli/stasis_indexer/website.c b/src/cli/stasis_indexer/website.c index aa6e2a5..07ad6ad 100644 --- a/src/cli/stasis_indexer/website.c +++ b/src/cli/stasis_indexer/website.c @@ -42,12 +42,12 @@ int indexer_make_website(struct Delivery **ctx) { // Convert markdown to html if (pandoc_exec(fullpath_src, fullpath_dest, have_css ? css_filename : NULL, "STASIS")) { - msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "Unable to convert %s\n", fullpath_src); + SYSWARN("Unable to convert %s", fullpath_src); } if (file_replace_text(fullpath_dest, ".md", ".html", 0)) { // inform-only - SYSERROR("%s: failed to rewrite *.md urls with *.html extension", fullpath_dest); + SYSWARN("%s: failed to rewrite *.md urls with *.html extension", fullpath_dest); } // Link the nearest README.html to index.html @@ -58,7 +58,7 @@ int indexer_make_website(struct Delivery **ctx) { link_dest[sizeof(link_dest) - 1] = '\0'; snprintf(link_dest, sizeof(link_dest), "%s/%s", root, "index.html"); if (symlink(link_from, link_dest)) { - SYSERROR("Warning: symlink(%s, %s) failed: %s", link_from, link_dest, strerror(errno)); + SYSWARN("symlink(%s, %s) failed: %s", link_from, link_dest, strerror(errno)); } } } diff --git a/src/lib/core/artifactory.c b/src/lib/core/artifactory.c index 1e9de84..669bfff 100644 --- a/src/lib/core/artifactory.c +++ b/src/lib/core/artifactory.c @@ -38,7 +38,7 @@ int artifactory_download_cli(char *dest, strncpy(os_ident, "linux", sizeof(os_ident) - 1); os_ident[sizeof(os_ident) - 1] = '\0'; } else { - fprintf(stderr, "%s: unknown operating system: %s\n", __FUNCTION__, os_ident); + SYSERROR("%s: unknown operating system: %s", __FUNCTION__, os_ident); return -1; } @@ -59,7 +59,7 @@ int artifactory_download_cli(char *dest, } else if (!strcmp(arch_ident, "arm64") || !strcmp(arch_ident, "aarch64")) { strncpy(arch_ident, "arm64", sizeof(arch_ident) - 1); } else { - fprintf(stderr, "%s: unknown architecture: %s\n", __FUNCTION__, arch_ident); + SYSERROR("%s: unknown architecture: %s", __FUNCTION__, arch_ident); return -1; } arch_ident[sizeof(arch_ident) - 1] = '\0'; @@ -79,7 +79,7 @@ int artifactory_download_cli(char *dest, path[sizeof(path) - 1] = '\0'; if (mkdirs(path, 0755)) { - fprintf(stderr, "%s: %s: %s", __FUNCTION__, path, strerror(errno)); + SYSERROR("%s: %s: %s", __FUNCTION__, path, strerror(errno)); return -1; } @@ -176,8 +176,8 @@ int jfrt_auth_init(struct JFRT_Auth *auth_ctx) { char *client_cert_path = getenv("STASIS_JF_CLIENT_CERT_PATH"); if (!url) { - fprintf(stderr, "Artifactory URL is not configured:\n"); - fprintf(stderr, "please set STASIS_JF_ARTIFACTORY_URL\n"); + SYSERROR("Artifactory URL is not configured:"); + SYSERROR("please set STASIS_JF_ARTIFACTORY_URL"); return -1; } auth_ctx->url = url; @@ -208,11 +208,11 @@ int jfrt_auth_init(struct JFRT_Auth *auth_ctx) { auth_ctx->client_cert_key_path = client_cert_key_path; auth_ctx->client_cert_path = client_cert_path; } else { - fprintf(stderr, "Artifactory authentication is not configured:\n"); - fprintf(stderr, "set STASIS_JF_USER and STASIS_JF_PASSWORD\n"); - fprintf(stderr, "or, set STASIS_JF_ACCESS_TOKEN\n"); - fprintf(stderr, "or, set STASIS_JF_SSH_KEY_PATH and STASIS_JF_SSH_KEY_PASSPHRASE\n"); - fprintf(stderr, "or, set STASIS_JF_CLIENT_CERT_KEY_PATH and STASIS_JF_CLIENT_CERT_PATH\n"); + SYSERROR("Artifactory authentication is not configured:"); + SYSERROR("set STASIS_JF_USER and STASIS_JF_PASSWORD"); + SYSERROR("or, set STASIS_JF_ACCESS_TOKEN"); + SYSERROR("or, set STASIS_JF_SSH_KEY_PATH and STASIS_JF_SSH_KEY_PASSPHRASE"); + SYSERROR("or, set STASIS_JF_CLIENT_CERT_KEY_PATH and STASIS_JF_CLIENT_CERT_PATH"); return -1; } return 0; @@ -305,7 +305,7 @@ int jfrog_cli_rt_download(struct JFRT_Auth *auth, struct JFRT_Download *ctx, cha char cmd[STASIS_BUFSIZ] = {0}; if (isempty(repo_path)) { - fprintf(stderr, "repo_path argument must be a valid artifactory repository path\n"); + SYSERROR("repo_path argument must be a valid artifactory repository path"); return -1; } @@ -371,12 +371,12 @@ int jfrog_cli_rt_upload(struct JFRT_Auth *auth, struct JFRT_Upload *ctx, char *s char cmd[STASIS_BUFSIZ] = {0}; if (isempty(src)) { - fprintf(stderr, "src argument must be a valid file system path\n"); + SYSERROR("src argument must be a valid file system path"); return -1; } if (isempty(repo_path)) { - fprintf(stderr, "repo_path argument must be a valid artifactory repository path\n"); + SYSERROR("repo_path argument must be a valid artifactory repository path"); return -1; } @@ -469,7 +469,7 @@ int jfrog_cli_rt_search(struct JFRT_Auth *auth, struct JFRT_Search *ctx, char *r char cmd[STASIS_BUFSIZ] = {0}; if (isempty(repo_path)) { - fprintf(stderr, "repo_path argument must be a valid artifactory repository path\n"); + SYSERROR("repo_path argument must be a valid artifactory repository path"); return -1; } diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index 0259e82..f9e2bd2 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -40,7 +40,7 @@ int micromamba(const struct MicromambaInfo *info, char *command, ...) { char *errmsg = NULL; const long http_code = download(url, installer_path, &errmsg); if (HTTP_ERROR(http_code)) { - fprintf(stderr, "download failed: %ld: %s\n", http_code, errmsg); + SYSERROR("download failed: %ld: %s", http_code, errmsg); guard_free(errmsg); return -1; } @@ -176,7 +176,7 @@ int pkg_index_provides(int mode, const char *index, const char *spec, const char int logfd = mkstemp(logfile); if (logfd < 0) { - perror(logfile); + SYSERROR("unable to create log file: %s", logfile); remove(logfile); // fail harmlessly if not present return PKG_INDEX_PROVIDES_E_INTERNAL_LOG_HANDLE; } @@ -330,7 +330,7 @@ static int conda_prepend_condabin(const char *root) { static int env0_to_runtime(const char *logfile) { FILE *fp = fopen(logfile, "r"); if (!fp) { - perror(logfile); + SYSERROR("unable to open log file for reading: %s, %s", logfile, strerror(errno)); return -1; } @@ -355,14 +355,14 @@ static int env0_to_runtime(const char *logfile) { char **part = split(buf, "=", 1); if (!part) { - perror("unable to split environment variable buffer"); + SYSERROR("unable to split environment variable buffer: %s", strerror(errno)); fclose(fp); return -1; } if (!part[0]) { - msg(STASIS_MSG_WARN | STASIS_MSG_L1, "Invalid environment variable key ignored: '%s'\n", buf); + SYSWARN("Invalid environment variable key ignored: '%s'", buf); } else if (!part[1]) { - msg(STASIS_MSG_WARN | STASIS_MSG_L1, "Invalid environment variable value ignored: '%s'\n", buf); + SYSWARN("Invalid environment variable value ignored: '%s'", buf); } else { setenv(part[0], part[1], 1); } @@ -391,7 +391,7 @@ int conda_activate(const char *root, const char *env_name) { int fd = mkstemp(logfile); if (fd < 0) { - perror(logfile); + SYSERROR("log file creation failed: %s, %s", logfile, strerror(errno)); return -1; } close(fd); @@ -402,13 +402,13 @@ int conda_activate(const char *root, const char *env_name) { // Verify conda's init scripts are available if (access(path_conda, F_OK) < 0) { - perror(path_conda); + SYSERROR("conda is missing: %s, %s", path_conda, strerror(errno)); remove(logfile); return -1; } if (access(path_mamba, F_OK) < 0) { - perror(path_mamba); + SYSERROR("mamba is missing: %s, %s", path_mamba, strerror(errno)); remove(logfile); return -1; } @@ -514,7 +514,7 @@ int conda_check_required() { guard_free(cmd_out); guard_strlist_free(&result); } else { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "The base package requirement check could not be performed\n"); + SYSERROR("The base package requirement check could not be performed"); return 2; } return 0; @@ -559,7 +559,7 @@ int conda_setup_headless() { } if (conda_exec(cmd)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Unable to install user-defined base packages (conda)\n"); + SYSERROR("Unable to install user-defined base packages (conda)"); return 1; } } @@ -582,21 +582,21 @@ int conda_setup_headless() { } if (pip_exec(cmd)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Unable to install user-defined base packages (pip)\n"); + SYSERROR("Unable to install user-defined base packages (pip)"); return 1; } } if (conda_check_required()) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Your STASIS configuration lacks the bare" - " minimum software required to build conda packages." - " Please fix it.\n"); + SYSERROR("Your STASIS configuration lacks the bare" + " minimum software required to build conda packages." + " Please fix it."); return 1; } if (globals.always_update_base_environment) { if (conda_exec("update --all")) { - fprintf(stderr, "conda update was unsuccessful\n"); + SYSERROR("conda update was unsuccessful"); return 1; } } @@ -630,7 +630,7 @@ int conda_env_create_from_uri(char *name, char *uri, char *python_version) { const long http_code = download(uri_fs ? uri_fs : uri, tempfile, &errmsg); if (HTTP_ERROR(http_code)) { if (errmsg) { - fprintf(stderr, "download failed: %ld: %s\n", http_code, errmsg); + SYSERROR("download failed: %ld: %s", http_code, errmsg); guard_free(errmsg); } guard_free(uri_fs); diff --git a/src/lib/core/copy.c b/src/lib/core/copy.c index ed545cc..7666e67 100644 --- a/src/lib/core/copy.c +++ b/src/lib/core/copy.c @@ -5,7 +5,7 @@ int copy2(const char *src, const char *dest, unsigned int op) { SYSDEBUG("Stat source file: %s", src); if (lstat(src, &src_stat) < 0) { - perror(src); + SYSERROR("unable to stat source file: %s, %s", src, strerror(errno)); return -1; } @@ -37,12 +37,12 @@ int copy2(const char *src, const char *dest, unsigned int op) { } } else if (S_ISREG(src_stat.st_mode) && src_stat.st_nlink > 2 && src_stat.st_dev == dnamest.st_dev) { if (link(src, dest) < 0) { - perror(src); + SYSERROR("unable to link: %s, %s", src, strerror(errno)); return -1; } } else if (S_ISFIFO(src_stat.st_mode) || S_ISBLK(src_stat.st_mode) || S_ISCHR(src_stat.st_mode) || S_ISSOCK(src_stat.st_mode)) { if (mknod(dest, src_stat.st_mode, src_stat.st_rdev) < 0) { - perror(src); + SYSERROR("unable to mknod: %s, %s", dest, strerror(errno)); return -1; } } else if (S_ISREG(src_stat.st_mode)) { @@ -51,14 +51,14 @@ int copy2(const char *src, const char *dest, unsigned int op) { SYSDEBUG("Opening source file for reading"); FILE *fp1 = fopen(src, "rb"); if (!fp1) { - perror(src); + SYSERROR("unable to open source file for reading: %s, %s", src, strerror(errno)); return -1; } SYSDEBUG("Opening destination file for writing"); FILE *fp2 = fopen(dest, "w+b"); if (!fp2) { - perror(dest); + SYSERROR("unable to open destination file for writing: %s, %s", dest, strerror(errno)); fclose(fp1); return -1; } @@ -71,16 +71,16 @@ int copy2(const char *src, const char *dest, unsigned int op) { fclose(fp2); if (bytes_written != (size_t) src_stat.st_size) { - fprintf(stderr, "%s: SHORT WRITE (expected %zu bytes, but wrote %zu bytes)\n", dest, src_stat.st_size, bytes_written); + SYSDEBUG("%s: SHORT WRITE (expected %zu bytes, but wrote %zu bytes)", dest, src_stat.st_size, bytes_written); return -1; } if (op & CT_OWNER && chown(dest, src_stat.st_uid, src_stat.st_gid) < 0) { - perror(dest); + SYSERROR("unable to change owner: %s, %s", dest, strerror(errno)); } if (op & CT_PERM && chmod(dest, src_stat.st_mode) < 0) { - perror(dest); + SYSERROR("unable to chmod: %s, %s", dest, strerror(errno)); } } else { errno = EOPNOTSUPP; diff --git a/src/lib/core/download.c b/src/lib/core/download.c index ef1474f..28c5a6f 100644 --- a/src/lib/core/download.c +++ b/src/lib/core/download.c @@ -61,7 +61,7 @@ long download(char *url, const char *filename, char **errmsg) { CURL *c = curl_easy_init(); for (size_t retry = 0; retry < max_retries; retry++) { if (retry) { - fprintf(stderr, "[RETRY %zu/%zu] %s: %s\n", retry + 1, max_retries, *errmsg, url); + SYSWARN("[RETRY %zu/%zu] %s: %s", retry + 1, max_retries, *errmsg, url); } SYSDEBUG("Configuring curl"); diff --git a/src/lib/core/envctl.c b/src/lib/core/envctl.c index 5987616..9069a7f 100644 --- a/src/lib/core/envctl.c +++ b/src/lib/core/envctl.c @@ -85,9 +85,8 @@ unsigned envctl_get_flags(const struct EnvCtl *envctl, const char *name) { envctl_decode_index(poll_index, &state, &id, &name_id); if (!state) { return 0; - } else { - fprintf(stderr, "managed environment variable: %s\n", name); } + SYSINFO("managed environment variable: %s", name); return envctl->item[id]->flags; } @@ -106,14 +105,15 @@ void envctl_do_required(const struct EnvCtl *envctl, int verbose) { continue; } if (code == STASIS_ENVCTL_RET_FAIL) { - msg(STASIS_MSG_ERROR, "\n%s%s must be defined.\n", name, STASIS_COLOR_RESET); + SYSERROR("%s%s must be defined.", name, STASIS_COLOR_RESET); failed++; + continue; } - msg(STASIS_MSG_ERROR, "\nan unknown envctl callback code occurred: %d\n", code); + SYSWARN("an unknown envctl callback code occurred: %d", code); } if (failed) { - msg(STASIS_MSG_ERROR, "Environment check failed with %d error(s)\n", failed); + SYSERROR("Environment check failed with %d error(s)", failed); exit(1); } } diff --git a/src/lib/core/environment.c b/src/lib/core/environment.c index d81c3d1..4258004 100644 --- a/src/lib/core/environment.c +++ b/src/lib/core/environment.c @@ -74,7 +74,7 @@ void runtime_export(RuntimeEnv *env, char **keys) { char *_sh = getenv("SHELL"); char *sh = path_basename(_sh); if (sh == NULL) { - fprintf(stderr, "echo SHELL environment variable is not defined"); + SYSERROR("echo SHELL environment variable is not defined"); exit(1); } diff --git a/src/lib/core/github.c b/src/lib/core/github.c index 7c20fa4..992ab32 100644 --- a/src/lib/core/github.c +++ b/src/lib/core/github.c @@ -15,7 +15,7 @@ static size_t writer(const void *contents, size_t size, size_t nmemb, void *resu char *ptr = realloc(content->data, content->len + newlen + 1); if (!ptr) { - perror("realloc failed"); + SYSERROR("realloc failed"); return 0; } @@ -89,8 +89,7 @@ int get_github_release_notes(const char *api_token, const char *repo, const char curl_easy_cleanup(curl); if(res != CURLE_OK) { - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(res)); + SYSERROR("curl_easy_perform() failed: %s", curl_easy_strerror(res)); return -1; } @@ -122,14 +121,14 @@ int get_github_release_notes(const char *api_token, const char *repo, const char if (data_mark) { *data_mark = '\0'; } - fprintf(stderr, "GitHub API Error: '%s'\n", data_offset); - fprintf(stderr, "URL: %s\n", endpoint_url); - fprintf(stderr, "POST: %s\n", endpoint_post_fields); + SYSERROR("GitHub API Error: '%s'", data_offset); + SYSERROR("URL: %s", endpoint_url); + SYSERROR("POST: %s", endpoint_post_fields); guard_free(content.data); return -1; } } else { - fprintf(stderr, "Unknown error\n"); + SYSERROR("Unknown error"); guard_free(content.data); return -1; } diff --git a/src/lib/core/ini.c b/src/lib/core/ini.c index 183aa6b..81c75ac 100644 --- a/src/lib/core/ini.c +++ b/src/lib/core/ini.c @@ -601,7 +601,8 @@ struct INIFILE *ini_open(const char *filename) { char *section_name = substring_between(line, "[]"); if (!section_name) { - fprintf(stderr, "error: invalid section syntax, line %zu: '%s'\n", i + 1, line); + SYSERROR("invalid section syntax, line %zu: '%s'", i + 1, line); + ini_free(&ini); return NULL; } diff --git a/src/lib/core/multiprocessing.c b/src/lib/core/multiprocessing.c index ffc6b95..f431dd3 100644 --- a/src/lib/core/multiprocessing.c +++ b/src/lib/core/multiprocessing.c @@ -24,7 +24,7 @@ static double get_task_interval_duration(const struct MultiProcessingTask *task) static void update_task_interval_start(struct MultiProcessingTask *task) { // Record the task stop time if (clock_gettime(CLOCK_REALTIME, &task->interval_data.t_start) < 0) { - perror("clock_gettime"); + SYSERROR("realtime clock unavailable"); exit(1); } } @@ -32,7 +32,7 @@ static void update_task_interval_start(struct MultiProcessingTask *task) { static void update_task_interval_elapsed(struct MultiProcessingTask *task) { // Record the interval stop time if (clock_gettime(CLOCK_REALTIME, &task->interval_data.t_stop) < 0) { - perror("clock_gettime"); + SYSERROR("realtime clock unavailable"); exit(1); } task->interval_data.duration = get_task_interval_duration(task); @@ -41,14 +41,14 @@ static void update_task_interval_elapsed(struct MultiProcessingTask *task) { static void update_task_start(struct MultiProcessingTask *task) { // Record the task start time if (clock_gettime(CLOCK_REALTIME, &task->time_data.t_start) < 0) { - perror("clock_gettime"); + SYSERROR("realtime clock unavailable"); exit(1); } } static void update_task_elapsed(struct MultiProcessingTask *task) { // Record the task stop time if (clock_gettime(CLOCK_REALTIME, &task->time_data.t_stop) < 0) { - perror("clock_gettime"); + SYSERROR("realtime clock unavailable"); exit(1); } task->time_data.duration = get_task_duration(task); @@ -76,22 +76,25 @@ int child(struct MultiProcessingPool *pool, struct MultiProcessingTask *task) { if (globals.enable_task_logging) { snprintf(task->log_file + strlen(task->log_file), sizeof(task->log_file) - strlen(task->log_file), "task-%zu-%d.log", mp_global_task_count, task->parent_pid); + SYSDEBUG("using log file: %s", task->log_file); } fp_log = freopen(task->log_file, "w+", stdout); if (!fp_log) { fprintf(stderr, "unable to open '%s' for writing: %s\n", task->log_file, strerror(errno)); + SYSERROR("unable to open '%s' for writing: %s", task->log_file, strerror(errno)); return -1; } int fd = -1; if ((fd = dup2(STDOUT_FILENO, STDERR_FILENO)) < 0) { SYSERROR("%s", "Unable to redirect stderr to stdout"); + SYSERROR("Unable to redirect stderr to stdout"); fclose(fp_log); return -1; } // Generate timestamp for log header - time_t t = time(NULL); + const time_t t = time(NULL); char *timebuf = ctime(&t); if (timebuf) { // strip line feed from timestamp @@ -131,7 +134,7 @@ int parent(struct MultiProcessingPool *pool, struct MultiProcessingTask *task, p // Check child's status pid_t code = waitpid(pid, child_status, WUNTRACED | WCONTINUED | WNOHANG); if (code < 0) { - perror("waitpid failed"); + SYSERROR("waitpid failed"); return -1; } return 0; @@ -144,6 +147,7 @@ static int mp_task_fork(struct MultiProcessingPool *pool, struct MultiProcessing int parent_status = 0; int child_status = 0; if (pid == -1) { + SYSERROR("fork failed"); return -1; } if (pid == 0) { @@ -164,7 +168,7 @@ struct MultiProcessingTask *mp_pool_task(struct MultiProcessingPool *pool, const SYSDEBUG("Using slot %zu of %zu", pool->num_used, pool->num_alloc); pool->num_used++; } else { - fprintf(stderr, "Maximum number of tasks reached\n"); + SYSERROR("Maximum number of tasks reached"); return NULL; } @@ -268,6 +272,7 @@ void mp_pool_show_summary(struct MultiProcessingPool *pool) { static int show_log_contents(FILE *stream, struct MultiProcessingTask *task) { FILE *fp = fopen(task->log_file, "r"); if (!fp) { + SYSERROR("Failed to open log file for reading: %s, %s", task->log_file, strerror(errno)); return -1; } char buf[STASIS_BUFSIZ] = {0}; @@ -296,7 +301,7 @@ int mp_pool_kill(struct MultiProcessingPool *pool, int signum) { status = kill(slot->pid, signum); semaphore_post(&pool->semaphore); if (status && errno != ESRCH) { - fprintf(stderr, "Task '%s' (pid: %d) did not respond: %s\n", slot->ident, slot->pid, strerror(errno)); + SYSERROR("Task '%s' (pid: %d) did not respond: %s", slot->ident, slot->pid, strerror(errno)); } else { // Wait for process to handle the signal, then set the status accordingly if (waitpid(slot->pid, &status, 0) >= 0) { @@ -349,7 +354,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { if (slot->status == MP_POOL_TASK_STATUS_INITIAL) { slot->_startup = time(NULL); if (mp_task_fork(pool, slot)) { - fprintf(stderr, "%s: mp_task_fork failed\n", slot->ident); + SYSERROR("%s: mp_task_fork failed", slot->ident); kill(0, SIGTERM); } } @@ -363,7 +368,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { // forever. This protects the program from entering an // infinite loop. SYSDEBUG("slot %zu: hang_check=%zu >= pool->num_used=%zu", i, hang_check, pool->num_used); - SYSERROR("%s is deadlocked\n", pool->ident); + SYSERROR("%s is deadlocked", pool->ident); failures++; goto pool_deadlocked; } @@ -422,13 +427,13 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { printf("%s Task ended (status: %d)\n", progress, status_exit); tasks_complete++; } else { - fprintf(stderr, "%s Task state is unknown (0x%04X)\n", progress, status); + SYSWARN("%s Task state is unknown (0x%04X)", progress, status); } if (globals.enable_task_logging) { // Show the log (always) if (show_log_contents(stdout, slot)) { - perror(slot->log_file); + SYSWARN("%s Task has no log file", slot->ident); } } @@ -452,17 +457,17 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { // Clean up logs and scripts left behind by the task if (globals.enable_task_logging) { if (remove(slot->log_file)) { - fprintf(stderr, "%s Unable to remove log file: '%s': %s\n", progress, slot->parent_script, strerror(errno)); + SYSWARN("%s Unable to remove log file: '%s': %s", progress, slot->parent_script, strerror(errno)); } } if (remove(slot->parent_script)) { - fprintf(stderr, "%s Unable to remove temporary script '%s': %s\n", progress, slot->parent_script, strerror(errno)); + SYSWARN("%s Unable to remove temporary script '%s': %s", progress, slot->parent_script, strerror(errno)); } // Update progress and tell the poller to ignore the PID. The process is gone. slot->pid = MP_POOL_PID_UNUSED; } else if (pid < 0) { - fprintf(stderr, "waitpid failed: %s\n", strerror(errno)); + SYSERROR("waitpid failed: %s", strerror(errno)); return -1; } else { // Track the number of seconds elapsed for each task. @@ -533,26 +538,29 @@ struct MultiProcessingPool *mp_pool_init(const char *ident, const char *log_root pool->num_alloc = MP_POOL_TASK_MAX; // Create the log directory + SYSDEBUG("Creating log directory: %s", pool->log_root); if (mkdirs(log_root, 0700) < 0) { if (errno != EEXIST) { - perror(log_root); + SYSERROR("%s: unable to create directory", log_root); mp_pool_free(&pool); return NULL; } } // Task array is shared with children + SYSDEBUG("Memory mapping pool task array"); pool->task = mmap(NULL, (pool->num_alloc + 1) * sizeof(*pool->task), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (pool->task == MAP_FAILED) { - perror("mmap"); + SYSERROR("unable to memory map pool task"); mp_pool_free(&pool); return NULL; } + SYSDEBUG("initializing pool semaphore"); char semaphore_name[255] = {0}; snprintf(semaphore_name, sizeof(semaphore_name), "stasis_mp_%s", ident); if (semaphore_init(&pool->semaphore, semaphore_name, 1) != 0) { - fprintf(stderr, "unable to initialize semaphore\n"); + SYSERROR("unable to initialize pool semaphore"); mp_pool_free(&pool); return NULL; } @@ -563,6 +571,7 @@ struct MultiProcessingPool *mp_pool_init(const char *ident, const char *log_root } void mp_pool_free(struct MultiProcessingPool **pool) { + SYSDEBUG("freeing pool"); if (!isempty((*pool)->semaphore.name)) { semaphore_destroy(&(*pool)->semaphore); } @@ -581,8 +590,9 @@ void mp_pool_free(struct MultiProcessingPool **pool) { // Unmap the pool if ((*pool)) { if (munmap((*pool), sizeof(*(*pool))) < 0) { - perror("munmap"); + SYSWARN("munmap failed: %s", strerror(errno)); } (*pool) = NULL; } + SYSDEBUG("pool freed"); }
\ No newline at end of file diff --git a/src/lib/core/recipe.c b/src/lib/core/recipe.c index e5769bb..0ee1ef8 100644 --- a/src/lib/core/recipe.c +++ b/src/lib/core/recipe.c @@ -21,8 +21,8 @@ int recipe_clone(char *recipe_dir, char *url, char *gitref, char **result) { if (!access(destdir, F_OK)) { if (!strcmp(destdir, "/")) { - fprintf(stderr, "STASIS is misconfigured. Please check your output path(s) immediately.\n"); - fprintf(stderr, "recipe_dir = '%s'\nreponame = '%s'\ndestdir = '%s'\n", + SYSERROR("STASIS is misconfigured. Please check your output path(s) immediately."); + SYSERROR("recipe_dir = '%s'\nreponame = '%s'\ndestdir = '%s'", recipe_dir, reponame, destdir); exit(1); } diff --git a/src/lib/core/relocation.c b/src/lib/core/relocation.c index 348bad1..8204101 100644 --- a/src/lib/core/relocation.c +++ b/src/lib/core/relocation.c @@ -112,7 +112,7 @@ int file_replace_text(const char* filename, const char* target, const char* repl FILE *fp = fopen(filename, "r"); if (!fp) { - fprintf(stderr, "unable to open for reading: %s\n", filename); + SYSERROR("unable to open for reading: %s", filename); return -1; } diff --git a/src/lib/core/str.c b/src/lib/core/str.c index 5df7372..501c232 100644 --- a/src/lib/core/str.c +++ b/src/lib/core/str.c @@ -212,7 +212,8 @@ char *join_ex(char *separator, ...) { // Initialize array argv = calloc(argc + 1, sizeof(char **)); if (argv == NULL) { - perror("join_ex calloc failed"); + SYSERROR("calloc failed: %s", strerror(errno)); + va_end(ap); return NULL; } @@ -546,7 +547,7 @@ char *normalize_space(char *s) { } if (!(tmp = strdup(s))) { - perror("could not allocate memory for temporary string"); + SYSERROR("could not allocate memory for temporary string"); return NULL; } char *tmp_orig = tmp; diff --git a/src/lib/core/strlist.c b/src/lib/core/strlist.c index 0d25a66..526a1c9 100644 --- a/src/lib/core/strlist.c +++ b/src/lib/core/strlist.c @@ -45,7 +45,7 @@ void strlist_append(struct StrList **pStrList, char *str) { tmp = realloc((*pStrList)->data, ((*pStrList)->num_alloc + 1) * sizeof(char *)); if (tmp == NULL) { guard_strlist_free(pStrList); - perror("failed to append to array"); + SYSERROR("failed to append to array: %s", strerror(errno)); exit(1); } (*pStrList)->data = tmp; @@ -437,7 +437,7 @@ void strlist_set(struct StrList **pStrList, size_t index, char *value) { } else { tmp = realloc((*pStrList)->data[index], (strlen(value) + 1) * sizeof(char *)); if (!tmp) { - perror("realloc strlist_set replacement value"); + SYSERROR("strlist_set replacement realloc failed: %s", strerror(errno)); return; } else if (tmp != (*pStrList)->data[index]) { (*pStrList)->data[index] = tmp; @@ -750,7 +750,7 @@ long double strlist_item_as_long_double(struct StrList *pStrList, size_t index) struct StrList *strlist_init() { struct StrList *pStrList = calloc(1, sizeof(struct StrList)); if (pStrList == NULL) { - perror("failed to allocate array"); + SYSERROR("failed to allocate array: %s", strerror(errno)); return NULL; } pStrList->num_inuse = 0; diff --git a/src/lib/core/system.c b/src/lib/core/system.c index 06ca7bf..f0fd38f 100644 --- a/src/lib/core/system.c +++ b/src/lib/core/system.c @@ -41,7 +41,7 @@ int shell(struct Process *proc, char *args) { pid_t pid = fork(); if (pid == -1) { - fprintf(stderr, "fork failed\n"); + SYSERROR("fork failed"); guard_free(t_name); fclose(tp); exit(1); @@ -52,7 +52,7 @@ int shell(struct Process *proc, char *args) { if (strlen(proc->f_stdout)) { fp_out = freopen(proc->f_stdout, "w+", stdout); if (!fp_out) { - fprintf(stderr, "Unable to redirect stdout to %s: %s\n", proc->f_stdout, strerror(errno)); + SYSERROR("Unable to redirect stdout to %s: %s", proc->f_stdout, strerror(errno)); exit(1); } } @@ -61,7 +61,7 @@ int shell(struct Process *proc, char *args) { if (!proc->redirect_stderr) { fp_err = freopen(proc->f_stderr, "w+", stderr); if (!fp_err) { - fprintf(stderr, "Unable to redirect stderr to %s: %s\n", proc->f_stdout, strerror(errno)); + SYSERROR("Unable to redirect stderr to %s: %s", proc->f_stdout, strerror(errno)); if (fp_out) { fclose(fp_out); } @@ -73,7 +73,7 @@ int shell(struct Process *proc, char *args) { if (proc->redirect_stderr) { if (fp_err) { if (dup2(fileno(fp_err), STDERR_FILENO) < 0) { - fprintf(stderr, "Unable to redirect stderr to %s: %s\n", proc->f_stderr, strerror(errno)); + SYSERROR("Unable to redirect stderr to %s: %s", proc->f_stderr, strerror(errno)); if (fp_out) { fclose(fp_out); } @@ -83,7 +83,7 @@ int shell(struct Process *proc, char *args) { } else { // redirect stderr to stdout if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { - fprintf(stderr, "Unable to redirect stderr to stdout: %s\n", strerror(errno)); + SYSERROR("Unable to redirect stderr to stdout: %s", strerror(errno)); if (fp_out) { fclose(fp_out); } @@ -97,13 +97,13 @@ int shell(struct Process *proc, char *args) { if (waitpid(pid, &status, WUNTRACED) > 0) { if (WIFEXITED(status) && WEXITSTATUS(status)) { if (WEXITSTATUS(status) == 127) { - fprintf(stderr, "execv failed\n"); + SYSERROR("execv failed"); } } else if (WIFSIGNALED(status)) { - fprintf(stderr, "signal received: %d\n", WIFSIGNALED(status)); + SYSWARN("signal received: %d", WIFSIGNALED(status)); } } else { - fprintf(stderr, "waitpid() failed\n"); + SYSERROR("waitpid() failed"); } } diff --git a/src/lib/core/template.c b/src/lib/core/template.c index cdf8e58..00e0058 100644 --- a/src/lib/core/template.c +++ b/src/lib/core/template.c @@ -168,7 +168,7 @@ char *tpl_render(char *str) { output = calloc(output_bytes, sizeof(*output)); if (!output) { - perror("unable to allocate output buffer"); + SYSERROR("unable to allocate output buffer: %s", strerror(errno)); return NULL; } @@ -218,7 +218,7 @@ char *tpl_render(char *str) { // Find closing brace b_close = strstr(&pos[off], "}}"); if (!b_close) { - fprintf(stderr, "error while templating '%s'\n\nunbalanced brace at position %zu\n", str, z); + SYSERROR("while templating '%s'\n\nunbalanced brace at position %zu", str, z); guard_free(output); return NULL; } else { @@ -240,7 +240,7 @@ char *tpl_render(char *str) { char *param_begin = strchr(func_name_temp, '('); if (!param_begin) { - fprintf(stderr, "At position %zu in %s\nfunction name must be followed by a '('\n", off, key); + SYSERROR("At position %zu in %s\nfunction name must be followed by a '('", off, key); guard_free(output); return NULL; } @@ -248,7 +248,7 @@ char *tpl_render(char *str) { param_begin++; char *param_end = strrchr(param_begin, ')'); if (!param_end) { - fprintf(stderr, "At position %zu in %s\nfunction arguments must be closed with a ')'\n", off, key); + SYSERROR("At position %zu in %s\nfunction arguments must be closed with a ')'", off, key); guard_free(output); return NULL; } @@ -265,7 +265,7 @@ char *tpl_render(char *str) { return NULL; } if (params_count > frame->argc || params_count < frame->argc) { - fprintf(stderr, "At position %zu in %s\nIncorrect number of arguments for function: %s (expected %d, got %d)\n", off, key, frame->key, frame->argc, params_count); + SYSERROR("At position %zu in %s\nIncorrect number of arguments for function: %s (expected %d, got %d)", off, key, frame->key, frame->argc, params_count); value = strdup(""); } else { for (size_t p = 0; p < sizeof(frame->argv) / sizeof(*frame->argv) && params[p] != NULL; p++) { @@ -276,7 +276,7 @@ char *tpl_render(char *str) { char *func_result = NULL; int func_status = 0; if ((func_status = frame->func(frame, &func_result))) { - fprintf(stderr, "%s returned non-zero status: %d\n", frame->key, func_status); + SYSERROR("%s returned non-zero status: %d", frame->key, func_status); } value = strdup(func_result ? func_result : ""); SYSDEBUG("Returned from function: %s (status: %d)\nData OUT\n--------\n'%s'", k, func_status, value); diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index 264f23d..54c3dce 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -182,7 +182,6 @@ char **file_readlines(const char *filename, size_t start, size_t limit, ReaderFn } if (fp == NULL) { - perror(filename); SYSERROR("failed to open %s for reading", filename); return NULL; } @@ -303,7 +302,7 @@ int touch(const char *filename) { FILE *fp = fopen(filename, "w"); if (!fp) { - perror(filename); + SYSERROR("unable to open %s for writing", filename); return 1; } fclose(fp); @@ -385,7 +384,11 @@ char *git_describe(const char *path) { if (!pp) { return NULL; } - fgets(version, sizeof(version) - 1, pp); + if (fgets(version, sizeof(version) - 1, pp) == NULL) { + pclose(pp); + popd(); + return NULL; + } strip(version); pclose(pp); popd(); @@ -398,7 +401,7 @@ char *git_rev_parse(const char *path, char *args) { memset(version, 0, sizeof(version)); if (isempty(args)) { - fprintf(stderr, "git_rev_parse args cannot be empty\n"); + SYSERROR("git_rev_parse args cannot be empty"); return NULL; } @@ -514,6 +517,10 @@ char *xmkstemp(FILE **fp, const char *mode) { snprintf(t_name, sizeof(t_name), "%s/%s", tmpdir, "STASIS.XXXXXX"); fd = mkstemp(t_name); + if (fd < 0) { + SYSERROR("unable to create temporary file: %s", t_name); + return NULL; + } *fp = fdopen(fd, mode); if (!*fp) { // unable to open, die @@ -632,11 +639,12 @@ int xml_pretty_print_in_place(const char *filename, const char *pretty_print_pro } if (copy2(tempfile, filename, CT_PERM)) { - goto pretty_print_failed; + SYSWARN("unable to copy: '%s' -> '%s'", tempfile, filename); } if (remove(tempfile)) { goto pretty_print_failed; + SYSWARN("unable to remove temporary file: %s", tempfile); } fclose(fp); @@ -891,9 +899,15 @@ int env_manipulate_pathstr(const char *key, char *path, int mode) { char *system_path_new = NULL; if (mode & PM_APPEND) { - asprintf(&system_path_new, "%s%s%s", system_path_old, PATH_SEP, path); + if (asprintf(&system_path_new, "%s%s%s", system_path_old, PATH_SEP, path) < 0 || !system_path_new) { + SYSERROR("%s", "Unable to allocate memory to update PATH"); + return -1; + } } else if (mode & PM_PREPEND) { - asprintf(&system_path_new, "%s%s%s", path, PATH_SEP, system_path_old); + if (asprintf(&system_path_new, "%s%s%s", path, PATH_SEP, system_path_old) < 0 || !system_path_new) { + SYSERROR("%s", "Unable to allocate memory to update PATH"); + return -1; + } } if (!system_path_new) { @@ -990,12 +1004,10 @@ int grow(const size_t size_new, size_t *size_orig, char **data) { char *tmp = realloc(*data, new_size); if (!tmp) { - perror("realloc failed"); + SYSERROR("realloc failed"); return -1; } - if (tmp != *data) { - *data = tmp; - } + *data = tmp; *size_orig = new_size; } return 0; @@ -1041,7 +1053,7 @@ static int read_vcs_records(const size_t line, char **data) { const char *vcs = vcs_name[i]; char *data_local = strdup(*data); if (!data_local) { - fprintf(stderr, "Out of memory\n"); + SYSERROR("out of memory"); return -1; } diff --git a/src/lib/core/wheel.c b/src/lib/core/wheel.c index ef491c9..ea2089a 100644 --- a/src/lib/core/wheel.c +++ b/src/lib/core/wheel.c @@ -139,7 +139,7 @@ static ssize_t wheel_parse_wheel(struct Wheel * pkg, const char * data) { break; } default: - fprintf(stderr, "warning: unhandled wheel key on line %zu:\nbuffer contents: '%s'\n", i, value); + SYSWARN("unhandled wheel key on line %zu:\nbuffer contents: '%s'", i, value); break; } guard_free(key); @@ -618,7 +618,7 @@ static ssize_t wheel_parse_metadata(struct WheelMetadata * const pkg, const char } case WHEEL_KEY_UNKNOWN: default: - fprintf(stderr, "warning: unhandled metadata key on line %zu:\nbuffer contents: '%s'\n", i, value); + SYSWARN("unhandled metadata key on line %zu:\nbuffer contents: '%s'", i, value); break; } guard_free(key); @@ -1205,7 +1205,7 @@ int wheel_show_info(const struct Wheel *wheel) { for (ssize_t i = 0; i < WHEEL_DIST_END_ENUM; i++) { const char *key = wheel_get_key_by_id(WHEEL_FROM_DIST, i); if (!key) { - fprintf(stderr, "wheel_get_key_by_id(%zi) failed\n", i); + SYSERROR("wheel_get_key_by_id(%zi) failed", i); return -1; } @@ -1213,7 +1213,7 @@ int wheel_show_info(const struct Wheel *wheel) { fflush(stdout); const struct WheelValue dist = wheel_get_value_by_id(wheel, WHEEL_FROM_DIST, i); if (wheel_value_error(&dist)) { - fprintf(stderr, "wheel_get_value_by_id(%zi) failed\n", i); + SYSERROR("wheel_get_value_by_id(%zi) failed", i); return -1; } switch (dist.type) { @@ -1274,7 +1274,7 @@ int wheel_show_info(const struct Wheel *wheel) { for (ssize_t i = 0; i < WHEEL_META_END_ENUM; i++) { const char *key = wheel_get_key_by_id(WHEEL_FROM_METADATA, i); if (!key) { - fprintf(stderr, "wheel_get_key_by_id(%zi) failed\n", i); + SYSERROR("wheel_get_key_by_id(%zi) failed", i); return -1; } printf("%s: ", key); @@ -1282,7 +1282,7 @@ int wheel_show_info(const struct Wheel *wheel) { const struct WheelValue pkg = wheel_get_value_by_id(wheel, WHEEL_FROM_METADATA, i); if (wheel_value_error(&pkg)) { - fprintf(stderr, "wheel_get_value_by_id(%zi) failed\n", i); + SYSERROR("wheel_get_value_by_id(%zi) failed", i); return -1; } switch (pkg.type) { diff --git a/src/lib/delivery/delivery.c b/src/lib/delivery/delivery.c index a150169..89074c8 100644 --- a/src/lib/delivery/delivery.c +++ b/src/lib/delivery/delivery.c @@ -449,7 +449,7 @@ void delivery_defer_packages(struct Delivery *ctx, int type) { } if (PKG_INDEX_PROVIDES_FAILED(upstream_exists)) { - fprintf(stderr, "%s's existence command failed for '%s': %s\n", + SYSERROR("%s's existence command failed for '%s': %s", mode, name, pkg_index_provides_strerror(upstream_exists)); exit(1); } @@ -474,7 +474,7 @@ void delivery_defer_packages(struct Delivery *ctx, int type) { } if (!strlist_count(deferred)) { - msg(STASIS_MSG_WARN | STASIS_MSG_L2, "No %s packages were filtered by test definitions\n", mode); + SYSWARN("No %s packages were filtered by test definitions\n", mode); } else { if (DEFER_CONDA == type) { guard_strlist_free(&ctx->conda.conda_packages); diff --git a/src/lib/delivery/delivery_artifactory.c b/src/lib/delivery/delivery_artifactory.c index 0926d9c..3c1cff3 100644 --- a/src/lib/delivery/delivery_artifactory.c +++ b/src/lib/delivery/delivery_artifactory.c @@ -49,7 +49,7 @@ int delivery_artifact_upload(struct Delivery *ctx) { int status = 0; if (jfrt_auth_init(&ctx->deploy.jfrog_auth)) { - fprintf(stderr, "Failed to initialize Artifactory authentication context\n"); + SYSERROR("Failed to initialize Artifactory authentication context"); return -1; } @@ -60,9 +60,9 @@ int delivery_artifact_upload(struct Delivery *ctx) { jfrt_upload_init(&ctx->deploy.jfrog[i].upload_ctx); if (!globals.jfrog.repo) { - msg(STASIS_MSG_WARN, "Artifactory repository path is not configured!\n"); - fprintf(stderr, "set STASIS_JF_REPO environment variable...\nOr append to configuration file:\n\n"); - fprintf(stderr, "[deploy:artifactory]\nrepo = example/generic/repo/path\n\n"); + SYSWARN("Artifactory repository path is not configured!"); + SYSWARN("set STASIS_JF_REPO environment variable...\nOr append to configuration file:\n"); + SYSWARN("[deploy:artifactory]\nrepo = example/generic/repo/path\n"); status++; break; } else if (!ctx->deploy.jfrog[i].repo) { @@ -71,7 +71,7 @@ int delivery_artifact_upload(struct Delivery *ctx) { if (!ctx->deploy.jfrog[i].repo || isempty(ctx->deploy.jfrog[i].repo) || !strlen(ctx->deploy.jfrog[i].repo)) { // Unlikely to trigger if the config parser is working correctly - msg(STASIS_MSG_ERROR, "Artifactory repository path is empty. Cannot continue.\n"); + SYSERROR("Artifactory repository path is empty. Cannot continue."); status++; break; } @@ -81,7 +81,7 @@ int delivery_artifact_upload(struct Delivery *ctx) { ctx->deploy.jfrog[i].upload_ctx.build_number = ctx->info.build_number; if (jfrog_cli_rt_ping(&ctx->deploy.jfrog_auth)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Unable to contact artifactory server: %s\n", ctx->deploy.jfrog_auth.url); + SYSERROR("Unable to contact artifactory server: %s", ctx->deploy.jfrog_auth.url); return -1; } @@ -104,7 +104,7 @@ int delivery_artifact_upload(struct Delivery *ctx) { ctx->deploy.jfrog[0].upload_ctx.build_number); } } else { - msg(STASIS_MSG_WARN | STASIS_MSG_L2, "Artifactory build info upload is disabled by CLI argument\n"); + SYSWARN("Artifactory build info upload is disabled by CLI argument"); } return status; @@ -112,7 +112,7 @@ int delivery_artifact_upload(struct Delivery *ctx) { int delivery_mission_render_files(struct Delivery *ctx) { if (!ctx->storage.mission_dir) { - fprintf(stderr, "Mission directory is not configured. Context not initialized?\n"); + SYSERROR("Mission directory is not configured. Context not initialized?"); return -1; } struct Data { @@ -124,7 +124,7 @@ int delivery_mission_render_files(struct Delivery *ctx) { memset(&data, 0, sizeof(data)); data.src = calloc(PATH_MAX, sizeof(*data.src)); if (!data.src) { - perror("data.src"); + SYSERROR("unable to allocate memory for data.src: %s", strerror(errno)); return -1; } @@ -154,14 +154,14 @@ int delivery_mission_render_files(struct Delivery *ctx) { char *contents = calloc(st.st_size + 1, sizeof(*contents)); if (!contents) { - perror("template file contents"); + SYSERROR("unable to allocate memory for template file contents: %s", strerror(errno)); guard_free(data.dest); continue; } FILE *fp = fopen(data.src, "rb"); if (!fp) { - perror(data.src); + SYSERROR("unable to open source template file: %s", strerror(errno)); guard_free(contents); guard_free(data.dest); continue; @@ -194,7 +194,7 @@ int delivery_series_sync(struct Delivery *ctx) { struct JFRT_Download dl = {0}; if (jfrt_auth_init(&ctx->deploy.jfrog_auth)) { - fprintf(stderr, "Failed to initialize Artifactory authentication context\n"); + SYSERROR("Failed to initialize Artifactory authentication context"); return -1; // error } diff --git a/src/lib/delivery/delivery_build.c b/src/lib/delivery/delivery_build.c index 3eb2714..66f9126 100644 --- a/src/lib/delivery/delivery_build.c +++ b/src/lib/delivery/delivery_build.c @@ -9,11 +9,11 @@ int delivery_build_recipes(struct Delivery *ctx) { char *recipe_dir = NULL; if (ctx->tests->test[i]->build_recipe) { // build a conda recipe if (recipe_clone(ctx->storage.build_recipes_dir, ctx->tests->test[i]->build_recipe, NULL, &recipe_dir)) { - fprintf(stderr, "Encountered an issue while cloning recipe for: %s\n", ctx->tests->test[i]->name); + SYSERROR("Encountered an issue while cloning recipe for: %s", ctx->tests->test[i]->name); return -1; } if (!recipe_dir) { - fprintf(stderr, "BUG: recipe_clone() succeeded but recipe_dir is NULL: %s\n", strerror(errno)); + SYSERROR("BUG: recipe_clone() succeeded but recipe_dir is NULL: %s", strerror(errno)); return -1; } int recipe_type = recipe_get_type(recipe_dir); @@ -114,7 +114,7 @@ int delivery_build_recipes(struct Delivery *ctx) { } popd(); } else { - fprintf(stderr, "Unable to enter recipe directory %s: %s\n", recipe_dir, strerror(errno)); + SYSERROR("Unable to enter recipe directory %s: %s", recipe_dir, strerror(errno)); guard_free(recipe_dir); return -1; } @@ -360,7 +360,7 @@ int delivery_build_wheels_manylinux(struct Delivery *ctx, const char *outdir) { outdir); if (manylinux_build_status) { - msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "manylinux build failed (%d)", manylinux_build_status); + SYSERROR("manylinux build failed (%d)", manylinux_build_status); guard_free(script); return -1; } @@ -376,8 +376,8 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { const int use_builder_manylinux = strcmp(globals.wheel_builder, "manylinux") == 0 && on_linux && docker_usable; if (!use_builder_build && !use_builder_cibuildwheel && !use_builder_manylinux) { - msg(STASIS_MSG_WARN, "Cannot build wheel for platform using: %s\n", globals.wheel_builder); - msg(STASIS_MSG_WARN, "Falling back to native toolchain.\n", globals.wheel_builder); + SYSWARN("Cannot build wheel for platform using: %s", globals.wheel_builder); + SYSWARN("Falling back to native toolchain.", globals.wheel_builder); use_builder_build = 1; } @@ -386,7 +386,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { result = strlist_init(); if (!result) { - perror("unable to allocate memory for string list"); + SYSERROR("unable to allocate memory for string list"); return NULL; } @@ -434,14 +434,14 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { const int dep_status = check_python_package_dependencies("."); if (dep_status) { - fprintf(stderr, "\nPlease replace all occurrences above with standard package specs:\n" + SYSERROR("Please replace all occurrences above with standard package specs:\n" "\n" " package==x.y.z\n" " package>=x.y.z\n" " package<=x.y.z\n" " ...\n" "\n"); - COE_CHECK_ABORT(dep_status, "Unreproducible delivery"); + COE_CHECK_ABORT(true, "Unreproducible delivery"); } strncpy(dname, ctx->tests->test[i]->name, sizeof(dname) - 1); @@ -449,13 +449,13 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { tolower_s(dname); snprintf(outdir, sizeof(outdir), "%s/%s", ctx->storage.wheel_artifact_dir, dname); if (mkdirs(outdir, 0755)) { - fprintf(stderr, "failed to create output directory: %s\n", outdir); + SYSERROR("failed to create output directory: %s", outdir); guard_strlist_free(&result); return NULL; } if (use_builder_manylinux) { if (delivery_build_wheels_manylinux(ctx, outdir)) { - fprintf(stderr, "failed to generate wheel package for %s-%s\n", ctx->tests->test[i]->name, + SYSERROR("failed to generate wheel package for %s-%s", ctx->tests->test[i]->name, ctx->tests->test[i]->version); guard_strlist_free(&result); guard_free(cmd); @@ -476,7 +476,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { } if (python_exec(cmd)) { - fprintf(stderr, "failed to generate wheel package for %s-%s\n", ctx->tests->test[i]->name, + SYSERROR("failed to generate wheel package for %s-%s", ctx->tests->test[i]->name, ctx->tests->test[i]->version); guard_strlist_free(&result); guard_free(cmd); @@ -490,7 +490,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { guard_free(cmd); popd(); } else { - fprintf(stderr, "Unable to enter source directory %s: %s\n", srcdir, strerror(errno)); + SYSERROR("Unable to enter source directory %s: %s", srcdir, strerror(errno)); guard_strlist_free(&result); return NULL; } diff --git a/src/lib/delivery/delivery_conda.c b/src/lib/delivery/delivery_conda.c index 6e96d56..117e6c9 100644 --- a/src/lib/delivery/delivery_conda.c +++ b/src/lib/delivery/delivery_conda.c @@ -70,7 +70,7 @@ void delivery_install_conda(char *install_script, char *conda_install_dir) { if (!access(conda_install_dir, F_OK)) { // directory exists so remove it if (rmtree(conda_install_dir)) { - perror("unable to remove previous installation"); + SYSERROR("unable to remove previous installation: %s", strerror(errno)); exit(1); } @@ -82,7 +82,7 @@ void delivery_install_conda(char *install_script, char *conda_install_dir) { install_script, conda_install_dir); if (shell_safe(&proc, cmd)) { - fprintf(stderr, "conda installation failed\n"); + SYSERROR("conda installation failed"); exit(1); } } else { @@ -94,7 +94,7 @@ void delivery_install_conda(char *install_script, char *conda_install_dir) { install_script, conda_install_dir); if (shell_safe(&proc, cmd)) { - fprintf(stderr, "conda installation failed\n"); + SYSERROR("conda installation failed"); exit(1); } } @@ -105,7 +105,7 @@ void delivery_install_conda(char *install_script, char *conda_install_dir) { void delivery_conda_enable(struct Delivery *ctx, char *conda_install_dir) { if (conda_activate(conda_install_dir, "base")) { - fprintf(stderr, "conda activation failed\n"); + SYSERROR("conda activation failed"); exit(1); } @@ -116,7 +116,7 @@ void delivery_conda_enable(struct Delivery *ctx, char *conda_install_dir) { snprintf(rcpath, sizeof(rcpath), "%s/%s", conda_install_dir, ".condarc"); setenv("CONDARC", rcpath, 1); if (runtime_replace(&ctx->runtime.environ, __environ)) { - perror("unable to replace runtime environment after activating conda"); + SYSERROR("unable to replace runtime environment after activating conda"); exit(1); } diff --git a/src/lib/delivery/delivery_docker.c b/src/lib/delivery/delivery_docker.c index 3177c96..79e9729 100644 --- a/src/lib/delivery/delivery_docker.c +++ b/src/lib/delivery/delivery_docker.c @@ -11,12 +11,12 @@ int delivery_docker(struct Delivery *ctx) { size_t total_build_args = strlist_count(ctx->deploy.docker.build_args); if (!has_registry) { - msg(STASIS_MSG_WARN | STASIS_MSG_L2, "No docker registry defined. You will need to manually re-tag the resulting image.\n"); + SYSWARN("No docker registry defined. You will need to manually re-tag the resulting image."); } if (!total_tags) { char default_tag[PATH_MAX]; - msg(STASIS_MSG_WARN | STASIS_MSG_L2, "No docker tags defined by configuration. Generating default tag(s).\n"); + SYSWARN("No docker tags defined by configuration. Generating default tag(s)."); // generate local tag memset(default_tag, 0, sizeof(default_tag)); snprintf(default_tag, sizeof(default_tag), "%s:%s-py%s", ctx->meta.name, ctx->info.build_name, ctx->meta.python_compact); @@ -68,13 +68,13 @@ int delivery_docker(struct Delivery *ctx) { snprintf(delivery_file, sizeof(delivery_file), "%s/%s.yml", ctx->storage.delivery_dir, ctx->info.release_name); if (access(delivery_file, F_OK) < 0) { - fprintf(stderr, "docker build cannot proceed without delivery file: %s\n", delivery_file); + SYSERROR("docker build cannot proceed without delivery file: %s", delivery_file); return -1; } snprintf(dest, sizeof(dest), "%s/%s.yml", ctx->storage.build_docker_dir, ctx->info.release_name); if (copy2(delivery_file, dest, CT_PERM)) { - fprintf(stderr, "Failed to copy delivery file to %s: %s\n", dest, strerror(errno)); + SYSERROR("Failed to copy delivery file to %s: %s", dest, strerror(errno)); return -1; } @@ -85,7 +85,7 @@ int delivery_docker(struct Delivery *ctx) { memset(rsync_cmd, 0, sizeof(rsync_cmd)); snprintf(rsync_cmd, sizeof(rsync_cmd), "rsync -avi --progress '%s' '%s'", ctx->storage.conda_artifact_dir, dest); if (system(rsync_cmd)) { - fprintf(stderr, "Failed to copy conda artifacts to docker build directory\n"); + SYSERROR("Failed to copy conda artifacts to docker build directory"); return -1; } @@ -93,7 +93,7 @@ int delivery_docker(struct Delivery *ctx) { memset(rsync_cmd, 0, sizeof(rsync_cmd)); snprintf(rsync_cmd, sizeof(rsync_cmd), "rsync -avi --progress '%s' '%s'", ctx->storage.wheel_artifact_dir, dest); if (system(rsync_cmd)) { - fprintf(stderr, "Failed to copy wheel artifacts to docker build directory\n"); + SYSWARN("Failed to copy wheel artifacts to docker build directory. No wheels produced?"); } if (docker_build(ctx->storage.build_docker_dir, args, ctx->deploy.docker.capabilities.build)) { @@ -110,17 +110,17 @@ int delivery_docker(struct Delivery *ctx) { msg(STASIS_MSG_L2, "Executing image test script for %s\n", tag); if (ctx->deploy.docker.test_script) { if (isempty(ctx->deploy.docker.test_script)) { - msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "Image test script has no content\n"); + SYSWARN("Image test script has no content"); } else { int state; if ((state = docker_script(tag, "--rm", ctx->deploy.docker.test_script, 0))) { - msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "Non-zero exit (%d) from test script. %s image archive will not be generated.\n", state >> 8, tag); + SYSERROR("Non-zero exit (%d) from test script. %s image archive will not be generated.", state >> 8, tag); // test failed -- don't save the image return -1; } } } else { - msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "No image test script defined\n"); + SYSWARN("No image test script defined"); } // Test successful, save image diff --git a/src/lib/delivery/delivery_export.c b/src/lib/delivery/delivery_export.c index a973875..0321050 100644 --- a/src/lib/delivery/delivery_export.c +++ b/src/lib/delivery/delivery_export.c @@ -14,7 +14,7 @@ static void delivery_export_configuration(const struct Delivery *ctx) { SYSDEBUG("%s: opening", filename); FILE *spec = fopen(filename, "w+"); if (!spec) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "failed %s\n", filename); + SYSERROR("open failed %s", filename); exit(1); } SYSDEBUG("%s: writing", filename); @@ -32,7 +32,7 @@ static void delivery_export_configuration(const struct Delivery *ctx) { SYSDEBUG("%s: opening", filename); spec = fopen(filename, "w+"); if (!spec) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "failed %s\n", filename); + SYSERROR("open failed %s", filename); exit(1); } SYSDEBUG("%s: writing", filename); @@ -55,7 +55,7 @@ void delivery_export(const struct Delivery *ctx, char *envs[]) { char *name = envs[i]; msg(STASIS_MSG_L2, "Exporting %s\n", name); if (conda_env_export(name, ctx->storage.delivery_dir, name)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "failed %s\n", name); + SYSERROR("export failed %s", name); exit(1); } } diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index 8e673ff..c73e7f0 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -54,14 +54,14 @@ int delivery_init_tmpdir(struct Delivery *ctx) { // If the directory doesn't exist, create it if (access(tmpdir, F_OK) < 0) { if (mkdirs(tmpdir, 0755) < 0) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "Unable to create temporary storage directory: %s (%s)\n", tmpdir, strerror(errno)); + SYSERROR("Unable to create temporary storage directory: %s (%s)", tmpdir, strerror(errno)); goto l_delivery_init_tmpdir_fatal; } } // If we can't read, write, or execute, then die if (access(tmpdir, R_OK | W_OK | X_OK) < 0) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "%s requires at least 0755 permissions.\n"); + SYSERROR("%s requires at least 0755 permissions."); goto l_delivery_init_tmpdir_fatal; } @@ -73,12 +73,12 @@ int delivery_init_tmpdir(struct Delivery *ctx) { #if defined(STASIS_OS_LINUX) // If we can't execute programs, or write data to the file system at all, then die if ((st.f_flag & ST_NOEXEC) != 0) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "%s is mounted with noexec\n", tmpdir); + SYSERROR("%s is mounted with noexec", tmpdir); goto l_delivery_init_tmpdir_fatal; } #endif if ((st.f_flag & ST_RDONLY) != 0) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "%s is mounted read-only\n", tmpdir); + SYSERROR("%s is mounted read-only", tmpdir); goto l_delivery_init_tmpdir_fatal; } @@ -129,7 +129,7 @@ void delivery_init_dirs_stage1(struct Delivery *ctx) { char *rootdir = getenv("STASIS_ROOT"); if (rootdir) { if (isempty(rootdir)) { - fprintf(stderr, "STASIS_ROOT is set, but empty. Please assign a file system path to this environment variable.\n"); + SYSERROR("STASIS_ROOT is set, but empty. Please assign a file system path to this environment variable."); exit(1); } path_store(&ctx->storage.root, PATH_MAX, rootdir, ctx->info.build_name); @@ -140,9 +140,10 @@ void delivery_init_dirs_stage1(struct Delivery *ctx) { path_store(&ctx->storage.tools_dir, PATH_MAX, ctx->storage.root, "tools"); path_store(&ctx->storage.tmpdir, PATH_MAX, ctx->storage.root, "tmp"); if (delivery_init_tmpdir(ctx)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "Set $TMPDIR to a location other than %s\n", globals.tmpdir); - if (globals.tmpdir) + SYSERROR("Set $TMPDIR to a location other than %s", globals.tmpdir); + if (globals.tmpdir) { guard_free(globals.tmpdir); + } exit(1); } @@ -189,7 +190,7 @@ int delivery_init_platform(struct Delivery *ctx) { char archsuffix[20]; struct utsname uts; if (uname(&uts)) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "uname() failed: %s\n", strerror(errno)); + SYSERROR("uname() failed: %s", strerror(errno)); return -1; } @@ -242,7 +243,7 @@ int delivery_init_platform(struct Delivery *ctx) { long cpu_count = get_cpu_count(); if (!cpu_count) { - fprintf(stderr, "Unable to determine CPU count. Falling back to 1.\n"); + SYSERROR("Unable to determine CPU count. Falling back to 1."); cpu_count = 1; } char ncpus[100] = {0}; @@ -391,7 +392,7 @@ int delivery_exists(struct Delivery *ctx) { if (globals.enable_artifactory) { if (jfrt_auth_init(&ctx->deploy.jfrog_auth)) { - fprintf(stderr, "Failed to initialize Artifactory authentication context\n"); + SYSERROR("Failed to initialize Artifactory authentication context"); return -1; // error } diff --git a/src/lib/delivery/delivery_install.c b/src/lib/delivery/delivery_install.c index 6a6b746..4d52b82 100644 --- a/src/lib/delivery/delivery_install.c +++ b/src/lib/delivery/delivery_install.c @@ -436,7 +436,7 @@ int delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, cha exit(1); } else if (!whl) { // not found - fprintf(stderr, "No wheel packages found that match the description of '%s'", info->name); + SYSERROR("No wheel packages found that match the description of '%s'", info->name); } else { // found, replace the original version with newly detected version guard_free(info->version); @@ -471,7 +471,7 @@ int delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, cha } snprintf(args + strlen(args), args_alloc_len - strlen(args), fmt, req, info->version); } else { - fprintf(stderr, "Deferred package '%s' is not present in the tested package list!\n", name); + SYSERROR("Deferred package '%s' is not present in the tested package list!", name); guard_free(args); return -1; } diff --git a/src/lib/delivery/delivery_populate.c b/src/lib/delivery/delivery_populate.c index 546ce3b..cfa3da2 100644 --- a/src/lib/delivery/delivery_populate.c +++ b/src/lib/delivery/delivery_populate.c @@ -33,18 +33,18 @@ int populate_info(struct Delivery *ctx) { if (!ctx->info.time_info) { ctx->info.time_info = malloc(sizeof(*ctx->info.time_info)); if (!ctx->info.time_info) { - msg(STASIS_MSG_ERROR, "%s: Unable to allocate memory for time_info\n", strerror(errno)); + SYSERROR("%s: Unable to allocate memory for time_info", strerror(errno)); return -1; } if (!localtime_r(&ctx->info.time_now, ctx->info.time_info)) { - msg(STASIS_MSG_ERROR, "%s: localtime_r failed\n", strerror(errno)); + SYSERROR("%s: localtime_r failed", strerror(errno)); return -1; } } ctx->info.time_str_epoch = calloc(STASIS_TIME_STR_MAX, sizeof(*ctx->info.time_str_epoch)); if (!ctx->info.time_str_epoch) { - msg(STASIS_MSG_ERROR, "%s: Unable to allocate memory for Unix epoch string\n", strerror(errno)); + SYSERROR("%s: Unable to allocate memory for Unix epoch string", strerror(errno)); return -1; } snprintf(ctx->info.time_str_epoch, STASIS_TIME_STR_MAX - 1, "%li", ctx->info.time_now); @@ -89,7 +89,7 @@ int populate_delivery_cfg(struct Delivery *ctx, int render_mode) { if (!globals.wheel_builder) { globals.wheel_builder = ini_getval_str(cfg, "default", "wheel_builder", render_mode, &err); if (err) { - msg(STASIS_MSG_WARN, "wheel_builder is undefined. Falling back to system toolchain: 'build'.\n"); + SYSWARN("wheel_builder is undefined. Falling back to system toolchain: 'build'."); globals.wheel_builder = strdup("build"); if (!globals.wheel_builder) { SYSERROR("unable to allocate memory for default wheel_builder value"); @@ -257,7 +257,7 @@ int populate_delivery_ini(struct Delivery *ctx, int render_mode) { } if (delivery_format_str(ctx, &ctx->info.release_name, STASIS_NAME_MAX, ctx->rules.release_fmt)) { - fprintf(stderr, "Failed to generate release name. Format used: %s\n", ctx->rules.release_fmt); + SYSERROR("Failed to generate release name. Format used: %s", ctx->rules.release_fmt); return -1; } @@ -387,7 +387,7 @@ int populate_mission_ini(struct Delivery **ctx, int render_mode) { (*ctx)->_stasis_ini_fp.mission = ini_open(missionfile); struct INIFILE *ini = (*ctx)->_stasis_ini_fp.mission; if (!ini) { - msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to read mission configuration: %s, %s\n", missionfile, strerror(errno)); + SYSERROR("Failed to read mission configuration: %s, %s", missionfile, strerror(errno)); return -1; } (*ctx)->_stasis_ini_fp.mission_path = strdup(missionfile); diff --git a/src/lib/delivery/delivery_postprocess.c b/src/lib/delivery/delivery_postprocess.c index 0f7d948..63093b3 100644 --- a/src/lib/delivery/delivery_postprocess.c +++ b/src/lib/delivery/delivery_postprocess.c @@ -78,12 +78,12 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename, unsigned stage) header = delivery_get_release_header(ctx); SYSDEBUG("Release header:\n%s", header); if (!header) { - msg(STASIS_MSG_ERROR, "failed to generate release header string\n", filename); + SYSERROR("failed to generate release header string", filename); exit(1); } tempfile = xmkstemp(&tp, "w+"); if (!tempfile || !tp) { - msg(STASIS_MSG_ERROR, "%s: unable to create temporary file\n", strerror(errno)); + SYSERROR("%s: unable to create temporary file", strerror(errno)); exit(1); } SYSDEBUG("Writing header to temporary file: %s", tempfile); @@ -92,7 +92,7 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename, unsigned stage) // Read the original file char **contents = file_readlines(filename, 0, 0, NULL); if (!contents) { - msg(STASIS_MSG_ERROR, "%s: unable to read %s", filename); + SYSERROR("%s: unable to read %s", filename); exit(1); } @@ -136,7 +136,7 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename, unsigned stage) // Replace the original file with our temporary data if (copy2(tempfile, filename, CT_PERM) < 0) { - fprintf(stderr, "%s: could not rename '%s' to '%s'\n", strerror(errno), tempfile, filename); + SYSERROR("%s: could not rename '%s' to '%s'", strerror(errno), tempfile, filename); exit(1); } SYSDEBUG("Removing file: %s", tempfile); @@ -155,7 +155,7 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename, unsigned stage) file_replace_text(filename, "@CONDA_CHANNEL@", output, 0); } else { SYSDEBUG("Will replace conda channel with local conda artifact directory"); - msg(STASIS_MSG_WARN, "conda_staging_dir is not configured. Using fallback: '%s'\n", ctx->storage.conda_artifact_dir); + SYSWARN("conda_staging_dir is not configured. Using fallback: '%s'", ctx->storage.conda_artifact_dir); file_replace_text(filename, "@CONDA_CHANNEL@", ctx->storage.conda_artifact_dir, 0); } @@ -169,7 +169,7 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename, unsigned stage) file_replace_text(filename, "@PIP_ARGUMENTS@", output, 0); } else { SYSDEBUG("Will replace pip arguments with local wheel artifact directory"); - msg(STASIS_MSG_WARN, "wheel_staging_dir is not configured. Using fallback: '%s'\n", ctx->storage.wheel_artifact_dir); + SYSWARN("wheel_staging_dir is not configured. Using fallback: '%s'", ctx->storage.wheel_artifact_dir); snprintf(output, sizeof(output), "--extra-index-url file://%s", ctx->storage.wheel_artifact_dir); file_replace_text(filename, "@PIP_ARGUMENTS@", output, 0); } @@ -189,8 +189,7 @@ int delivery_copy_conda_artifacts(struct Delivery *ctx) { // One must run conda build at least once to create the "conda-bld" directory. // When this directory is missing there can be no build artifacts. if (access(conda_build_dir, F_OK) < 0) { - msg(STASIS_MSG_RESTRICT | STASIS_MSG_WARN | STASIS_MSG_L3, - "Skipped: 'conda build' has never been executed.\n"); + SYSWARN("Skipped: 'conda build' has never been executed."); return 0; } diff --git a/src/lib/delivery/delivery_show.c b/src/lib/delivery/delivery_show.c index f4ac825..1740688 100644 --- a/src/lib/delivery/delivery_show.c +++ b/src/lib/delivery/delivery_show.c @@ -108,7 +108,7 @@ void delivery_runtime_show(struct Delivery *ctx) { char *item = strlist_item(rt, i); if (!item) { // not supposed to occur - msg(STASIS_MSG_WARN | STASIS_MSG_L1, "Encountered unexpected NULL at record %zu of %zu of runtime array.\n", i); + SYSWARN("Encountered unexpected NULL in record %zu of %zu in runtime array.", i, total); return; } printf("%s\n", item); diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c index 732ec2b..65d0451 100644 --- a/src/lib/delivery/delivery_test.c +++ b/src/lib/delivery/delivery_test.c @@ -97,25 +97,25 @@ void delivery_tests_run(struct Delivery *ctx) { snprintf(globals.workaround.conda_reactivate, PATH_MAX - 1, "\nset +x; mamba activate ${CONDA_DEFAULT_ENV}; set -x\n"); if (!ctx->tests || !ctx->tests->num_used) { - msg(STASIS_MSG_WARN | STASIS_MSG_L2, "no tests are defined!\n"); + SYSWARN("no tests are defined!"); } else { pool[PARALLEL] = mp_pool_init("parallel", ctx->storage.tmpdir); if (!pool[PARALLEL]) { - perror("mp_pool_init/parallel"); + SYSERROR("mp_pool_init/parallel initialization failed"); exit(1); } pool[PARALLEL]->status_interval = globals.pool_status_interval; pool[SERIAL] = mp_pool_init("serial", ctx->storage.tmpdir); if (!pool[SERIAL]) { - perror("mp_pool_init/serial"); + SYSERROR("mp_pool_init/serial initialization failed"); exit(1); } pool[SERIAL]->status_interval = globals.pool_status_interval; pool[SETUP] = mp_pool_init("setup", ctx->storage.tmpdir); if (!pool[SETUP]) { - perror("mp_pool_init/setup"); + SYSERROR("mp_pool_init/setup initialization failed"); exit(1); } pool[SETUP]->status_interval = globals.pool_status_interval; @@ -148,8 +148,7 @@ void delivery_tests_run(struct Delivery *ctx) { } msg(STASIS_MSG_L2, "Loading tests for %s %s\n", test->name, test->version); if (!test->script || !strlen(test->script)) { - msg(STASIS_MSG_WARN | STASIS_MSG_L3, "Nothing to do. To fix, declare a 'script' in section: [test:%s]\n", - test->name); + SYSWARN("Nothing to do. To fix, declare a 'script' in section: [test:%s]", test->name); continue; } @@ -179,14 +178,14 @@ void delivery_tests_run(struct Delivery *ctx) { } else { int dep_status = check_python_package_dependencies("."); if (dep_status) { - fprintf(stderr, "\nPlease replace all occurrences above with standard package specs:\n" + SYSERROR("Please replace all occurrences above with standard package specs:\n" "\n" " package==x.y.z\n" " package>=x.y.z\n" " package<=x.y.z\n" " ...\n" "\n"); - COE_CHECK_ABORT(dep_status, "Unreproducible delivery"); + COE_CHECK_ABORT(true, "Unreproducible delivery"); } char *cmd = calloc(strlen(test->script) + STASIS_BUFSIZ, sizeof(*cmd)); @@ -387,7 +386,7 @@ int delivery_fixup_test_results(struct Delivery *ctx) { snprintf(path, sizeof(path), "%s/%s", ctx->storage.results_dir, rec->d_name); msg(STASIS_MSG_L3, "%s\n", rec->d_name); if (xml_pretty_print_in_place(path, STASIS_XML_PRETTY_PRINT_PROG, STASIS_XML_PRETTY_PRINT_ARGS)) { - msg(STASIS_MSG_L3 | STASIS_MSG_WARN, "Failed to rewrite file '%s'\n", rec->d_name); + SYSWARN("Failed to rewrite file '%s'", rec->d_name); } } diff --git a/tests/test_conda.c b/tests/test_conda.c index e32c9f2..f6ee2f8 100644 --- a/tests/test_conda.c +++ b/tests/test_conda.c @@ -146,11 +146,11 @@ void test_pip_index_provides() { int result = pkg_index_provides(PKG_USE_PIP, test->pindex, test->name, "."); STASIS_ASSERT(result == test->expected, "Unexpected result"); if (PKG_INDEX_PROVIDES_FAILED(result)) { - fprintf(stderr, "error: %s\n", pkg_index_provides_strerror(result)); + SYSERROR("%s", pkg_index_provides_strerror(result)); } else if (result == PKG_NOT_FOUND) { - fprintf(stderr, "package not found: '%s'\n", test->name); + SYSERROR("package not found: '%s'", test->name); } else { - printf("package found: '%s'\n", test->name); + SYSDEBUG("package found: '%s'", test->name); } } } @@ -208,7 +208,7 @@ int main(int argc, char *argv[]) { char ws[] = "workspace_XXXXXX"; if (!mkdtemp(ws)) { - perror("mkdtemp"); + SYSERROR("unable to mkdtemp: %s", strerror(errno)); exit(1); } getcwd(cwd_start, sizeof(cwd_start) - 1); diff --git a/tests/test_system.c b/tests/test_system.c index 9e4a862..cdef618 100644 --- a/tests/test_system.c +++ b/tests/test_system.c @@ -4,7 +4,7 @@ static int ascii_file_contains(const char *filename, const char *value) { int result = -1; char *contents = stasis_testing_read_ascii(filename); if (!contents) { - perror(filename); + SYSERROR("unable to read %s: %s", filename, strerror(errno)); return result; } result = strcmp(contents, value) == 0; diff --git a/tests/test_utils.c b/tests/test_utils.c index 119dea3..696e7ff 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -276,7 +276,7 @@ void test_file_readlines() { const char *data = "I am\na file\nwith multiple lines\nsee?\n"; FILE *fp = fopen(filename, "w"); if (!fp) { - perror(filename); + SYSERROR("unable to open file: %s, %s", filename, strerror(errno)); return; } if (fwrite(data, sizeof(*data), strlen(data), fp) != strlen(data)) { @@ -375,7 +375,7 @@ void test_rmtree() { snprintf(path, sizeof(path), "%s/%s", root, tree[i]); snprintf(mockfile, sizeof(mockfile), "%s/%zu.txt", path, i); if (mkdir(path, 0755)) { - perror(path); + SYSERROR("mkdir failed: %s, %s", path, strerror(errno)); STASIS_ASSERT(false, NULL); } touch(mockfile); diff --git a/tests/test_wheel.c b/tests/test_wheel.c index 525251d..e486b05 100644 --- a/tests/test_wheel.c +++ b/tests/test_wheel.c @@ -80,27 +80,27 @@ static void mock_python_package() { mkdir("testpkg/src", 0755); mkdir("testpkg/src/testpkg", 0755); if (touch("testpkg/src/testpkg/__init__.py")) { - fprintf(stderr, "unable to write __init__.py"); + SYSERROR("unable to write __init__.py"); exit(1); } if (touch("testpkg/README.md")) { - fprintf(stderr, "unable to write README.md"); + SYSERROR("unable to write README.md"); exit(1); } if (stasis_testing_write_ascii("testpkg/pyproject.toml", pyproject_toml_data)) { - perror("unable to write pyproject.toml"); + SYSERROR("unable to write pyproject.toml"); exit(1); } if (stasis_testing_write_ascii("testpkg/README.md", readme)) { - perror("unable to write readme"); + SYSERROR("unable to write readme"); exit(1); } if (pip_exec("install build")) { - fprintf(stderr, "unable to install build tool using pip\n"); + SYSERROR("unable to install build tool using pip"); exit(1); } if (python_exec("-m build -w ./testpkg")) { - fprintf(stderr, "unable build test package"); + SYSERROR("unable build test package"); exit(1); } } @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) { char ws[] = "workspace_XXXXXX"; if (!mkdtemp(ws)) { - perror("mkdtemp"); + SYSERROR("mkdtemp failed: %s, %s", ws, strerror(errno)); exit(1); } getcwd(cwd_start, sizeof(cwd_start) - 1); @@ -145,29 +145,29 @@ int main(int argc, char *argv[]) { ctx.storage.root = strdup(cwd_workspace); char *cfgfile = join((char *[]) {globals.sysconfdir, "stasis.ini", NULL}, "/"); if (!cfgfile) { - perror("unable to create path to global config"); + SYSERROR("unable to create path to global config"); exit(1); } ctx._stasis_ini_fp.cfg = ini_open(cfgfile); if (!ctx._stasis_ini_fp.cfg) { - fprintf(stderr, "unable to open config file, %s\n", cfgfile); + SYSERROR("unable to open config file, %s", cfgfile); exit(1); } ctx._stasis_ini_fp.cfg_path = realpath(cfgfile, NULL); if (!ctx._stasis_ini_fp.cfg_path) { - fprintf(stderr, "unable to determine absolute path of config, %s\n", cfgfile); + SYSERROR("unable to determine absolute path of config, %s", cfgfile); exit(1); } guard_free(cfgfile); setenv("LANG", "C", 1); if (bootstrap_build_info(&ctx)) { - fprintf(stderr, "bootstrap_build_info failed\n"); + SYSERROR("bootstrap_build_info failed"); exit(1); } if (delivery_init(&ctx, INI_READ_RENDER)) { - fprintf(stderr, "delivery_init failed\n"); + SYSERROR("delivery_init failed"); exit(1); } @@ -178,23 +178,23 @@ int main(int argc, char *argv[]) { guard_free(install_url); if (conda_activate(ctx.storage.conda_install_prefix, "base")) { - fprintf(stderr, "conda_activate failed\n"); + SYSERROR("conda_activate failed"); exit(1); } if (conda_exec("install -y boa conda-build")) { - fprintf(stderr, "conda_exec failed\n"); + SYSERROR("conda_exec failed"); exit(1); } if (conda_setup_headless()) { - fprintf(stderr, "conda_setup_headless failed\n"); + SYSERROR("conda_setup_headless failed"); exit(1); } if (conda_env_create("testpkg", ctx.meta.python, NULL)) { - fprintf(stderr, "conda_env_create failed\n"); + SYSERROR("conda_env_create failed"); exit(1); } if (conda_activate(ctx.storage.conda_install_prefix, "testpkg")) { - fprintf(stderr, "conda_activate failed\n"); + SYSERROR("conda_activate failed"); exit(1); } @@ -203,11 +203,11 @@ int main(int argc, char *argv[]) { STASIS_TEST_RUN(tests); if (chdir(cwd_start) < 0) { - fprintf(stderr, "chdir failed\n"); + SYSERROR("chdir failed: %s, %s", cwd_start, strerror(errno)); exit(1); } if (rmtree(cwd_workspace)) { - perror(cwd_workspace); + SYSERROR("rmtree failed: %s, %s", cwd_workspace, strerror(errno)); } delivery_free(&ctx); globals_free(); |
