power: reloacte marking poweroff option 04/286004/1 accepted/tizen/7.0/unified/20230103.055617
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 23 Dec 2022 01:17:08 +0000 (10:17 +0900)
committeryoungjae cho <y0.cho@samsung.com>
Mon, 26 Dec 2022 00:42:27 +0000 (00:42 +0000)
Poweroff option can be marked just on receiving the option from dbus
method. It is safer in that it prevents loss of option address due to
asynchronous process of power transition.

Change-Id: I77f7c81035d3281396c0aea0a8c96760f08d5334
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
(cherry picked from commit 470680f23c1c37d375238c43c7f7821977350814)

src/power/power-off.c
src/power/power-off.h
src/power/power.c

index 37cecc3..de68503 100644 (file)
@@ -60,6 +60,7 @@
 
 static struct timeval tv_start_poweroff;
 static int poweroff_delay_second = 0;
+static int silent_reboot = 0;
 
 static void poweroff_start_animation(void)
 {
@@ -220,6 +221,9 @@ static void mark_poweroff_option(uint64_t state, const char *option)
        else
                return;
 
+       if (option && strncmp(option, "silent", sizeof("silent")) == 0)
+               silent_reboot = 1;
+
        fd = open(optpath, O_RDWR|O_CREAT, S_IRUSR | S_IWUSR);
        if (fd < 0) {
                _E("Failed to create '%s'.", optpath);
@@ -291,15 +295,13 @@ static void system_shutdown_send_system_event(void)
        bundle_free(b);
 }
 
-void poweroff_prepare(uint64_t state, void *option)
+void poweroff_prepare(uint64_t state)
 {
        int vconf = VCONFKEY_SYSMAN_POWER_OFF_NONE;
 
        if (!is_poweroff_state(state))
                return;
 
-       mark_poweroff_option(state, option);
-
        if (state == DEVICED_POWER_STATE_POWEROFF)
                vconf = VCONFKEY_SYSMAN_POWER_OFF_DIRECT;
        else if (state == DEVICED_POWER_STATE_REBOOT)
@@ -313,7 +315,7 @@ void poweroff_prepare(uint64_t state, void *option)
        system_shutdown_send_system_event();
 
        /* Skip running animation if it is silent reboot */
-       if (option && strncmp(option, "silent", sizeof("silent")) == 0)
+       if (silent_reboot)
                return;
 
        poweroff_start_animation();
@@ -401,8 +403,10 @@ static GVariant *dbus_poweroff_option_handler(GDBusConnection *conn,
                goto out;
        }
 
+       mark_poweroff_option(next, option);
+
        CRITICAL_LOG("Poweroff pid=%d(%s) requests type=%s option=%s.", ret, comm, type, option);
-       power_request_change_state_strict(DEVICED_POWER_STATE_ALL, next, 9000, option);
+       power_request_change_state_strict(DEVICED_POWER_STATE_ALL, next, 9000, NULL);
 
 out:
        g_free(type);
index 7e961f7..bdef892 100644 (file)
@@ -34,7 +34,7 @@
 void power_off_init(void);
 int poweroff_check_revived(void);
 void poweroff_request_shutdown(int state);
-void poweroff_prepare(uint64_t state, void *option);
+void poweroff_prepare(uint64_t state);
 void poweroff_main(void *udata);
 
 #endif /* __DEVICED_POWER_OFF_H__ */
index e225839..42e0da3 100644 (file)
@@ -274,7 +274,7 @@ static void power_action_poweroff(void *data)
        // do not transition anymore after poweroff
        unregister_notifier(DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE, transition_request_callback);
 
-       poweroff_prepare(current, data);
+       poweroff_prepare(current);
        poweroff_main((void *)(intptr_t) current);
 }