]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: ignore enablement of template units w/o instance when presetting 19870/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 9 Jun 2021 16:41:17 +0000 (18:41 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Jun 2021 08:02:38 +0000 (10:02 +0200)
When we have a unit which cannot be enabled:
 # foo@.service:
 ...
 [Install]
 WantedBy=foo.target  # there is no instance, so we don't know what to enable

we should throw an error when invoked directly with 'enable', but
not when doing 'preset' or 'preset-all'.

Fixes #19856.

src/shared/install.c
src/shared/install.h

index f61d10532f56a509f8e9157e67681a63ebaacc18..ba4fa5b136cc81e06b5a77450c69d8ce4e5fbf75 100644 (file)
@@ -1916,8 +1916,16 @@ static int install_info_symlink_wants(
                         return q;
 
                 if (!unit_name_is_valid(dst, valid_dst_type)) {
-                        /* Generate a proper error here: EUCLEAN if the name is generally bad,
-                         * EIDRM if the template status doesn't match. */
+                        /* Generate a proper error here: EUCLEAN if the name is generally bad, EIDRM if the
+                         * template status doesn't match. If we are doing presets don't bother reporting the
+                         * error. This also covers cases like 'systemctl preset serial-getty@.service', which
+                         * has no DefaultInstance, so there is nothing we can do. At the same time,
+                         * 'systemctl enable serial-getty@.service' should fail, the user should specify an
+                         * instance like in 'systemctl enable serial-getty@ttyS0.service'.
+                         */
+                        if (file_flags & UNIT_FILE_IGNORE_AUXILIARY_FAILURE)
+                                continue;
+
                         if (unit_name_is_valid(dst, UNIT_NAME_ANY)) {
                                 unit_file_changes_add(changes, n_changes, -EIDRM, dst, n);
                                 r = -EIDRM;
@@ -3214,7 +3222,9 @@ static int execute_preset(
                 int q;
 
                 /* Returns number of symlinks that where supposed to be installed. */
-                q = install_context_apply(scope, file_flags, plus, paths, config_path, SEARCH_LOAD, changes, n_changes);
+                q = install_context_apply(scope,
+                                          file_flags | UNIT_FILE_IGNORE_AUXILIARY_FAILURE,
+                                          plus, paths, config_path, SEARCH_LOAD, changes, n_changes);
                 if (r >= 0) {
                         if (q < 0)
                                 r = q;
index 74a45db04c6d124f770563940109501434e451e8..c3a0249f5f73a23a366c0a436cbcb891e47a79b9 100644 (file)
@@ -39,10 +39,11 @@ enum {
 };
 
 enum UnitFileFlags {
-        UNIT_FILE_RUNTIME  = 1 << 0, /* Public API via DBUS, do not change */
-        UNIT_FILE_FORCE    = 1 << 1, /* Public API via DBUS, do not change */
-        UNIT_FILE_PORTABLE = 1 << 2, /* Public API via DBUS, do not change */
-        UNIT_FILE_DRY_RUN  = 1 << 3,
+        UNIT_FILE_RUNTIME                  = 1 << 0, /* Public API via DBUS, do not change */
+        UNIT_FILE_FORCE                    = 1 << 1, /* Public API via DBUS, do not change */
+        UNIT_FILE_PORTABLE                 = 1 << 2, /* Public API via DBUS, do not change */
+        UNIT_FILE_DRY_RUN                  = 1 << 3,
+        UNIT_FILE_IGNORE_AUXILIARY_FAILURE = 1 << 4,
         _UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE,
 };