fflush(stdout);
}
- r = unit_name_mangle_with_suffix(*i, 0, ".service", &mangled);
+ r = unit_name_mangle(*i, 0, &mangled);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name '%s': %m", *i);
*
* 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);
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);
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);
UNIT_NAME_MANGLE_WARN = 1 << 1,
} UnitNameMangle;
-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);
static inline int unit_name_mangle(const char *name, UnitNameMangle flags, char **ret) {
- return unit_name_mangle_with_suffix(name, flags, ".service", ret);
+ return unit_name_mangle_with_suffix(name, NULL, flags, ".service", ret);
}
bool service_unit_name_is_valid(const char *name);
STRV_FOREACH(s, names) {
char *x;
- r = unit_name_mangle_with_suffix(*s, 0, ".mount", &x);
+ r = unit_name_mangle_with_suffix(*s, "as dependency", 0, ".mount", &x);
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
r = strv_consume(&units, x);
if (r < 0)
return log_error_errno(r, "Could not watch job: %m");
- r = unit_name_mangle_with_suffix(machine_name, 0, ".scope", &scope);
+ r = unit_name_mangle_with_suffix(machine_name, "as machine name", 0, ".scope", &scope);
if (r < 0)
return log_error_errno(r, "Failed to mangle scope name: %m");
_cleanup_free_ char *scope = NULL;
int r;
- r = unit_name_mangle_with_suffix(machine_name, 0, ".scope", &scope);
+ r = unit_name_mangle_with_suffix(machine_name, "to terminate", 0, ".scope", &scope);
if (r < 0)
return log_error_errno(r, "Failed to mangle scope name: %m");
if (!isempty(arg_slice)) {
_cleanup_free_ char *slice = NULL;
- r = unit_name_mangle_with_suffix(arg_slice, arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, ".slice", &slice);
+ r = unit_name_mangle_with_suffix(arg_slice, "as slice",
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ ".slice", &slice);
if (r < 0)
return log_error_errno(r, "Failed to mangle name '%s': %m", arg_slice);
}
if (arg_unit) {
- r = unit_name_mangle_with_suffix(arg_unit, arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, ".service", &service);
+ r = unit_name_mangle_with_suffix(arg_unit, "as unit",
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ ".service", &service);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name: %m");
} else {
return log_oom();
if (arg_unit) {
- r = unit_name_mangle_with_suffix(arg_unit, arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, ".scope", &scope);
+ r = unit_name_mangle_with_suffix(arg_unit, "as unit",
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ ".scope", &scope);
if (r < 0)
return log_error_errno(r, "Failed to mangle scope name: %m");
} else {
break;
default:
- r = unit_name_mangle_with_suffix(arg_unit, arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, ".service", &service);
+ r = unit_name_mangle_with_suffix(arg_unit, "as unit",
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ ".service", &service);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name: %m");
- r = unit_name_mangle_with_suffix(arg_unit, arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, suffix, &trigger);
+ r = unit_name_mangle_with_suffix(arg_unit, "as trigger",
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ suffix, &trigger);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name: %m");
char *t;
UnitNameMangle options = UNIT_NAME_MANGLE_GLOB | (arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN);
- if (suffix)
- r = unit_name_mangle_with_suffix(*name, options, suffix, &t);
- else
- r = unit_name_mangle(*name, options, &t);
+ r = unit_name_mangle_with_suffix(*name, NULL, options, suffix ?: ".service", &t);
if (r < 0)
return log_error_errno(r, "Failed to mangle name: %m");
assert(argc >= 2);
assert(argv);
- r = unit_name_mangle_with_suffix(argv[1], arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, ".target", &unit);
+ r = unit_name_mangle_with_suffix(argv[1], "set-default",
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ ".target", &unit);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name: %m");
return r;
}
-static int mangle_names(char **original_names, char ***mangled_names) {
+static int mangle_names(const char *operation, char **original_names, char ***mangled_names) {
char **i, **l, **name;
int r;
return log_oom();
}
} else {
- r = unit_name_mangle(*name, arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, i);
+ r = unit_name_mangle_with_suffix(*name, operation,
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ ".service", i);
if (r < 0) {
*i = NULL;
strv_free(l);
if (!argv[1])
return 0;
- r = mangle_names(strv_skip(argv, 1), &names);
+ r = mangle_names("to enable", strv_skip(argv, 1), &names);
if (r < 0)
return r;
if (!argv[1])
return 0;
- r = unit_name_mangle_with_suffix(argv[1], arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, ".target", &target);
+ r = unit_name_mangle_with_suffix(argv[1], "as target",
+ arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
+ ".target", &target);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name: %m");
- r = mangle_names(strv_skip(argv, 2), &names);
+ r = mangle_names("as dependency", strv_skip(argv, 2), &names);
if (r < 0)
return r;
char **name;
int r;
- r = mangle_names(strv_skip(argv, 1), &names);
+ r = mangle_names("to check", strv_skip(argv, 1), &names);
if (r < 0)
return r;