mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-15 12:51:49 -05:00
Server: implemented a signal handler for SIGQUIT, SIGINT, SIGTERM, SIGHUP so the application exits nicely
This commit is contained in:
parent
305f2f7fe6
commit
415d2222d5
@ -18,9 +18,35 @@
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "loggerwithfile.h"
|
||||
#include "maincore.h"
|
||||
|
||||
void handler(int sig) {
|
||||
fprintf(stderr, "quit the application by signal(%d).\n", sig);
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
void catchUnixSignals(const std::vector<int>& quitSignals) {
|
||||
sigset_t blocking_mask;
|
||||
sigemptyset(&blocking_mask);
|
||||
|
||||
for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
|
||||
sigaddset(&blocking_mask, *it);
|
||||
}
|
||||
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = handler;
|
||||
sa.sa_mask = blocking_mask;
|
||||
sa.sa_flags = 0;
|
||||
|
||||
for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
|
||||
sigaction(*it, &sa, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *logger)
|
||||
{
|
||||
@ -30,6 +56,10 @@ static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *lo
|
||||
QCoreApplication::setApplicationName("SDRangelSrv");
|
||||
QCoreApplication::setApplicationVersion("3.9.0");
|
||||
|
||||
int catchSignals[] = {SIGQUIT, SIGINT, SIGTERM, SIGHUP};
|
||||
std::vector<int> vsig(catchSignals, catchSignals + sizeof(catchSignals) / sizeof(int));
|
||||
catchUnixSignals(vsig);
|
||||
|
||||
MainParser parser;
|
||||
parser.parse(a);
|
||||
MainCore m(logger, parser, &a);
|
||||
|
Loading…
Reference in New Issue
Block a user