summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-05-31 14:43:53 +0200
committerMike Yuan <me@yhndnzj.com>2024-07-17 18:14:32 +0200
commite1ac52594d3c9bbe8b5d58d5ebb19db3b4e612a8 (patch)
treeb10b89ca862321f663aae3515b0248b24cf46259
parentcore/unit: introduce unit_set_freezer_state, make logging consistent (diff)
downloadsystemd-e1ac52594d3c9bbe8b5d58d5ebb19db3b4e612a8.tar.xz
systemd-e1ac52594d3c9bbe8b5d58d5ebb19db3b4e612a8.zip
core/unit: introduce unit_freezer_complete, correctly report end state
-rw-r--r--src/core/cgroup.c8
-rw-r--r--src/core/unit.c24
-rw-r--r--src/core/unit.h3
3 files changed, 12 insertions, 23 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 98f33fe580..e9eb6f96e8 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -4044,12 +4044,8 @@ static int unit_check_cgroup_events(Unit *u) {
/* Disregard freezer state changes due to operations not initiated by us.
* See: https://github.com/systemd/systemd/pull/13512/files#r416469963 and
* https://github.com/systemd/systemd/pull/13512#issuecomment-573007207 */
- if (values[1] && IN_SET(u->freezer_state, FREEZER_FREEZING, FREEZER_FREEZING_BY_PARENT, FREEZER_THAWING)) {
- if (streq(values[1], "0"))
- unit_thawed(u);
- else
- unit_frozen(u);
- }
+ if (values[1] && IN_SET(u->freezer_state, FREEZER_FREEZING, FREEZER_FREEZING_BY_PARENT, FREEZER_THAWING))
+ unit_freezer_complete(u, streq(values[1], "0") ? FREEZER_RUNNING : FREEZER_FROZEN);
free(values[0]);
free(values[1]);
diff --git a/src/core/unit.c b/src/core/unit.c
index 01f2ca189c..2ef2a1fbe8 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -6267,26 +6267,20 @@ void unit_set_freezer_state(Unit *u, FreezerState state) {
unit_add_to_dbus_queue(u);
}
-void unit_frozen(Unit *u) {
- assert(u);
-
- u->freezer_state = u->freezer_state == FREEZER_FREEZING_BY_PARENT
- ? FREEZER_FROZEN_BY_PARENT
- : FREEZER_FROZEN;
-
- log_unit_debug(u, "Unit now %s.", freezer_state_to_string(u->freezer_state));
-
- bus_unit_send_pending_freezer_message(u, false);
-}
+void unit_freezer_complete(Unit *u, FreezerState kernel_state) {
+ bool expected;
-void unit_thawed(Unit *u) {
assert(u);
+ assert(IN_SET(kernel_state, FREEZER_RUNNING, FREEZER_FROZEN));
- u->freezer_state = FREEZER_RUNNING;
+ expected = IN_SET(u->freezer_state, FREEZER_RUNNING, FREEZER_THAWING) == (kernel_state == FREEZER_RUNNING);
- log_unit_debug(u, "Unit thawed.");
+ unit_set_freezer_state(u, expected ? freezer_state_finish(u->freezer_state) : kernel_state);
+ log_unit_info(u, "Unit now %s.", u->freezer_state == FREEZER_RUNNING ? "thawed" :
+ freezer_state_to_string(u->freezer_state));
- bus_unit_send_pending_freezer_message(u, false);
+ /* If the cgroup's final state is against what's requested by us, report as canceled. */
+ bus_unit_send_pending_freezer_message(u, /* canceled = */ !expected);
}
int unit_freezer_action(Unit *u, FreezerAction action) {
diff --git a/src/core/unit.h b/src/core/unit.h
index 2003b6a779..31a1a13df1 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -1040,8 +1040,7 @@ 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);
+void unit_freezer_complete(Unit *u, FreezerState kernel_state);
Condition *unit_find_failed_condition(Unit *u);