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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-02-11 15:31:37 +01:00
parent 4f78e5fa86
commit 3604664638
+11 -13
View File
@@ -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);