ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
803fb7
From c9a4b1688552a23867d3d9db18620501d57d33da Mon Sep 17 00:00:00 2001
803fb7
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
803fb7
Date: Sat, 16 Apr 2016 19:31:53 -0400
803fb7
Subject: [PATCH] systemctl/core: ignore masked units in preset-all
803fb7
803fb7
With any masked unit that would that would be enabled by presets, we'd get:
803fb7
803fb7
test@rawhide $ sudo systemctl preset-all
803fb7
Failed to execute operation: Unit file is masked.
803fb7
803fb7
test@rawhide $ sudo systemctl --root=/ preset-all
803fb7
Operation failed: Cannot send after transport endpoint shutdown
803fb7
803fb7
Simply ignore those units:
803fb7
803fb7
test@rawhide $ sudo systemctl preset-all
803fb7
Unit xxx.service is masked, ignoring.
803fb7
803fb7
Cherry-picked from: 9a0a413a195a21888cf926be5595d0efc1eef0fe
803fb7
Related: #1375097
803fb7
---
803fb7
 src/core/dbus-manager.c          | 12 +++++++-----
803fb7
 src/libsystemd/sd-bus/bus-util.c | 10 ++++++++--
803fb7
 src/shared/install.c             |  4 ++++
803fb7
 src/shared/install.h             |  5 +++++
803fb7
 src/systemctl/systemctl.c        | 20 ++++++++++++++------
803fb7
 5 files changed, 38 insertions(+), 13 deletions(-)
803fb7
803fb7
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
803fb7
index 8d3758ac7..c2067c099 100644
803fb7
--- a/src/core/dbus-manager.c
803fb7
+++ b/src/core/dbus-manager.c
803fb7
@@ -1598,11 +1598,13 @@ static int reply_unit_file_changes_and_free(
803fb7
         unsigned i;
803fb7
         int r;
803fb7
 
803fb7
-        if (n_changes > 0) {
803fb7
-                r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL);
803fb7
-                if (r < 0)
803fb7
-                        log_debug_errno(r, "Failed to send UnitFilesChanged signal: %m");
803fb7
-        }
803fb7
+        for (i = 0; i < n_changes; i++)
803fb7
+                if (unit_file_change_is_modification(changes[i].type)) {
803fb7
+                        r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL);
803fb7
+                        if (r < 0)
803fb7
+                                log_debug_errno(r, "Failed to send UnitFilesChanged signal: %m");
803fb7
+                        break;
803fb7
+                }
803fb7
 
803fb7
         r = sd_bus_message_new_method_return(message, &reply);
803fb7
         if (r < 0)
803fb7
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
803fb7
index 9d70798cd..75d03708e 100644
803fb7
--- a/src/libsystemd/sd-bus/bus-util.c
803fb7
+++ b/src/libsystemd/sd-bus/bus-util.c
803fb7
@@ -1893,11 +1893,17 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un
803fb7
                 if (!quiet) {
803fb7
                         if (streq(type, "symlink"))
803fb7
                                 log_info("Created symlink from %s to %s.", path, source);
803fb7
-                        else
803fb7
+                        else if (streq(type, "unlink"))
803fb7
                                 log_info("Removed symlink %s.", path);
803fb7
+                        else if (streq(type, "masked"))
803fb7
+                                log_info("Unit %s is masked, ignoring.", path);
803fb7
+                        else
803fb7
+                                log_notice("Manager reported unknown change type \"%s\" for %s.", type, path);
803fb7
                 }
803fb7
 
803fb7
-                r = unit_file_changes_add(changes, n_changes, streq(type, "symlink") ? UNIT_FILE_SYMLINK : UNIT_FILE_UNLINK, path, source);
803fb7
+                r = unit_file_changes_add(changes, n_changes,
803fb7
+                                          unit_file_change_type_from_string(type),
803fb7
+                                          path, source);
803fb7
                 if (r < 0)
803fb7
                         return r;
803fb7
         }
