new USR1 shutdown function

This commit is contained in:
Vincent-FK 2021-01-11 18:50:17 +01:00
parent d07ca9c5e7
commit 473e9515ec
2 changed files with 21 additions and 20 deletions

View File

@ -54,6 +54,7 @@ typedef enum {ASPECT_RATIOS} ENUM_ASPECT_RATIOS_TYPES;
#define SHELL_CMD_USB_CHECK_IS_SHARING "share is_sharing" #define SHELL_CMD_USB_CHECK_IS_SHARING "share is_sharing"
#define SHELL_CMD_POWERDOWN "shutdown_funkey" #define SHELL_CMD_POWERDOWN "shutdown_funkey"
#define SHELL_CMD_SCHEDULE_POWERDOWN "sched_shutdown" #define SHELL_CMD_SCHEDULE_POWERDOWN "sched_shutdown"
#define SHELL_CMD_CANCEL_SCHED_POWERDOWN "cancel_sched_powerdown"
#define SHELL_CMD_SET_LAUNCHER_GMENU2X "set_launcher gmenu2x" #define SHELL_CMD_SET_LAUNCHER_GMENU2X "set_launcher gmenu2x"
#define SHELL_CMD_SET_LAUNCHER_RETROFE "set_launcher retrofe" #define SHELL_CMD_SET_LAUNCHER_RETROFE "set_launcher retrofe"

View File

@ -47,6 +47,7 @@
#if defined(__linux) || defined(__APPLE__) #if defined(__linux) || defined(__APPLE__)
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include <errno.h> #include <errno.h>
#include <cstring> #include <cstring>
#endif #endif
@ -577,6 +578,7 @@ void RetroFE::run( )
if ( collectionInputClear ) if ( collectionInputClear )
{ {
// Empty event queue // Empty event queue
SDL_Event e; SDL_Event e;
while ( SDL_PollEvent( &e ) ); while ( SDL_PollEvent( &e ) );
input_.resetStates( ); input_.resetStates( );
@ -1554,27 +1556,25 @@ void RetroFE::handle_sigusr1(int sig)
/* Quick save and turn off the console */ /* Quick save and turn off the console */
void RetroFE::quick_poweroff() void RetroFE::quick_poweroff()
{ {
/* Vars */ /* Send command to cancel any previously scheduled powerdown */
char shell_cmd[200]; if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
FILE *fp; {
/* Countdown is still ticking, so better do nothing
/* Send command to kill any previously scheduled shutdown */ than start writing and get interrupted!
sprintf(shell_cmd, "pkill %s", SHELL_CMD_SCHEDULE_POWERDOWN); */
fp = popen(shell_cmd, "r"); printf("Failed to cancel scheduled shutdown\n");
if (fp == NULL) {
printf("Failed to run command %s\n", shell_cmd);
std::stringstream ss; std::stringstream ss;
ss << "Failed to run command " << shell_cmd; ss << "Failed to run command " << SHELL_CMD_CANCEL_SCHED_POWERDOWN;
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() ); Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() );
exit(0);
} }
/* Clean Poweroff */ /* Perform Instant Play save and shutdown */
sprintf(shell_cmd, "%s", SHELL_CMD_POWERDOWN); execlp(SHELL_CMD_POWERDOWN, SHELL_CMD_POWERDOWN);
fp = popen(shell_cmd, "r");
if (fp == NULL) { /* Should not be reached */
printf("Failed to run command %s\n", shell_cmd); printf("Failed to perform shutdown\n");
std::stringstream ss;
ss << "Failed to run command " << shell_cmd; /* Exit Emulator */
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() ); exit(0);
}
} }