From 382352ee8799cff282dc663ab7afc475e814d2d2 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 15 Jun 2021 15:16:43 +0900 Subject: [PATCH] Change timeout way of reboot command Change-Id: I92f4f05a367c6229e6781f29457c89682d45de14 Signed-off-by: taemin.yeom --- src/power-command/command.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/power-command/command.c b/src/power-command/command.c index 397174d..868a666 100644 --- a/src/power-command/command.c +++ b/src/power-command/command.c @@ -33,9 +33,11 @@ #include #include -#define DEVICED_CALL_MAX_TRIES 60 -#define DEVICED_CALL_INTERVAL_SECONDS 2 -#define DEVICED_SERVICE_NAME "deviced.service" +#include + +#define DEVICED_CALL_MAX_SECONDS 120 +#define DEVICED_CALL_INTERVAL_SECONDS 1 +#define DEVICED_SERVICE_NAME "deviced.service" /* State can be checked manually by calling: * dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/deviced_2eservice org.freedesktop.DBus.Properties.Get string:org.freedesktop.systemd1.Unit string:ActiveState @@ -66,8 +68,12 @@ static bool service_is_inactive(const char *service) static bool deviced_call_poweroff_once(const char *action, const char *extra_option) { + static bool reboot_triggered = false; assert(action); + if (reboot_triggered) + return true; + int ret_dbus = extra_option ? gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOffWithOption", g_variant_new("(ss)", action, extra_option), NULL) : gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, "PowerOff", g_variant_new("(s)", action), NULL) @@ -77,29 +83,30 @@ static bool deviced_call_poweroff_once(const char *action, const char *extra_opt return false; } else CRITICAL_LOG("Succesfully requested shutdown using deviced"); + + reboot_triggered = true; return true; } static bool deviced_call_poweroff(const char *action, const char *extra_option) { - for (int i = 0; i < DEVICED_CALL_MAX_TRIES; i++) { + struct timespec begin, now; + device_power_request_lock(POWER_LOCK_CPU, 0); + clock_gettime(CLOCK_MONOTONIC, &begin); + + while (true) { if (service_is_inactive(DEVICED_SERVICE_NAME)) { CRITICAL_LOG(DEVICED_SERVICE_NAME " is inactive, will not request shutdown to it"); return false; } - if (deviced_call_poweroff_once(action, extra_option)) { - /* Don't exit yet as this will cause "normal" systemd poweroff to happen, - * likely before deviced poweroff completes - */ - for (;;) - pause(); - return true; - } - - CRITICAL_LOG("Failed to request shutdown to deviced (try %d of %d). Will sleep %d seconds.", - i, DEVICED_CALL_MAX_TRIES, DEVICED_CALL_INTERVAL_SECONDS); + deviced_call_poweroff_once(action, extra_option); + CRITICAL_LOG("Deviced call poweroff and will sleep %d second.", DEVICED_CALL_INTERVAL_SECONDS); sleep(DEVICED_CALL_INTERVAL_SECONDS); + + clock_gettime(CLOCK_MONOTONIC, &now); + if ((now.tv_sec - begin.tv_sec) >= DEVICED_CALL_MAX_SECONDS) + break; } CRITICAL_LOG("Failed to shutdown system using deviced - falling back to systemd shutdown"); -- 2.7.4