Skip to content

Commit 0839722

Browse files
committed
new USR1 shutdown function
1 parent ac40292 commit 0839722

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/funkeymenu.h

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

src/gmenu2x.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,24 @@ static void quit_all(int err) {
125125
/* Quick save and turn off the console */
126126
static void quick_poweroff()
127127
{
128-
/* Vars */
129-
char shell_cmd[200];
130-
FILE *fp;
131-
132-
/* Send command to kill any previously scheduled shutdown */
133-
sprintf(shell_cmd, "pkill %s", SHELL_CMD_SCHEDULE_POWERDOWN);
134-
fp = popen(shell_cmd, "r");
135-
if (fp == NULL) {
136-
ERROR("Failed to run command %s\n", shell_cmd);
128+
/* Send command to cancel any previously scheduled powerdown */
129+
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
130+
{
131+
/* Countdown is still ticking, so better do nothing
132+
than start writing and get interrupted!
133+
*/
134+
printf("Failed to cancel scheduled shutdown\n");
135+
exit(0);
137136
}
138137

139-
/* Clean Poweroff */
140-
sprintf(shell_cmd, "%s", SHELL_CMD_POWERDOWN);
141-
fp = popen(shell_cmd, "r");
142-
if (fp == NULL) {
143-
ERROR("Failed to run command %s\n", shell_cmd);
144-
}
138+
/* Perform Instant Play save and shutdown */
139+
execlp(SHELL_CMD_POWERDOWN, SHELL_CMD_POWERDOWN);
140+
141+
/* Should not be reached */
142+
printf("Failed to perform Instant Play save and shutdown\n");
143+
144+
/* Exit Emulator */
145+
exit(0);
145146
}
146147

147148
/* Handler for SIGUSR1, caused by closing the console */

0 commit comments

Comments
 (0)