diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-04-30 17:52:19 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-05-01 19:58:59 -0400 |
commit | 133e5b362f862ac9c9b1dd7b5de0b004cbb9af54 (patch) | |
tree | cf78e1d009490270332b235b9e157c0bfa2e1538 /src/shared/install.c | |
parent | 6597fa61173a16d9d93141a749badad67c4b4aa8 (diff) |
shared/install: refuse template files for non-templateable units
$ systemctl --root=/ enable templated@bar.mount
Unit type mount cannot be templated.
Failed to enable: Invalid argument.
Diffstat (limited to 'src/shared/install.c')
-rw-r--r-- | src/shared/install.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index f89e2c6387..f02d81504f 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1050,6 +1050,8 @@ static int unit_file_load( {} }; + const char *name; + UnitType type; _cleanup_fclose_ FILE *f = NULL; _cleanup_close_ int fd = -1; struct stat st; @@ -1059,6 +1061,12 @@ static int unit_file_load( assert(info); assert(path); + name = basename(path); + type = unit_name_to_type(name); + if (unit_name_is_valid(name, UNIT_NAME_TEMPLATE|UNIT_NAME_INSTANCE) && + !unit_type_may_template(type)) + return log_error_errno(EINVAL, "Unit type %s cannot be templated.", unit_type_to_string(type)); + if (!(flags & SEARCH_LOAD)) { r = lstat(path, &st); if (r < 0) |