diff --git a/src/ui/powerscreen.c b/src/ui/powerscreen.c index 24d2818..b96181a 100644 --- a/src/ui/powerscreen.c +++ b/src/ui/powerscreen.c @@ -24,19 +24,25 @@ static bool power_screen_dispatch(PowerScreen *screen, if (state->sel_down) { switch (screen->choice) { case POWER_SCREEN_RESTART_PROGRAM: - request_restart(); + request_exit(true); break; case POWER_SCREEN_REBOOT: LOG_VERBOSE("Rebooting..."); - reboot(RB_AUTOBOOT); - abort(); - // how did we even get here??? + if (system("reboot") != 0) { + warnx("reboot(8) failed"); + // just force it if doing it cleanly failed + reboot(RB_AUTOBOOT); + } + request_exit(false); break; case POWER_SCREEN_POWEROFF: LOG_VERBOSE("Powering off..."); - reboot(RB_POWEROFF); - abort(); - // how did we even get here??? + if (system("poweroff") != 0) { + warnx("poweroff(8) failed"); + // just force it if doing it cleanly failed + reboot(RB_POWEROFF); + } + request_exit(false); break; default: warnx("invalid power screen choice"); @@ -44,6 +50,7 @@ static bool power_screen_dispatch(PowerScreen *screen, LCD_DISPLAY_ON); return true; } + return false; } screen->choice = (screen->choice + state->up_down - state->down_down) % POWER_SCREEN_NCHOICE; diff --git a/src/ui/settzscreen.c b/src/ui/settzscreen.c index d742295..cc34dbb 100644 --- a/src/ui/settzscreen.c +++ b/src/ui/settzscreen.c @@ -476,7 +476,7 @@ static bool set_tz_screen_finish(SetTZScreen *screen, LOG_VERBOSE("Set timezone to: \"%s\"\n", buf); } free(buf); - request_restart(); + request_exit(true); } if (state->up_down || state->back_down || state->sel_down || state->down_down) { diff --git a/src/util.c b/src/util.c index 78a68a8..a7180fb 100644 --- a/src/util.c +++ b/src/util.c @@ -535,9 +535,9 @@ bool mkdirs(const char *path, mode_t mode) { return true; } -void request_restart() { +void request_exit(bool restart) { RUNNING = false; - SHOULD_RESTART = true; + SHOULD_RESTART = restart; } bool timed_wait(pid_t pid, int *out_status, useconds_t micro) { diff --git a/src/util.h b/src/util.h index eab7a5c..337370e 100644 --- a/src/util.h +++ b/src/util.h @@ -251,10 +251,11 @@ bool export_database_as_csv(sqlite3 *db, const char *dest); bool mkdirs(const char *path, mode_t mode); /* - * Request that this program re-invoke itself with the same arguments. Used to - * re-initialize configuration values. + * Request that this program exit. If RESTART request instead that it re-invoke + * itself with the same arguments. */ -void request_restart(void); +void request_exit(bool restart); + /* * waitpid(2) for PID for MICRO microseconds. If STATUS is not NULL, store the * exit status there. Use the various WIF* macros to test the status. This