From 0d9a89c717cd0f5f69a05fbe5bc7d24dae558826 Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Thu, 20 Aug 2026 01:28:05 +0200 Subject: [PATCH] fix --- tools/server/server-common.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp index 47f5e1886d..0c578d7d33 100644 --- a/tools/server/server-common.cpp +++ b/tools/server/server-common.cpp @@ -1979,19 +1979,24 @@ void server_sleep_rst::init(int argc, char ** argv) { return; } + // note: the env var is kept, is_boot_to_sleep() reads it during the whole process lifetime try { boot_state = json::parse(state); } catch (const std::exception & e) { SRV_ERR("failed to read the state left by the previous process: %s\n", e.what()); + common_set_env(SLEEP_STATE_ENV, ""); // unusable, boot normally instead } - - // clear it now, so that child processes do not inherit it - common_set_env(SLEEP_STATE_ENV, ""); } void server_sleep_rst::enable(common_params & params) { - if (params.sleep_mode != COMMON_SLEEP_MODE_RST) { + // the state left by the previous process is unusable without the restart, drop it + auto disable = [this]() { boot_state = json(); + common_set_env(SLEEP_STATE_ENV, ""); + }; + + if (params.sleep_mode != COMMON_SLEEP_MODE_RST) { + disable(); return; } @@ -1999,7 +2004,7 @@ void server_sleep_rst::enable(common_params & params) { // exec() can only restart a standalone process SRV_WRN("%s", "--sleep-mode rst is not supported in this mode, using --sleep-mode free\n"); params.sleep_mode = COMMON_SLEEP_MODE_FREE; - boot_state = json(); + disable(); return; }