]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
report: simplify error propagation 40642/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Mon, 9 Feb 2026 11:15:56 +0000 (12:15 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 11 Feb 2026 14:31:37 +0000 (15:31 +0100)
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.

src/report/report.c

index fad7fdf363dbfbc914cde94f514b4789bb24d6bf..6909f78455cb8b4a238db9ff54f8bb1604a13a87 100644 (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);