Skip to content

Commit 72e4edc

Browse files
authored
Merge pull request #1700 from nicolasnoble/signals
Adding signals support.
2 parents 2be1554 + ce133a6 commit 72e4edc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/main.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
1818
***************************************************************************/
1919

20+
#include <csignal>
2021
#include <filesystem>
2122
#include <iostream>
2223
#include <map>
@@ -191,10 +192,12 @@ int pcsxMain(int argc, char **argv) {
191192
// Creating the "system" global object first, making sure anything logging-related is
192193
// enabled as much as possible.
193194
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); });
194198
const auto &logfileArgOpt = args.get<std::string>("logfile");
195199
const PCSX::u8string logfileArg = MAKEU8(logfileArgOpt.has_value() ? logfileArgOpt->c_str() : "");
196200
if (!logfileArg.empty()) system->useLogfile(logfileArg);
197-
PCSX::g_system = system;
198201
std::filesystem::path self = PCSX::BinPath::getExecutablePath();
199202
std::filesystem::path binDir = std::filesystem::absolute(self).parent_path();
200203
system->setBinDir(binDir);
@@ -383,7 +386,7 @@ runner.init({
383386
// First, set up a closer. This makes sure that everything is shut down gracefully,
384387
// in the right order, once we exit the scope. This is because of how we're still
385388
// allowing exceptions to occur.
386-
Cleaner cleaner([&emulator, &system, &exitCode, luacovEnabled]() {
389+
Cleaner cleaner([&emulator, &system, &exitCode, luacovEnabled, sigint, sigterm]() {
387390
emulator->m_spu->close();
388391
emulator->m_cdrom->clearIso();
389392

@@ -402,6 +405,8 @@ runner.init({
402405
PCSX::g_emulator = nullptr;
403406

404407
exitCode = system->exitCode();
408+
std::signal(SIGINT, sigint);
409+
std::signal(SIGTERM, sigterm);
405410
delete system;
406411
PCSX::g_system = nullptr;
407412
});

0 commit comments

Comments
 (0)