803fb7
diff --git a/src/shared/install.c b/src/shared/install.c
803fb7
index ab86cd145..62da52d3b 100644
803fb7
--- a/src/shared/install.c
803fb7
+++ b/src/shared/install.c
803fb7
@@ -2402,6 +2402,9 @@ int unit_file_preset_all(
803fb7
                                 continue;
803fb7
 
803fb7
                         r = preset_prepare_one(scope, &plus, &minus, &paths, root_dir, mode, de->d_name);
803fb7
+                        if (r == -ESHUTDOWN)
803fb7
+                                r = unit_file_changes_add(changes, n_changes,
803fb7
+                                                          UNIT_FILE_IS_MASKED, de->d_name, NULL);
803fb7
                         if (r < 0)
803fb7
                                 return r;
803fb7
                 }
803fb7
@@ -2535,6 +2538,7 @@ DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);
803fb7
 static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE_MAX] = {
803fb7
         [UNIT_FILE_SYMLINK] = "symlink",
803fb7
         [UNIT_FILE_UNLINK] = "unlink",
803fb7
+        [UNIT_FILE_IS_MASKED] = "masked",
803fb7
 };
803fb7
 
803fb7
 DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, UnitFileChangeType);
803fb7
diff --git a/src/shared/install.h b/src/shared/install.h
803fb7
index 87a40b67c..f0e36661b 100644
803fb7
--- a/src/shared/install.h
803fb7
+++ b/src/shared/install.h
803fb7
@@ -60,10 +60,15 @@ typedef enum UnitFilePresetMode {
803fb7
 typedef enum UnitFileChangeType {
803fb7
         UNIT_FILE_SYMLINK,
803fb7
         UNIT_FILE_UNLINK,
803fb7
+        UNIT_FILE_IS_MASKED,
803fb7
         _UNIT_FILE_CHANGE_TYPE_MAX,
803fb7
         _UNIT_FILE_CHANGE_TYPE_INVALID = -1
803fb7
 } UnitFileChangeType;
803fb7
 
803fb7
+static inline bool unit_file_change_is_modification(UnitFileChangeType type) {
803fb7
+        return IN_SET(type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK);
803fb7
+}
803fb7
+
803fb7
 typedef struct UnitFileChange {
803fb7
         UnitFileChangeType type;
803fb7
         char *path;
803fb7
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
803fb7
index e4b404abc..a688d6905 100644
803fb7
--- a/src/systemctl/systemctl.c
803fb7
+++ b/src/systemctl/systemctl.c
803fb7
@@ -1944,12 +1944,20 @@ static void dump_unit_file_changes(const UnitFileChange *changes, unsigned n_cha
803fb7
 
803fb7
         assert(changes || n_changes == 0);
803fb7
 
803fb7
-        for (i = 0; i < n_changes; i++) {
803fb7
-                if (changes[i].type == UNIT_FILE_SYMLINK)
803fb7
-                        log_info("Created symlink from %s to %s.", changes[i].path, changes[i].source);
803fb7
-                else
803fb7
-                        log_info("Removed symlink %s.", changes[i].path);
803fb7
-        }
803fb7
+        for (i = 0; i < n_changes; i++)
803fb7
+                switch(changes[i].type) {
803fb7
+                case UNIT_FILE_SYMLINK:
803fb7
+                        log_info("Created symlink %s, pointing to %s.", changes[i].path, changes[i].source);
803fb7
+                        break;
803fb7
+                case UNIT_FILE_UNLINK:
803fb7
+                        log_info("Removed %s.", changes[i].path);
803fb7
+                        break;
803fb7
+                case UNIT_FILE_IS_MASKED:
803fb7
+                        log_info("Unit %s is masked, ignoring.", changes[i].path);
803fb7
+                        break;
803fb7
+                default:
803fb7
+                        assert_not_reached("bad change type");
803fb7
+                }
803fb7
 }
803fb7
 
803fb7
 static int set_default(sd_bus *bus, char **args) {