#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 */
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)
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);
disable_systemd_journald();
disable_coredump_handler();
- poweroff_wait_for_seconds();
+ poweroff_delay_for_seconds();
disable_display();
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;