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