From 2a8f53c67b5d4633ec40e6cd940e222d4b8d3217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 6 Jun 2019 17:33:59 +0200 Subject: [PATCH] Use unit->id instead of description in messages v2: - rename unit_identifier to unit_status_string --- TODO | 2 -- src/core/job.c | 6 +++--- src/core/manager.c | 2 +- src/core/unit.c | 11 ++++++++++- src/core/unit.h | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index a575f9ab73..0df3a62403 100644 --- a/TODO +++ b/TODO @@ -524,8 +524,6 @@ Features: * maybe add support for specifier expansion in user.conf, specifically DefaultEnvironment= -* consider showing the unit names during boot up in the status output, not just the unit descriptions - * maybe allow timer units with an empty Units= setting, so that they can be used for resuming the system but nothing else. diff --git a/src/core/job.c b/src/core/job.c index df7eacfbc0..c69ccc221d 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -579,7 +579,7 @@ static void job_log_begin_status_message(Unit *u, uint32_t job_id, JobType t) { format = job_get_begin_status_message_format(u, t); DISABLE_WARNING_FORMAT_NONLITERAL; - (void) snprintf(buf, sizeof buf, format, unit_description(u)); + (void) snprintf(buf, sizeof buf, format, unit_status_string(u)); REENABLE_WARNING; mid = t == JOB_START ? "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTING_STR : @@ -889,7 +889,7 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job /* Show condition check message if the job did not actually do anything due to failed condition. */ if (t == JOB_START && result == JOB_DONE && !u->condition_result) { log_struct(LOG_INFO, - "MESSAGE=Condition check resulted in %s being skipped.", unit_description(u), + "MESSAGE=Condition check resulted in %s being skipped.", unit_status_string(u), "JOB_ID=%" PRIu32, job_id, "JOB_TYPE=%s", job_type_to_string(t), "JOB_RESULT=%s", job_result_to_string(result), @@ -909,7 +909,7 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job * xsprintf() on purpose here: we are fine with truncation and don't * consider that an error. */ DISABLE_WARNING_FORMAT_NONLITERAL; - (void) snprintf(buf, sizeof(buf), format, unit_description(u)); + (void) snprintf(buf, sizeof(buf), format, unit_status_string(u)); REENABLE_WARNING; switch (t) { diff --git a/src/core/manager.c b/src/core/manager.c index 6b89a5c5bb..09507648fb 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -231,7 +231,7 @@ static void manager_print_jobs_in_progress(Manager *m) { "%sA %s job is running for %s (%s / %s)", strempty(job_of_n), job_type_to_string(j->type), - unit_description(j->unit), + unit_status_string(j->unit), time, limit); } diff --git a/src/core/unit.c b/src/core/unit.c index 463db73ff1..71eb988cd6 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1067,6 +1067,15 @@ const char *unit_description(Unit *u) { return strna(u->id); } +const char *unit_status_string(Unit *u) { + assert(u); + + if (u->manager->status_unit_format == STATUS_UNIT_FORMAT_NAME && u->id) + return u->id; + + return unit_description(u); +} + static void print_unit_dependency_mask(FILE *f, const char *kind, UnitDependencyMask mask, bool *space) { const struct { UnitDependencyMask mask; @@ -1644,7 +1653,7 @@ static bool unit_test_assert(Unit *u) { void unit_status_printf(Unit *u, const char *status, const char *unit_status_msg_format) { const char *d; - d = unit_description(u); + d = unit_status_string(u); if (log_get_show_color()) d = strjoina(ANSI_HIGHLIGHT, d, ANSI_NORMAL); diff --git a/src/core/unit.h b/src/core/unit.h index ef495f836b..e7bfc6b4a7 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -671,6 +671,7 @@ int unit_set_slice(Unit *u, Unit *slice); int unit_set_default_slice(Unit *u); const char *unit_description(Unit *u) _pure_; +const char *unit_status_string(Unit *u) _pure_; bool unit_has_name(const Unit *u, const char *name);