When mangling names, optionally emit a warning (#8400)

The warning is not emitted for absolute paths like /dev/sda or /home, which are
converted to .device and .mount unit names without any fuss.

Most of the time it's unlikely that users use invalid unit names on purpose,
so let's warn them. Warnings are silenced when --quiet is used.

$ build/systemctl show -p Id hello@foo-bar/baz
Invalid unit name "hello@foo-bar/baz" was escaped as "hello@foo-bar-baz" (maybe you should use systemd-escape?)
Id=hello@foo-bar-baz.service

$ build/systemd-run --user --slice foo-bar/baz --unit foo-bar/foo true
Invalid unit name "foo-bar/foo" was escaped as "foo-bar-foo" (maybe you should use systemd-escape?)
Invalid unit name "foo-bar/baz" was escaped as "foo-bar-baz" (maybe you should use systemd-escape?)
Running as unit: foo-bar-foo.service

Fixes #8302.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-03-21 15:26:47 +01:00
committed by Lennart Poettering
parent b85aca4f92
commit 37cbc1d579
12 changed files with 71 additions and 62 deletions
+5 -5
View File
@@ -68,14 +68,14 @@ int unit_name_from_path_instance(const char *prefix, const char *path, const cha
int unit_name_to_path(const char *name, char **ret);
typedef enum UnitNameMangle {
UNIT_NAME_NOGLOB,
UNIT_NAME_GLOB,
UNIT_NAME_MANGLE_GLOB = 1,
UNIT_NAME_MANGLE_WARN = 2,
} UnitNameMangle;
int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret);
int unit_name_mangle_with_suffix(const char *name, UnitNameMangle flags, const char *suffix, char **ret);
static inline int unit_name_mangle(const char *name, UnitNameMangle allow_globs, char **ret) {
return unit_name_mangle_with_suffix(name, allow_globs, ".service", ret);
static inline int unit_name_mangle(const char *name, UnitNameMangle flags, char **ret) {
return unit_name_mangle_with_suffix(name, flags, ".service", ret);
}
int slice_build_parent_slice(const char *slice, char **ret);