From: Zbigniew Jędrzejewski-Szmek Date: Mon, 9 Feb 2026 11:15:56 +0000 (+0100) Subject: report: simplify error propagation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3604664638cb0733f5ed199c621dcebddb0fae5f;p=thirdparty%2Fsystemd.git report: simplify error propagation Returning EXIT_* from an inner function is unusual and better avoided. Let's just return a negative value and let the caller do the conversion. --- diff --git a/src/report/report.c b/src/report/report.c index fad7fdf363d..6909f78455c 100644 --- a/src/report/report.c +++ b/src/report/report.c @@ -197,7 +197,7 @@ static int metrics_query(void) { if (!d) { if (errno != ENOENT) return log_error_errno(errno, "Failed to open metrics directory %s: %m", metrics_path); - } else { + } else FOREACH_DIRENT(de, d, return log_warning_errno(errno, "Failed to read %s: %m", metrics_path)) { @@ -215,7 +215,6 @@ static int metrics_query(void) { (void) metrics_call(&context, p); } - } if (set_isempty(context.links)) log_info("No metrics sources found."); @@ -227,18 +226,17 @@ static int metrics_query(void) { r = metrics_output_sorted(&context); if (r < 0) return r; - - if (n_skipped_sources > 0) - log_warning("Too many metrics sources, only %u sources contacted, %zu sources skipped.", set_size(context.links), n_skipped_sources); - if (context.n_skipped_metrics > 0) - log_warning("Too many metrics, only %zu metrics collected, %zu metrics skipped.", context.n_metrics, context.n_skipped_metrics); - - if (n_skipped_sources > 0 || - context.n_skipped_metrics > 0) - return EXIT_FAILURE; } - return EXIT_SUCCESS; + if (n_skipped_sources > 0) + return log_warning_errno(SYNTHETIC_ERRNO(EUCLEAN), + "Too many metrics sources, only %u sources contacted, %zu sources skipped.", + set_size(context.links), n_skipped_sources); + if (context.n_skipped_metrics > 0) + return log_warning_errno(SYNTHETIC_ERRNO(EUCLEAN), + "Too many metrics, only %zu metrics collected, %zu metrics skipped.", + context.n_metrics, context.n_skipped_metrics); + return 0; } static int help(void) { @@ -339,4 +337,4 @@ static int run(int argc, char *argv[]) { return metrics_query(); } -DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); +DEFINE_MAIN_FUNCTION(run);