|
47 | 47 | #if defined(__linux) || defined(__APPLE__) |
48 | 48 | #include <sys/stat.h> |
49 | 49 | #include <sys/types.h> |
| 50 | +#include <unistd.h> |
50 | 51 | #include <errno.h> |
51 | 52 | #include <cstring> |
52 | 53 | #endif |
@@ -576,7 +577,8 @@ void RetroFE::run( ) |
576 | 577 | config_.getProperty( "collectionInputClear", collectionInputClear ); |
577 | 578 | if ( collectionInputClear ) |
578 | 579 | { |
579 | | - // Empty event queue |
| 580 | + // Empty event queue |
| 581 | + |
580 | 582 | SDL_Event e; |
581 | 583 | while ( SDL_PollEvent( &e ) ); |
582 | 584 | input_.resetStates( ); |
@@ -1554,27 +1556,25 @@ void RetroFE::handle_sigusr1(int sig) |
1554 | 1556 | /* Quick save and turn off the console */ |
1555 | 1557 | void RetroFE::quick_poweroff() |
1556 | 1558 | { |
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"); |
1566 | 1566 | std::stringstream ss; |
1567 | | - ss << "Failed to run command " << shell_cmd; |
| 1567 | + ss << "Failed to run command " << SHELL_CMD_CANCEL_SCHED_POWERDOWN; |
1568 | 1568 | Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() ); |
| 1569 | + exit(0); |
1569 | 1570 | } |
1570 | 1571 |
|
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); |
1580 | 1580 | } |
0 commit comments