Skip to content

Commit

Permalink
Call terminate() on Windows
Browse files Browse the repository at this point in the history
Closes #196
  • Loading branch information
dongresource committed Dec 16, 2021
1 parent c6ffcd4 commit a5582fe
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,20 @@ void terminate(int arg) {
exit(0);
}

#ifndef _WIN32
#ifdef _WIN32
static inline int winTerminate(DWORD arg) {
terminate(0);
return FALSE;
}
#endif

void initsignals() {
#ifdef _WIN32
if (!SetConsoleCtrlHandler(winTerminate, TRUE)) {
std::cerr << "[FATAL] Failed to set control handler" << std::endl;
exit(1);
}
#else
struct sigaction act;

memset((void*)&act, 0, sizeof(act));
Expand All @@ -82,8 +94,8 @@ void initsignals() {
perror("sigaction");
exit(1);
}
}
#endif
}

int main() {
#ifdef _WIN32
Expand All @@ -92,9 +104,8 @@ int main() {
std::cerr << "OpenFusion: WSAStartup failed" << std::endl;
exit(EXIT_FAILURE);
}
#else
initsignals();
#endif
initsignals();
settings::init();

std::cout << "[INFO] OpenFusion v" GIT_VERSION << std::endl;
Expand Down

0 comments on commit a5582fe

Please sign in to comment.