-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
42 lines (31 loc) · 978 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <QCoreApplication>
#include <QDateTime>
#include <QMetaObject>
#include <signal.h>
#include "InVpn.hpp"
static InVpn *_glob;
static void signal_prog_end(int, siginfo_t *, void *) {
QMetaObject::invokeMethod(_glob, "quit", Qt::QueuedConnection);
}
static void signal_prog_restart(int, siginfo_t *, void *) {
QMetaObject::invokeMethod(_glob, "restart", Qt::QueuedConnection);
}
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
// got a better seed?
qsrand(QDateTime::currentMSecsSinceEpoch() & 0xffffffff);
InVpn vpn;
if (!vpn.isValid()) return 1;
_glob = &vpn;
// catch signals, send to Qt object by using Qt::QueuedConnection
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = signal_prog_end;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sa.sa_sigaction = signal_prog_restart;
sigaction(SIGUSR2, &sa, NULL);
return app.exec();
}