17
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18
18
***************************************************************************/
19
19
20
+ #include < csignal>
20
21
#include < filesystem>
21
22
#include < iostream>
22
23
#include < map>
@@ -191,10 +192,12 @@ int pcsxMain(int argc, char **argv) {
191
192
// Creating the "system" global object first, making sure anything logging-related is
192
193
// enabled as much as possible.
193
194
SystemImpl *system = new SystemImpl (args);
195
+ PCSX::g_system = system;
196
+ auto sigint = std::signal (SIGINT, [](auto signal) { PCSX::g_system->quit (-1 ); });
197
+ auto sigterm = std::signal (SIGTERM, [](auto signal) { PCSX::g_system->quit (-1 ); });
194
198
const auto &logfileArgOpt = args.get <std::string>(" logfile" );
195
199
const PCSX::u8string logfileArg = MAKEU8 (logfileArgOpt.has_value () ? logfileArgOpt->c_str () : " " );
196
200
if (!logfileArg.empty ()) system->useLogfile (logfileArg);
197
- PCSX::g_system = system;
198
201
std::filesystem::path self = PCSX::BinPath::getExecutablePath ();
199
202
std::filesystem::path binDir = std::filesystem::absolute (self).parent_path ();
200
203
system->setBinDir (binDir);
@@ -383,7 +386,7 @@ runner.init({
383
386
// First, set up a closer. This makes sure that everything is shut down gracefully,
384
387
// in the right order, once we exit the scope. This is because of how we're still
385
388
// allowing exceptions to occur.
386
- Cleaner cleaner ([&emulator, &system, &exitCode, luacovEnabled]() {
389
+ Cleaner cleaner ([&emulator, &system, &exitCode, luacovEnabled, sigint, sigterm ]() {
387
390
emulator->m_spu ->close ();
388
391
emulator->m_cdrom ->clearIso ();
389
392
@@ -402,6 +405,8 @@ runner.init({
402
405
PCSX::g_emulator = nullptr ;
403
406
404
407
exitCode = system->exitCode ();
408
+ std::signal (SIGINT, sigint);
409
+ std::signal (SIGTERM, sigterm);
405
410
delete system;
406
411
PCSX::g_system = nullptr ;
407
412
});
0 commit comments