From 13dcc96ffb02041018f15e6fff3979ff933ca624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 30 Aug 2019 13:52:33 +0200 Subject: [PATCH] docs: describe valid unit names in systemd.unit(5) --- man/systemd.unit.xml | 26 +++++++++++++++++--------- src/test/test-unit-name.c | 3 +++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index 8307be1d33..acb09d005d 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -104,16 +104,24 @@ systemd.scope5. - Unit files are loaded from a set of paths determined during - compilation, described in the next section. + Unit files are loaded from a set of paths determined during compilation, described in the next + section. - Unit files can be parameterized by a single argument called the "instance name". The unit - is then constructed based on a "template file" which serves as the definition of multiple - services or other units. A template unit must have a single @ at the end of - the name (right before the type suffix). The name of the full unit is formed by inserting the - instance name between @ and the unit type suffix. In the unit file itself, - the instance parameter may be referred to using %i and other specifiers, see - below. + Valid unit names consist of a "name prefix" and a dot and a suffix specifying the unit type. The + "unit prefix" must consist of one or more valid characters (ASCII letters, digits, :, + -, _, ., and \). The total + length of the unit name including the suffix must not exceed 256 characters. The type suffix must be one + of .service, .socket, .device, + .mount, .automount, .swap, + .target, .path, .timer, + .slice, or .scope. + + Units names can be parameterized by a single argument called the "instance name". The unit is then + constructed based on a "template file" which serves as the definition of multiple services or other + units. A template unit must have a single @ at the end of the name (right before the + type suffix). The name of the full unit is formed by inserting the instance name between + @ and the unit type suffix. In the unit file itself, the instance parameter may be + referred to using %i and other specifiers, see below. Unit files may contain additional options on top of those listed here. If systemd encounters an unknown option, it will diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 7fe732cf2f..25c649828e 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -50,6 +50,9 @@ static void test_unit_name_is_valid(void) { assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE)); assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_TEMPLATE)); assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE)); + assert_se( unit_name_is_valid(".test.service", UNIT_NAME_PLAIN)); + assert_se( unit_name_is_valid(".test@.service", UNIT_NAME_TEMPLATE)); + assert_se( unit_name_is_valid("_strange::::.service", UNIT_NAME_ANY)); assert_se(!unit_name_is_valid(".service", UNIT_NAME_ANY)); assert_se(!unit_name_is_valid("", UNIT_NAME_ANY));