Skip to content

Commit

Permalink
Add signal handlers for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace314159 committed Oct 4, 2023
1 parent d1c455b commit 641ff4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion gazebo/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,11 @@ void Server::Fini()
/////////////////////////////////////////////////
void Server::Run()
{
#ifndef _WIN32
// Now that we're about to run, install a signal handler to allow for
// graceful shutdown on Ctrl-C.
#ifdef _WIN32
signal(SIGINT, Server::SigInt);
#else
struct sigaction sigact;
sigact.sa_flags = 0;
sigact.sa_handler = Server::SigInt;
Expand Down
9 changes: 8 additions & 1 deletion gazebo/gazebo_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <sys/types.h>
#else
#include <process.hpp>
#include <signal.h>
#endif

#include "gazebo/common/Console.hh"
Expand Down Expand Up @@ -227,6 +228,11 @@ int main(int _argc, char **_argv)

std::atomic<bool> g_shouldExit = false;

void sig_handler(int /*signo*/)
{
g_shouldExit = true;
}

int main(int _argc, char **_argv)
{
if (_argc >= 2 &&
Expand All @@ -235,6 +241,8 @@ int main(int _argc, char **_argv)
return 0;
}

signal(SIGINT, sig_handler);

std::vector<std::string> argvServer;
std::vector<std::string> argvClient;

Expand Down Expand Up @@ -272,7 +280,6 @@ int main(int _argc, char **_argv)
{
g_shouldExit = true;
}

}

// Cleanup
Expand Down
4 changes: 3 additions & 1 deletion gazebo/gui/GuiIface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,11 @@ bool gui::run(int _argc, char **_argv)

mainWindow->RenderWidget()->AddPlugins(g_plugins_to_load);

#ifndef _WIN32
// Now that we're about to run, install a signal handler to allow for
// graceful shutdown on Ctrl-C.
#ifdef _WIN32
signal(SIGINT, signal_handler);
#else
struct sigaction sigact;
sigact.sa_flags = 0;
sigact.sa_handler = signal_handler;
Expand Down

0 comments on commit 641ff4c

Please sign in to comment.