shared/install: warn about DefaultInstance in non-template units
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 30 Apr 2016 21:08:38 +0000 (17:08 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 1 May 2016 23:58:59 +0000 (19:58 -0400)
[/etc/systemd/system/mnt-test.mount:6] DefaultInstance only makes sense for template units, ignoring.

src/shared/install.c

index cc39aaf..f89e2c6 100644 (file)
@@ -1003,6 +1003,7 @@ static int config_parse_default_instance(
                 void *userdata) {
 
         UnitFileInstallInfo *i = data;
+        const char *name;
         char *printed;
         int r;
 
@@ -1010,6 +1011,15 @@ static int config_parse_default_instance(
         assert(lvalue);
         assert(rvalue);
 
+        name = basename(filename);
+        if (unit_name_is_valid(name, UNIT_NAME_INSTANCE))
+                /* When enabling an instance, we might be using a template unit file,
+                 * but we should ignore DefaultInstance silently. */
+                return 0;
+        if (!unit_name_is_valid(name, UNIT_NAME_TEMPLATE))
+                return log_syntax(unit, LOG_WARNING, filename, line, 0,
+                                  "DefaultInstance only makes sense for template units, ignoring.");
+
         r = install_full_printf(i, rvalue, &printed);
         if (r < 0)
                 return r;