Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip keymon's force shutdown if runtime is already shutting down #1579

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include <sys/mman.h>
#include <sys/reboot.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>

#include "system/axp.h"
#include "utils/msleep.h"
#include "system/display.h"
#include "system/battery.h"
#include "system/device_model.h"
#include "system/display.h"
#include "system/keymap_hw.h"
#include "system/osd.h"
#include "system/rumble.h"
Expand All @@ -29,6 +29,7 @@
#include "utils/file.h"
#include "utils/flags.h"
#include "utils/log.h"
#include "utils/msleep.h"
#include "utils/process.h"
#include "utils/str.h"

Expand Down Expand Up @@ -176,7 +177,7 @@ void quit(int exitcode)
//
// Shutdown
//
void shutdown(void)
void force_shutdown(void)
{
set_system_shutdown();
screenshot_system();
Expand All @@ -191,6 +192,14 @@ void shutdown(void)
exit(0);
}

void wait(int seconds)
{
time_t t = time(NULL);
while ((time(NULL) - t) < seconds) {
sleep(1);
}
}

//
// [onion] deepsleep if MainUI/gameSwitcher/retroarch is running
//
Expand Down Expand Up @@ -233,10 +242,11 @@ void deepsleep(void)
terminate_drastic();
}

sleep(10);
// catch the resolution change signal on MMV4
sleep(20);
shutdown();
// Wait 30s before forcing a shutdown
wait(30);
if (!temp_flag_get("shutting_down")) {
force_shutdown();
}
}

//
Expand Down Expand Up @@ -327,9 +337,9 @@ void turnOffScreen(void)
suspend_exec(stay_awake ? -1 : timeout);
}

static void *runWritingSettingsThread(void* param)
static void *runWritingSettingsThread(void *param)
{
bool *isWritingSettingsThreadActive = (bool*)param;
bool *isWritingSettingsThreadActive = (bool *)param;
*isWritingSettingsThreadActive = true;
settings_shm_write();
settings_save();
Expand Down Expand Up @@ -469,7 +479,7 @@ int main(void)
else if (repeat_power >= REPEAT_SEC(5)) {
short_pulse();
remove(CMD_TO_RUN_PATH);
shutdown(); // 10sec force shutdown
force_shutdown(); // 10sec force shutdown
}
break;
}
Expand Down Expand Up @@ -756,8 +766,7 @@ int main(void)

if (settings_changed || needWriteSettings) {
needWriteSettings = true;
if (!isWritingSettingsThreadActive)
{
if (!isWritingSettingsThreadActive) {
needWriteSettings = false;
pthread_create(&writingSettingsThread, NULL, runWritingSettingsThread, &isWritingSettingsThreadActive);
}
Expand Down
6 changes: 3 additions & 3 deletions static/build/.tmp_update/runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ launch_switcher() {

check_off_order() {
if [ -f /tmp/.offOrder ]; then
touch /tmp/shutting_down

#EmuDeck - CheckOff scripts
check_off_scripts=$(find "$sysdir/checkoff" -type f -name "*.sh")
Expand Down Expand Up @@ -654,8 +655,8 @@ mute_theme_bgm() {
}

create_swap() {
swapfile="/mnt/SDCARD/cachefile"
if [ ! -e "$swapfile" ] ; then
swapfile="/mnt/SDCARD/cachefile"
if [ ! -e "$swapfile" ]; then
log "Creating swap file"
dd if=/dev/zero of="$swapfile" bs=1M count=128
mkswap "$swapfile"
Expand All @@ -664,7 +665,6 @@ create_swap() {
swapon "$swapfile"
}


init_system() {
log "\n:: Init system"

Expand Down
Loading