Skip to content

Commit 473e951

Browse files
committed
new USR1 shutdown function
1 parent d07ca9c commit 473e951

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

RetroFE/Source/Menu/MenuMode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef enum {ASPECT_RATIOS} ENUM_ASPECT_RATIOS_TYPES;
5454
#define SHELL_CMD_USB_CHECK_IS_SHARING "share is_sharing"
5555
#define SHELL_CMD_POWERDOWN "shutdown_funkey"
5656
#define SHELL_CMD_SCHEDULE_POWERDOWN "sched_shutdown"
57+
#define SHELL_CMD_CANCEL_SCHED_POWERDOWN "cancel_sched_powerdown"
5758
#define SHELL_CMD_SET_LAUNCHER_GMENU2X "set_launcher gmenu2x"
5859
#define SHELL_CMD_SET_LAUNCHER_RETROFE "set_launcher retrofe"
5960

RetroFE/Source/RetroFE.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#if defined(__linux) || defined(__APPLE__)
4848
#include <sys/stat.h>
4949
#include <sys/types.h>
50+
#include <unistd.h>
5051
#include <errno.h>
5152
#include <cstring>
5253
#endif
@@ -576,7 +577,8 @@ void RetroFE::run( )
576577
config_.getProperty( "collectionInputClear", collectionInputClear );
577578
if ( collectionInputClear )
578579
{
579-
// Empty event queue
580+
// Empty event queue
581+
580582
SDL_Event e;
581583
while ( SDL_PollEvent( &e ) );
582584
input_.resetStates( );
@@ -1554,27 +1556,25 @@ void RetroFE::handle_sigusr1(int sig)
15541556
/* Quick save and turn off the console */
15551557
void RetroFE::quick_poweroff()
15561558
{
1557-
/* Vars */
1558-
char shell_cmd[200];
1559-
FILE *fp;
1560-
1561-
/* Send command to kill any previously scheduled shutdown */
1562-
sprintf(shell_cmd, "pkill %s", SHELL_CMD_SCHEDULE_POWERDOWN);
1563-
fp = popen(shell_cmd, "r");
1564-
if (fp == NULL) {
1565-
printf("Failed to run command %s\n", shell_cmd);
1559+
/* Send command to cancel any previously scheduled powerdown */
1560+
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
1561+
{
1562+
/* Countdown is still ticking, so better do nothing
1563+
than start writing and get interrupted!
1564+
*/
1565+
printf("Failed to cancel scheduled shutdown\n");
15661566
std::stringstream ss;
1567-
ss << "Failed to run command " << shell_cmd;
1567+
ss << "Failed to run command " << SHELL_CMD_CANCEL_SCHED_POWERDOWN;
15681568
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() );
1569+
exit(0);
15691570
}
15701571

1571-
/* Clean Poweroff */
1572-
sprintf(shell_cmd, "%s", SHELL_CMD_POWERDOWN);
1573-
fp = popen(shell_cmd, "r");
1574-
if (fp == NULL) {
1575-
printf("Failed to run command %s\n", shell_cmd);
1576-
std::stringstream ss;
1577-
ss << "Failed to run command " << shell_cmd;
1578-
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() );
1579-
}
1572+
/* Perform Instant Play save and shutdown */
1573+
execlp(SHELL_CMD_POWERDOWN, SHELL_CMD_POWERDOWN);
1574+
1575+
/* Should not be reached */
1576+
printf("Failed to perform shutdown\n");
1577+
1578+
/* Exit Emulator */
1579+
exit(0);
15801580
}

0 commit comments

Comments
 (0)