summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-08-30 13:52:33 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-08-30 13:55:55 +0200
commit13dcc96ffb02041018f15e6fff3979ff933ca624 (patch)
tree4bcdc2eb853fe7f2c0af2501e2355d163fe26f8d
parent153d5975751aab58c3c4cdfdbe13ea7187c16e28 (diff)
downloadsystemd-13dcc96ffb02041018f15e6fff3979ff933ca624.tar.gz
docs: describe valid unit names in systemd.unit(5)
-rw-r--r--man/systemd.unit.xml28
-rw-r--r--src/test/test-unit-name.c3
2 files changed, 21 insertions, 10 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 @@
<citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para>
- <para>Unit files are loaded from a set of paths determined during
- compilation, described in the next section.</para>
-
- <para>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 <literal>@</literal> 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 <literal>@</literal> and the unit type suffix. In the unit file itself,
- the instance parameter may be referred to using <literal>%i</literal> and other specifiers, see
- below.</para>
+ <para>Unit files are loaded from a set of paths determined during compilation, described in the next
+ section.</para>
+
+ <para>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, <literal>:</literal>,
+ <literal>-</literal>, <literal>_</literal>, <literal>.</literal>, and <literal>\</literal>). The total
+ length of the unit name including the suffix must not exceed 256 characters. The type suffix must be one
+ of <literal>.service</literal>, <literal>.socket</literal>, <literal>.device</literal>,
+ <literal>.mount</literal>, <literal>.automount</literal>, <literal>.swap</literal>,
+ <literal>.target</literal>, <literal>.path</literal>, <literal>.timer</literal>,
+ <literal>.slice</literal>, or <literal>.scope</literal>.</para>
+
+ <para>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 <literal>@</literal> 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
+ <literal>@</literal> and the unit type suffix. In the unit file itself, the instance parameter may be
+ referred to using <literal>%i</literal> and other specifiers, see below.</para>
<para>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));