File 0001-test2.patch of Package systemd

From 09a6eba956f2403d0c87d8ab1f97cef16595d3a5 Mon Sep 17 00:00:00 2001
From: Antonio Alvarez Feijoo <antonio.feijoo@suse.com>
Date: Fri, 5 Dec 2025 18:17:00 +0100
Subject: [PATCH] test2

---
 src/core/manager.c   |  3 +++
 src/shared/install.c | 49 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/src/core/manager.c b/src/core/manager.c
index c1c2b713ec..2670d193e4 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1926,6 +1926,9 @@ static void manager_preset_all(Manager *m) {
 
         assert(m);
 
+        if (symlink("/dev/null", "/run/systemd/preset-mask") < 0 && errno != EEXIST)
+                log_error_errno(errno, "Failed to symlink /run/systemd/preset-mask to /dev/null: %m");
+
         if (m->first_boot <= 0)
                 return;
 
diff --git a/src/shared/install.c b/src/shared/install.c
index 20f7fb6ad7..aa5d6e64a0 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -3580,7 +3580,7 @@ static int execute_preset(
 
                         RET_GATHER(r, create_symlink(
                                         lp,
-                                        "/dev/null",
+                                        "/run/systemd/preset-mask",
                                         path,
                                         file_flags & UNIT_FILE_FORCE,
                                         changes,
@@ -3617,6 +3617,37 @@ static int execute_preset(
         return r;
 }
 
+static int preset_mask_check_and_remove(
+                const char *name,
+                const char *config_path) {
+
+        _cleanup_free_ char *path = NULL, *target = NULL;
+        struct stat st;
+        int r;
+
+        assert(name);
+        assert(config_path);
+
+        path = path_make_absolute(name, config_path);
+        if (!path)
+                return -ENOMEM;
+
+        if (stat(path, &st) == 0 && null_or_empty(&st)) {
+                r = readlink_malloc(path, &target);
+                if (r < 0)
+                        return r;
+
+                if (streq(target, "/run/systemd/preset-mask")) {
+                        if (unlink(path) < 0)
+                                return log_error_errno(errno, "Failed to remove %s: %m", path);
+
+                        log_info("Removed '%s'.", path);
+                }
+        }
+
+        return 0;
+}
+
 static int preset_prepare_one(
                 RuntimeScope scope,
                 InstallContext *plus,
@@ -3652,23 +3683,35 @@ static int preset_prepare_one(
         if (r == PRESET_ENABLE) {
                 if (instance_name_list)
                         STRV_FOREACH(s, instance_name_list) {
+                                r = preset_mask_check_and_remove(*s, lp->persistent_config);
+                                if (r < 0)
+                                        return r;
+
                                 r = install_info_discover_and_check(plus, lp, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
                                                                     &info, changes, n_changes);
                                 if (r < 0)
                                         return r;
                         }
                 else {
+                        r = preset_mask_check_and_remove(name, lp->persistent_config);
+                        if (r < 0)
+                                return r;
+
                         r = install_info_discover_and_check(plus, lp, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
                                                             &info, changes, n_changes);
                         if (r < 0)
                                 return r;
                 }
 
-        } else if (r == PRESET_DISABLE)
+        } else if (r == PRESET_DISABLE) {
+                r = preset_mask_check_and_remove(name, lp->persistent_config);
+                if (r < 0)
+                        return r;
+
                 r = install_info_discover(minus, lp, name, SEARCH_FOLLOW_CONFIG_SYMLINKS,
                                           &info, changes, n_changes);
 
-        else if (r == PRESET_MASK) {
+        } else if (r == PRESET_MASK) {
                 if (!unit_name_is_valid(name, UNIT_NAME_ANY))
                         return -EINVAL;
 
-- 
2.51.0

openSUSE Build Service is sponsored by