summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-05-31 14:46:16 +0200
committerMike Yuan <me@yhndnzj.com>2024-07-17 18:14:32 +0200
commit0064290a54fe46047889d44b3215d04b60e77c17 (patch)
tree11db45a8c8ba0d7df145358075ba8b61219d754d /src/core
parentcore/cgroup: skip freezer action wholly if current == objective (diff)
downloadsystemd-0064290a54fe46047889d44b3215d04b60e77c17.tar.xz
systemd-0064290a54fe46047889d44b3215d04b60e77c17.zip
core/unit: introduce unit_set_freezer_state, make logging consistent
Also, emit PropertiesChanged signal for FreezerState too. Fixes #31115
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cgroup.c8
-rw-r--r--src/core/unit.c16
-rw-r--r--src/core/unit.h1
3 files changed, 19 insertions, 6 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index a8bdd0dd0d..98f33fe580 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -5156,19 +5156,15 @@ int unit_cgroup_freezer_action(Unit *u, FreezerAction action) {
if (r < 0)
return r;
- log_unit_debug(u, "Unit freezer state was %s, now %s.",
- freezer_state_to_string(u->freezer_state),
- freezer_state_to_string(next));
-
r = write_string_file(path, one_zero(objective == FREEZER_FROZEN), WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)
return r;
- u->freezer_state = next;
+ unit_set_freezer_state(u, next);
return 1; /* Wait for cgroup event before replying */
skip:
- u->freezer_state = freezer_state_finish(next);
+ unit_set_freezer_state(u, freezer_state_finish(next));
return 0;
}
diff --git a/src/core/unit.c b/src/core/unit.c
index 999e690a32..01f2ca189c 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -6251,6 +6251,22 @@ bool unit_can_freeze(const Unit *u) {
return UNIT_VTABLE(u)->freezer_action;
}
+void unit_set_freezer_state(Unit *u, FreezerState state) {
+ assert(u);
+ assert(state >= 0);
+ assert(state < _FREEZER_STATE_MAX);
+
+ if (u->freezer_state == state)
+ return;
+
+ log_unit_debug(u, "Freezer state changed %s -> %s",
+ freezer_state_to_string(u->freezer_state), freezer_state_to_string(state));
+
+ u->freezer_state = state;
+
+ unit_add_to_dbus_queue(u);
+}
+
void unit_frozen(Unit *u) {
assert(u);
diff --git a/src/core/unit.h b/src/core/unit.h
index 9c8dbcf12a..2003b6a779 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -1039,6 +1039,7 @@ bool unit_can_isolate_refuse_manual(Unit *u);
bool unit_can_freeze(const Unit *u);
int unit_freezer_action(Unit *u, FreezerAction action);
void unit_next_freezer_state(Unit *u, FreezerAction action, FreezerState *ret_next, FreezerState *ret_objective);
+void unit_set_freezer_state(Unit *u, FreezerState state);
void unit_frozen(Unit *u);
void unit_thawed(Unit *u);