power: Remove erronous DIRECT poweroff type 28/199928/2
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 14 Feb 2019 15:47:00 +0000 (16:47 +0100)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 19 Feb 2019 08:19:42 +0000 (08:19 +0000)
Commit 51849e1cad ("power: Rework handling of repeated poweroff/reboot
request") mistakenly introduced POWEROFF type.  Before that commit
"DIRECT" type was used to mean POWEROFF.

This commit reverts to original behaviour, dropping DIRECT type
for all new uses but retains constant for compatiblity.

Change-Id: I4ddd5fa7fe45dd54bd9a597ed36b989b93a2f3f8

src/core/main.c
src/power/power-handler.c
src/power/power-handler.h

index a2ece6b..9ff0cd1 100644 (file)
@@ -98,7 +98,7 @@ static int deviced_main(int argc, char **argv)
                /* Restarted: deviced was terminated
                 * in middle of reboot/poweroff - resume procedure
                 */
-               poweroff_procedure();
+               powerdown();
                return 0;
        }
 
index 589dd02..f0fa00f 100644 (file)
@@ -74,14 +74,13 @@ static bool during_poweroff;
 static dd_list *poweroff_handles;
 
 static char *poweroff_type_flagpaths[] = { // index denotes type
-       [POWER_OFF_DIRECT] = POWER_FLAG_POWEROFF,
+       [POWER_OFF_POWEROFF] = POWER_FLAG_POWEROFF,
        [POWER_OFF_REBOOT] = POWER_FLAG_REBOOT,
 };
 static char *poweroff_type_names[] = { // index denotes type
        [POWER_OFF_POWEROFF] = POWER_POWEROFF,
        [POWER_OFF_POPUP] = PWROFF_POPUP,
        [POWER_OFF_REBOOT] = POWER_REBOOT,
-       [POWER_OFF_DIRECT] = "",
 };
 
 static char *poweroff_type_to_name(enum poweroff_type type)
@@ -189,7 +188,31 @@ static bool disable_coredump_handler(void)
        return is_ok;
 }
 
-static void powerdown(void)
+static void poweroff_request_shutdown()
+{
+       _I("Requested power off via systemd");
+
+       char *method;
+
+       if (poweroff_opt.type == POWER_OFF_REBOOT)
+               method = "Reboot";
+       else if (poweroff_opt.type == POWER_OFF_POWEROFF)
+               method = "PowerOff";
+       else {
+               _E("poweroff invalid type (%d)", poweroff_opt.type);
+               return;
+       }
+
+       dbus_handle_method_sync_timeout(SYSTEMD_DBUS_DEST,
+                                       SYSTEMD_DBUS_PATH,
+                                       SYSTEMD_DBUS_IFACE_MANAGER,
+                                       method,
+                                       NULL,
+                                       NULL,
+                                       POWEROFF_WAIT_SYSTEMD_MS);
+}
+
+void powerdown(void)
 {
        static int wait;
        struct timeval now;
@@ -223,50 +246,8 @@ static void powerdown(void)
        }
 
        watchdog_notify();
-}
-
-static void poweroff_request_shutdown()
-{
-       _I("Requested power off via systemd");
-
-       char *method;
 
-       if (poweroff_opt.type == POWER_OFF_REBOOT)
-               method = "Reboot";
-       else if (poweroff_opt.type == POWER_OFF_POWEROFF)
-               method = "PowerOff";
-       else {
-               _E("poweroff invalid type (%d)", poweroff_opt.type);
-               return;
-       }
-
-       dbus_handle_method_sync_timeout(SYSTEMD_DBUS_DEST,
-                                       SYSTEMD_DBUS_PATH,
-                                       SYSTEMD_DBUS_IFACE_MANAGER,
-                                       method,
-                                       NULL,
-                                       NULL,
-                                       POWEROFF_WAIT_SYSTEMD_MS);
-}
-
-static void poweroff_direct(void)
-{
-       _I("Requested power off without systemd (direct call)");
-       if (syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
-                   LINUX_REBOOT_CMD_POWER_OFF, NULL) < 0)
-               _E("Failed to poweroff (%d)", errno);
-}
-
-int poweroff_procedure(void)
-{
-       powerdown();
-
-       if (poweroff_opt.type == POWER_OFF_DIRECT)
-               poweroff_direct();
-       else
-               poweroff_request_shutdown();
-
-       return 0;
+       poweroff_request_shutdown();
 }
 
 int check_power_flag(void)
@@ -336,10 +317,8 @@ static void poweroff_remove_handle(pid_t pid)
 
 static gboolean poweroff_timeout_cb(void *data)
 {
-       int ret;
-       pid_t pid;
+       pid_t pid = (pid_t)((intptr_t)data);
 
-       pid = (pid_t)((intptr_t)data);
        poweroff_remove_handle(pid);
 
        if (DD_LIST_LENGTH(poweroff_handles)) {
@@ -368,9 +347,7 @@ static gboolean poweroff_timeout_cb(void *data)
        /* TODO for notify. will be removed asap. */
        vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, poweroff_opt.type);
 
-       ret = poweroff_procedure();
-       if (ret < 0)
-               _E("Failed to %s (%d)", name, ret);
+       powerdown();
 
 out:
        if (disp_plgn.update_pm_setting)
@@ -488,7 +465,6 @@ static void poweroff_send_broadcast(int status)
                                                g_variant_new("(i)", status));
 }
 
-
 static int power_execute_pid(char *type, char *option, pid_t pid)
 {
        if (during_poweroff) {
@@ -790,7 +766,6 @@ static void power_init(void *data)
        register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
 
        add_poweroff_option(POWER_OFF_POWEROFF, NULL);
-       add_poweroff_option(POWER_OFF_DIRECT, NULL);
        add_poweroff_option(POWER_OFF_RESTART, NULL);
        add_poweroff_option(POWER_OFF_POPUP, NULL);
 
index 968e17a..551356c 100644 (file)
@@ -36,9 +36,9 @@ enum poweroff_type {
        POWER_OFF_NONE = POWER_OFF_INVALID,  // compat only
        POWER_OFF_POPUP,
        POWER_OFF_POWEROFF, /* replaces POWER_OFF_DIRECT */
+       POWER_OFF_DIRECT = POWER_OFF_POWEROFF, // compat only
        POWER_OFF_REBOOT,
        POWER_OFF_RESTART = POWER_OFF_REBOOT, // compat only
-       POWER_OFF_DIRECT,
 };
 
 struct power_option {
@@ -53,6 +53,6 @@ struct poweroff_handle {
 };
 
 int check_power_flag(void);
-int poweroff_procedure(void);
+void powerdown(void);
 
 #endif /* __POWER_HANDLE_H__ */