From 470680f23c1c37d375238c43c7f7821977350814 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 23 Dec 2022 10:17:08 +0900 Subject: [PATCH] power: reloacte marking poweroff option 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 --- src/power/power-off.c | 14 +++++++++----- src/power/power-off.h | 2 +- src/power/power.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/power/power-off.c b/src/power/power-off.c index 37cecc3..de68503 100644 --- a/src/power/power-off.c +++ b/src/power/power-off.c @@ -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); diff --git a/src/power/power-off.h b/src/power/power-off.h index 7e961f7..bdef892 100644 --- a/src/power/power-off.h +++ b/src/power/power-off.h @@ -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__ */ diff --git a/src/power/power.c b/src/power/power.c index e225839..42e0da3 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -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); } -- 2.7.4