sd-device: make TAGS= property prefixed and suffixed with ":"

The commit 6f3ac0d517 drops the prefix and
suffix in TAGS= property. But there exists several rules that have like
`TAGS=="*:tag:*"`. So, the property must be always prefixed and suffixed
with ":".

Fixes #17930.
This commit is contained in:
Yu Watanabe
2020-12-14 14:04:53 +09:00
parent ba9385d91f
commit 8d80f27530
5 changed files with 87 additions and 57 deletions
+20 -5
View File
@@ -1977,23 +1977,33 @@ IteratedCache* iterated_cache_free(IteratedCache *cache) {
return mfree(cache);
}
int set_strjoin(Set *s, const char *separator, char **ret) {
int set_strjoin(Set *s, const char *separator, bool wrap_with_separator, char **ret) {
size_t separator_len, allocated = 0, len = 0;
_cleanup_free_ char *str = NULL;
const char *value;
bool first = true;
bool first;
assert(ret);
if (set_isempty(s)) {
*ret = NULL;
return 0;
}
separator_len = strlen_ptr(separator);
if (separator_len == 0)
wrap_with_separator = false;
first = !wrap_with_separator;
SET_FOREACH(value, s) {
size_t l = strlen_ptr(value);
if (l == 0)
continue;
if (!GREEDY_REALLOC(str, allocated, len + l + (first ? 0 : separator_len) + 1))
if (!GREEDY_REALLOC(str, allocated, len + l + (first ? 0 : separator_len) + (wrap_with_separator ? separator_len : 0) + 1))
return -ENOMEM;
if (separator_len > 0 && !first) {
@@ -2005,8 +2015,13 @@ int set_strjoin(Set *s, const char *separator, char **ret) {
len += l;
first = false;
}
if (str)
str[len] = '\0';
if (wrap_with_separator) {
memcpy(str + len, separator, separator_len);
len += separator_len;
}
str[len] = '\0';
*ret = TAKE_PTR(str);
return 0;
+1 -1
View File
@@ -151,4 +151,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free);
#define _cleanup_set_free_ _cleanup_(set_freep)
#define _cleanup_set_free_free_ _cleanup_(set_free_freep)
int set_strjoin(Set *s, const char *separator, char **ret);
int set_strjoin(Set *s, const char *separator, bool wrap_with_separator, char **ret);