From: Zbigniew Jędrzejewski-Szmek Date: Tue, 6 Aug 2019 19:20:07 +0000 (+0200) Subject: shared/unit-file: fix systemctl cat user@.service X-Git-Tag: v243-rc2~38 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fsystemd.git;a=commitdiff_plain;h=b208cbe5b41df010508f2f190dc69bca04421624 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(). --- 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);