From b208cbe5b41df010508f2f190dc69bca04421624 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 6 Aug 2019 21:20:07 +0200 Subject: [PATCH] shared/unit-file: fix systemctl cat user@.service I assumed that unit_name_to_instnace() returns NULL if there is no instance. In fact it returns "", so the check for instance was wrong. Also avoid unnecessary call to unit_name_is_valid(). --- src/shared/unit-file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c index db73c9bd4b6..f83633be5f8 100644 --- a/src/shared/unit-file.c +++ b/src/shared/unit-file.c @@ -415,7 +415,7 @@ int unit_file_find_fragment( return -ENOMEM; /* The unit always has its own name if it's not a template. */ - if (unit_name_is_valid(unit_name, UNIT_NAME_PLAIN | UNIT_NAME_INSTANCE)) { + if (IN_SET(name_type, UNIT_NAME_PLAIN, UNIT_NAME_INSTANCE)) { r = set_put_strdup(names, unit_name); if (r < 0) return r; @@ -430,12 +430,12 @@ int unit_file_find_fragment( /* Add any aliases of the original name to the set of names */ nnn = hashmap_get(unit_name_map, basename(fragment)); STRV_FOREACH(t, nnn) { - if (instance && unit_name_is_valid(*t, UNIT_NAME_TEMPLATE)) { + if (name_type == UNIT_NAME_INSTANCE && unit_name_is_valid(*t, UNIT_NAME_TEMPLATE)) { char *inst; r = unit_name_replace_instance(*t, instance, &inst); if (r < 0) - return log_debug_errno(r, "Cannot build instance name %s+%s: %m", *t, instance); + return log_debug_errno(r, "Cannot build instance name %s+%s: %m", *t, instance); if (!streq(unit_name, inst)) log_debug("%s: %s has alias %s", __func__, unit_name, inst); -- 2.39.2