]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: refuse template files for non-templateable units 3162/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 30 Apr 2016 21:52:19 +0000 (17:52 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 1 May 2016 23:58:59 +0000 (19:58 -0400)
$ systemctl --root=/ enable templated@bar.mount
Unit type mount cannot be templated.
Failed to enable: Invalid argument.

src/shared/install.c

index f89e2c63877785d7f66a9ee7937028cef42891b7..f02d81504faac3d5e836f7d2fd0e60d5d0a1b64b 100644 (file)
@@ -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)