From 2a8ce43a4b7ff301378443f0de05c4e3d05d96b8 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 24 Mar 2022 13:56:26 +0900 Subject: [PATCH] power: add configuration for poweroff delay time Change-Id: I29fe716445cb197b66338d973c6acd1fc40890a8 Signed-off-by: Youngjae Cho --- conf/power.conf | 1 + src/power/power-handler.c | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/conf/power.conf b/conf/power.conf index 57a49fa..437c672 100644 --- a/conf/power.conf +++ b/conf/power.conf @@ -8,3 +8,4 @@ Option=silent [PowerState] TimeoutSleepSupport=yes ChangeStateMaxWaitSecond=10 +PowerOffDelaySecond=4 diff --git a/src/power/power-handler.c b/src/power/power-handler.c index b52bb6d..9e09401 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -51,7 +51,6 @@ #include "boot.h" #include "shared/plugin.h" -#define POWEROFF_DURATION 4 #define POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ #define POWEROFF_WAIT_MAX 10 /* 10 seconds */ #define POWEROFF_WAIT_SYSTEMD_MS (30 * 1000/*ms*/) /* 30 seconds */ @@ -83,6 +82,7 @@ enum poweroff_stage { POWEROFF_WAIT_OTHERS, /* Wait for other processes to clean up their resources */ }; +static int poweroff_delay_second = 0; static enum poweroff_stage poweroff_stage; static const char *poweroff_type_to_name(enum poweroff_type type) @@ -202,21 +202,23 @@ void poweroff_request_shutdown(void) raise(SIGUSR1); } -static void poweroff_wait_for_seconds(void) +static void poweroff_delay_for_seconds(void) { static int wait; struct timeval now; - int poweroff_duration = POWEROFF_DURATION; int check_duration = 0; + if (poweroff_delay_second == 0) + return; + watchdog_notify(); gettimeofday(&now, NULL); check_duration = now.tv_sec - tv_start_poweroff.tv_sec; - while (check_duration < poweroff_duration) { + while (check_duration < poweroff_delay_second) { if (wait == 0) { - _I("Wait poweroff %d %d.", check_duration, poweroff_duration); + _I("Wait poweroff %d %d.", check_duration, poweroff_delay_second); wait = 1; } usleep(100000); @@ -244,7 +246,7 @@ void poweroff_prepare(void) disable_systemd_journald(); disable_coredump_handler(); - poweroff_wait_for_seconds(); + poweroff_delay_for_seconds(); disable_display(); @@ -728,22 +730,15 @@ static int add_poweroff_option(enum poweroff_type type, const char *option) static int load_config(struct parse_result *result, void *user_data) { enum poweroff_type type; - int ret_val; - if (MATCH(result->section, "PowerOff")) + if (MATCH(result->section, "PowerOff") && MATCH(result->name, "Option")) { type = POWEROFF_TYPE_DIRECT; - else if (MATCH(result->section, "Reboot")) + add_poweroff_option(type, result->value); + } else if (MATCH(result->section, "Reboot") && MATCH(result->name, "Option")) { type = POWEROFF_TYPE_RESTART; - else - return 0; - - if (!MATCH(result->name, "Option")) - return 0; - - ret_val = add_poweroff_option(type, result->value); - if (ret_val < 0) { - _E("Failed to add %s option=%s", result->section, result->value); - return ret_val; + add_poweroff_option(type, result->value); + } else if (MATCH(result->section, "PowerState") && MATCH(result->name, "PowerOffDelaySecond")) { + sscanf(result->value, "%d", &poweroff_delay_second); } return 0; -- 2.7.4