summaryrefslogtreecommitdiffstats
path: root/src/basic/unit-name.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-10-24 14:09:11 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-10-25 06:41:49 +0200
commitdf7c4eb62a22a5b131007d98ee49f57f6f95483e (patch)
treefd7edf3e3402c294ebb45a3c60ff0ba91558bca0 /src/basic/unit-name.c
parentresolved: set stream type during DnsStream creation (diff)
downloadsystemd-df7c4eb62a22a5b131007d98ee49f57f6f95483e.tar.xz
systemd-df7c4eb62a22a5b131007d98ee49f57f6f95483e.zip
various tools: be more explicit when a glob is passed when not supported
See https://bugzilla.redhat.com/show_bug.cgi?id=1763488: when we say that 'foo@*.service' is not a valid unit name, this is not clear enough. Let's include the name of the operation that does not support globbing in the error message: $ build/systemctl enable 'foo@*.service' Glob pattern passed to enable, but globs are not supported for this. Invalid unit name "foo@*.service" escaped as "foo@\x2a.service". ...
Diffstat (limited to 'src/basic/unit-name.c')
-rw-r--r--src/basic/unit-name.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
index bcd01f8515..3e37e34325 100644
--- a/src/basic/unit-name.c
+++ b/src/basic/unit-name.c
@@ -597,10 +597,10 @@ static bool do_escape_mangle(const char *f, bool allow_globs, char *t) {
*
* If @allow_globs, globs characters are preserved. Otherwise, they are escaped.
*/
-int unit_name_mangle_with_suffix(const char *name, UnitNameMangle flags, const char *suffix, char **ret) {
+int unit_name_mangle_with_suffix(const char *name, const char *operation, UnitNameMangle flags, const char *suffix, char **ret) {
char *s;
int r;
- bool mangled;
+ bool mangled, suggest_escape = true;
assert(name);
assert(suffix);
@@ -617,10 +617,14 @@ int unit_name_mangle_with_suffix(const char *name, UnitNameMangle flags, const c
goto good;
/* Already a fully valid globbing expression? If so, no mangling is necessary either... */
- if ((flags & UNIT_NAME_MANGLE_GLOB) &&
- string_is_glob(name) &&
- in_charset(name, VALID_CHARS_GLOB))
- goto good;
+ if (string_is_glob(name) && in_charset(name, VALID_CHARS_GLOB)) {
+ if (flags & UNIT_NAME_MANGLE_GLOB)
+ goto good;
+ log_full(flags & UNIT_NAME_MANGLE_WARN ? LOG_NOTICE : LOG_DEBUG,
+ "Glob pattern passed%s%s, but globs are not supported for this.",
+ operation ? " " : "", operation ?: "");
+ suggest_escape = false;
+ }
if (is_device_path(name)) {
r = unit_name_from_path(name, ".device", ret);
@@ -645,11 +649,12 @@ int unit_name_mangle_with_suffix(const char *name, UnitNameMangle flags, const c
mangled = do_escape_mangle(name, flags & UNIT_NAME_MANGLE_GLOB, s);
if (mangled)
log_full(flags & UNIT_NAME_MANGLE_WARN ? LOG_NOTICE : LOG_DEBUG,
- "Invalid unit name \"%s\" was escaped as \"%s\" (maybe you should use systemd-escape?)",
- name, s);
+ "Invalid unit name \"%s\" escaped as \"%s\"%s.",
+ name, s,
+ suggest_escape ? " (maybe you should use systemd-escape?)" : "");
- /* Append a suffix if it doesn't have any, but only if this is not a glob, so that we can allow "foo.*" as a
- * valid glob. */
+ /* Append a suffix if it doesn't have any, but only if this is not a glob, so that we can allow
+ * "foo.*" as a valid glob. */
if ((!(flags & UNIT_NAME_MANGLE_GLOB) || !string_is_glob(s)) && unit_name_to_type(s) < 0)
strcat(s, suffix);