summaryrefslogtreecommitdiff
path: root/src/test/test-unit-name.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-21 15:26:47 +0100
committerLennart Poettering <lennart@poettering.net>2018-03-21 15:26:47 +0100
commit37cbc1d57992f49b3607bd66973dd30e0a8d1073 (patch)
tree495e940367f2cf5534c43b14af602c344969accf /src/test/test-unit-name.c
parentb85aca4f9218adf52f6c09d490f189d59b4dacd5 (diff)
downloadsystemd-37cbc1d57992f49b3607bd66973dd30e0a8d1073.tar.gz
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.
Diffstat (limited to 'src/test/test-unit-name.c')
-rw-r--r--src/test/test-unit-name.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index f7598d2284..3c7a17b42f 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -162,10 +162,10 @@ static void test_unit_name_to_path(void) {
test_unit_name_to_path_one("home/foo", NULL, -EINVAL);
}
-static void test_unit_name_mangle_one(UnitNameMangle allow_globs, const char *pattern, const char *expect, int ret) {
+static void test_unit_name_mangle_one(bool allow_globs, const char *pattern, const char *expect, int ret) {
_cleanup_free_ char *t = NULL;
- assert_se(unit_name_mangle(pattern, allow_globs, &t) == ret);
+ assert_se(unit_name_mangle(pattern, (allow_globs * UNIT_NAME_MANGLE_GLOB) | UNIT_NAME_MANGLE_WARN, &t) == ret);
puts(strna(t));
assert_se(streq_ptr(t, expect));
@@ -173,29 +173,29 @@ static void test_unit_name_mangle_one(UnitNameMangle allow_globs, const char *pa
_cleanup_free_ char *k = NULL;
assert_se(unit_name_is_valid(t, UNIT_NAME_ANY) ||
- (allow_globs == UNIT_NAME_GLOB && string_is_glob(t)));
+ (allow_globs && string_is_glob(t)));
- assert_se(unit_name_mangle(t, allow_globs, &k) == 0);
+ assert_se(unit_name_mangle(t, (allow_globs * UNIT_NAME_MANGLE_GLOB) | UNIT_NAME_MANGLE_WARN, &k) == 0);
assert_se(streq_ptr(t, k));
}
}
static void test_unit_name_mangle(void) {
puts("-------------------------------------------------");
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "foo.service", "foo.service", 0);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "/home", "home.mount", 1);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "/dev/sda", "dev-sda.device", 1);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "üxknürz.service", "\\xc3\\xbcxkn\\xc3\\xbcrz.service", 1);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "foobar-meh...waldi.service", "foobar-meh...waldi.service", 0);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "_____####----.....service", "_____\\x23\\x23\\x23\\x23----.....service", 1);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "_____##@;;;,,,##----.....service", "_____\\x23\\x23@\\x3b\\x3b\\x3b\\x2c\\x2c\\x2c\\x23\\x23----.....service", 1);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "xxx@@@@/////\\\\\\\\\\yyy.service", "xxx@@@@-----\\\\\\\\\\yyy.service", 1);
- test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "", NULL, -EINVAL);
-
- test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo.service", "foo.service", 0);
- test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo", "foo.service", 1);
- test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo*", "foo*", 0);
- test_unit_name_mangle_one(UNIT_NAME_GLOB, "ü*", "\\xc3\\xbc*", 1);
+ test_unit_name_mangle_one(false, "foo.service", "foo.service", 0);
+ test_unit_name_mangle_one(false, "/home", "home.mount", 1);
+ test_unit_name_mangle_one(false, "/dev/sda", "dev-sda.device", 1);
+ test_unit_name_mangle_one(false, "üxknürz.service", "\\xc3\\xbcxkn\\xc3\\xbcrz.service", 1);
+ test_unit_name_mangle_one(false, "foobar-meh...waldi.service", "foobar-meh...waldi.service", 0);
+ test_unit_name_mangle_one(false, "_____####----.....service", "_____\\x23\\x23\\x23\\x23----.....service", 1);
+ test_unit_name_mangle_one(false, "_____##@;;;,,,##----.....service", "_____\\x23\\x23@\\x3b\\x3b\\x3b\\x2c\\x2c\\x2c\\x23\\x23----.....service", 1);
+ test_unit_name_mangle_one(false, "xxx@@@@/////\\\\\\\\\\yyy.service", "xxx@@@@-----\\\\\\\\\\yyy.service", 1);
+ test_unit_name_mangle_one(false, "", NULL, -EINVAL);
+
+ test_unit_name_mangle_one(true, "foo.service", "foo.service", 0);
+ test_unit_name_mangle_one(true, "foo", "foo.service", 1);
+ test_unit_name_mangle_one(true, "foo*", "foo*", 0);
+ test_unit_name_mangle_one(true, "ü*", "\\xc3\\xbc*", 1);
}
static int test_unit_printf(void) {