From 7a1e761070e5b223191b1cb7526730adf1a76681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 4 Feb 2026 10:21:43 +0100 Subject: [PATCH 1/3] pid1: shorten message about jobs skipped after failed condition checks I was looking at some logs on a console, and because of the lengthy message, the actually interesting part, i.e. what condition failed, didn't even fit on the screen. Let's make the sentence legible but brief. --- src/core/job.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/job.c b/src/core/job.c index 449afc1251..1cac09bd06 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -787,7 +787,7 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult log_unit_struct( u, job_done_messages[result].log_level, - LOG_MESSAGE("%s was skipped because no trigger condition checks were met.", + LOG_MESSAGE("%s skipped, no trigger condition checks were met.", ident), LOG_ITEM("JOB_ID=%" PRIu32, job_id), LOG_ITEM("JOB_TYPE=%s", job_type_to_string(t)), @@ -798,7 +798,7 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult log_unit_struct( u, job_done_messages[result].log_level, - LOG_MESSAGE("%s was skipped because of an unmet condition check (%s=%s%s).", + LOG_MESSAGE("%s skipped, unmet condition check %s=%s%s", ident, condition_type_to_string(c->type), c->negate ? "!" : "", From ab4028c47a3dcb923d0acdab2b45e24627948353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 4 Feb 2026 17:57:24 +0100 Subject: [PATCH 2/3] metrics/report: use _cleanup_, avoid goto --- src/report/report.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/report/report.c b/src/report/report.c index 591efa8da8..42819ae29b 100644 --- a/src/report/report.c +++ b/src/report/report.c @@ -79,16 +79,13 @@ static int metrics_on_query_reply( log_info("Varlink timed out"); else log_error("Varlink error: %s", error_id); - - goto finish; + } else { + /* Collect metrics for later sorting */ + if (!GREEDY_REALLOC(context->metrics, context->n_metrics + 1)) + return log_oom(); + context->metrics[context->n_metrics++] = sd_json_variant_ref(parameters); } - /* Collect metrics for later sorting */ - if (!GREEDY_REALLOC(context->metrics, context->n_metrics + 1)) - return log_oom(); - context->metrics[context->n_metrics++] = sd_json_variant_ref(parameters); - -finish: if (!FLAGS_SET(flags, SD_VARLINK_REPLY_CONTINUES)) { assert(context->n_open_connections > 0); context->n_open_connections--; @@ -156,9 +153,6 @@ static void context_done(Context *context) { static void metrics_output_sorted(Context *context) { assert(context); - if (context->n_metrics == 0) - return; - typesafe_qsort(context->metrics, context->n_metrics, metric_compare); FOREACH_ARRAY(m, context->metrics, context->n_metrics) @@ -170,16 +164,14 @@ static void metrics_output_sorted(Context *context) { } static int metrics_query(void) { - _cleanup_closedir_ DIR *d = NULL; - _cleanup_(sd_event_unrefp) sd_event *event = NULL; - _cleanup_free_ char *metrics_path = NULL; int r; + _cleanup_free_ char *metrics_path = NULL; r = runtime_directory_generic(arg_runtime_scope, "systemd/report", &metrics_path); if (r < 0) return log_error_errno(r, "Failed to determine metrics directory path: %m"); - d = opendir(metrics_path); + _cleanup_closedir_ DIR *d = opendir(metrics_path); if (!d) { if (errno == ENOENT) return 0; @@ -187,6 +179,7 @@ static int metrics_query(void) { return log_error_errno(errno, "Failed to open directory %s: %m", metrics_path); } + _cleanup_(sd_event_unrefp) sd_event *event = NULL; r = sd_event_default(&event); if (r < 0) return log_error_errno(r, "Failed to get event loop: %m"); @@ -202,15 +195,14 @@ static int metrics_query(void) { CLEANUP_ARRAY(varlinks, n_varlinks, sd_varlink_unref_many); - Context context = {}; + _cleanup_(context_done) Context context = {}; FOREACH_DIRENT(de, d, return -errno) { - _cleanup_free_ char *p = NULL; if (!IN_SET(de->d_type, DT_SOCK, DT_UNKNOWN)) continue; - p = path_join(metrics_path, de->d_name); + _cleanup_free_ char *p = path_join(metrics_path, de->d_name); if (!p) return log_oom(); @@ -227,15 +219,11 @@ static int metrics_query(void) { } r = sd_event_loop(event); - if (r < 0) { - context_done(&context); + if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); - } metrics_output_sorted(&context); - context_done(&context); - return 0; } @@ -318,11 +306,7 @@ static int run(int argc, char *argv[]) { if (r <= 0) return r; - r = metrics_query(); - if (r < 0) - return r; - - return 0; + return metrics_query(); } DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); From dffcb61f7f74fe2f4a227be89a9718276f4b38c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 4 Feb 2026 18:20:11 +0100 Subject: [PATCH 3/3] metrics/report: add log messages, do not hang if no metrics are found If the directory existed but was empty, we'd hang in the event loop. --- src/report/report.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/report/report.c b/src/report/report.c index 42819ae29b..dcaf91c238 100644 --- a/src/report/report.c +++ b/src/report/report.c @@ -108,7 +108,7 @@ static int metrics_call(const char *path, sd_event *event, sd_varlink **ret, Con r = sd_varlink_connect_address(&vl, path); if (r < 0) - return log_debug_errno(r, "Unable to connect to %s: %m", path); + return log_error_errno(r, "Unable to connect to %s: %m", path); (void) sd_varlink_set_userdata(vl, context); @@ -118,15 +118,15 @@ static int metrics_call(const char *path, sd_event *event, sd_varlink **ret, Con r = sd_varlink_attach_event(vl, event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) - return log_debug_errno(r, "Failed to attach varlink connection to event loop: %m"); + return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); r = sd_varlink_bind_reply(vl, metrics_on_query_reply); if (r < 0) - return log_debug_errno(r, "Failed to bind reply callback: %m"); + return log_error_errno(r, "Failed to bind reply callback: %m"); r = sd_varlink_observe(vl, "io.systemd.Metrics.List", /* parameters= */ NULL); if (r < 0) - return log_debug_errno(r, "Failed to issue io.systemd.Metrics.List call: %m"); + return log_error_errno(r, "Failed to issue io.systemd.Metrics.List call: %m"); *ret = TAKE_PTR(vl); @@ -161,6 +161,9 @@ static void metrics_output_sorted(Context *context) { SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO | SD_JSON_FORMAT_FLUSH, stdout, NULL); + + if (context->n_metrics == 0) + log_warning("No reporting sockets found."); } static int metrics_query(void) { @@ -171,13 +174,12 @@ static int metrics_query(void) { if (r < 0) return log_error_errno(r, "Failed to determine metrics directory path: %m"); - _cleanup_closedir_ DIR *d = opendir(metrics_path); - if (!d) { - if (errno == ENOENT) - return 0; + log_debug("Looking for reports in %s/", metrics_path); - return log_error_errno(errno, "Failed to open directory %s: %m", metrics_path); - } + _cleanup_closedir_ DIR *d = opendir(metrics_path); + if (!d) + return log_full_errno(errno == ENOENT ? LOG_WARNING : LOG_ERR, errno, + "Failed to open metrics directory %s: %m", metrics_path); _cleanup_(sd_event_unrefp) sd_event *event = NULL; r = sd_event_default(&event); @@ -191,13 +193,14 @@ static int metrics_query(void) { size_t n_varlinks = MAX_CONCURRENT_METRICS_SOCKETS; sd_varlink **varlinks = new0(sd_varlink *, n_varlinks); if (!varlinks) - return log_error_errno(ENOMEM, "Failed to allocate varlinks array: %m"); + return log_oom(); CLEANUP_ARRAY(varlinks, n_varlinks, sd_varlink_unref_many); _cleanup_(context_done) Context context = {}; - FOREACH_DIRENT(de, d, return -errno) { + FOREACH_DIRENT(de, d, + return log_warning_errno(errno, "Failed to read %s: %m", metrics_path)) { if (!IN_SET(de->d_type, DT_SOCK, DT_UNKNOWN)) continue; @@ -207,10 +210,8 @@ static int metrics_query(void) { return log_oom(); r = metrics_call(p, event, &varlinks[context.n_open_connections], &context); - if (r < 0) { - log_error_errno(r, "Failed to connect to %s: %m", p); + if (r < 0) continue; - } if (++context.n_open_connections >= MAX_CONCURRENT_METRICS_SOCKETS) { log_warning("Too many concurrent metrics sockets, stop iterating"); @@ -218,9 +219,11 @@ static int metrics_query(void) { } } - r = sd_event_loop(event); - if (r < 0) - return log_error_errno(r, "Failed to run event loop: %m"); + if (context.n_open_connections > 0) { + r = sd_event_loop(event); + if (r < 0) + return log_error_errno(r, "Failed to run event loop: %m"); + } metrics_output_sorted(&context);