Change timeout way of reboot command 13/259813/9 submit/tizen/20210616.024518
authortaemin.yeom <taemin.yeom@samsung.com>
Tue, 15 Jun 2021 06:16:43 +0000 (15:16 +0900)
committertaemin.yeom <taemin.yeom@samsung.com>
Wed, 16 Jun 2021 01:34:54 +0000 (10:34 +0900)
Change-Id: I92f4f05a367c6229e6781f29457c89682d45de14
Signed-off-by: taemin.yeom <taemin.yeom@samsung.com>
src/power-command/command.c

index 397174d..868a666 100644 (file)
 #include <libsyscommon/libgdbus.h>
 #include <libsyscommon/libsystemd.h>
 
-#define DEVICED_CALL_MAX_TRIES         60
-#define DEVICED_CALL_INTERVAL_SECONDS  2
-#define DEVICED_SERVICE_NAME           "deviced.service"
+#include <device/power.h>
+
+#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");