diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2017-02-26 21:25:36 +0300 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2017-02-26 21:25:36 +0300 |
commit | f2ea3dec5f11dece934549794f5e879c26605ef7 (patch) | |
tree | 22ffe0674ed12c5682920819c497bd8763e93c13 /src/murmur | |
parent | 21888b11b6916e2ed2b2c148ed22448a7b407d1d (diff) |
UnixMurmur: Add USR1 signal handler for reloading SSL settings.
Hot certificate reloading will use the USR1 signal.
This adds the meat of the implementation to UnixMurmur, such that
the PR for live-reloading SSL settings via the SIGUSR1 signal is
more easily digestable.
Diffstat (limited to 'src/murmur')
-rw-r--r-- | src/murmur/UnixMurmur.cpp | 36 | ||||
-rw-r--r-- | src/murmur/UnixMurmur.h | 6 |
2 files changed, 39 insertions, 3 deletions
diff --git a/src/murmur/UnixMurmur.cpp b/src/murmur/UnixMurmur.cpp index 71c8ab121..1e3e45efa 100644 --- a/src/murmur/UnixMurmur.cpp +++ b/src/murmur/UnixMurmur.cpp @@ -85,6 +85,7 @@ extern QFile *qfLog; int UnixMurmur::iHupFd[2]; int UnixMurmur::iTermFd[2]; +int UnixMurmur::iUsr1Fd[2]; UnixMurmur::UnixMurmur() { bRoot = true; @@ -99,13 +100,18 @@ UnixMurmur::UnixMurmur() { if (::socketpair(AF_UNIX, SOCK_STREAM, 0, iTermFd)) qFatal("Couldn't create TERM socketpair"); + if (::socketpair(AF_UNIX, SOCK_STREAM, 0, iUsr1Fd)) + qFatal("Couldn't create USR1 socketpair"); + qsnHup = new QSocketNotifier(iHupFd[1], QSocketNotifier::Read, this); qsnTerm = new QSocketNotifier(iTermFd[1], QSocketNotifier::Read, this); + qsnUsr1 = new QSocketNotifier(iUsr1Fd[1], QSocketNotifier::Read, this); connect(qsnHup, SIGNAL(activated(int)), this, SLOT(handleSigHup())); connect(qsnTerm, SIGNAL(activated(int)), this, SLOT(handleSigTerm())); + connect(qsnUsr1, SIGNAL(activated(int)), this, SLOT(handleSigUsr1())); - struct sigaction hup, term; + struct sigaction hup, term, usr1; hup.sa_handler = hupSignalHandler; sigemptyset(&hup.sa_mask); @@ -121,20 +127,31 @@ UnixMurmur::UnixMurmur() { if (sigaction(SIGTERM, &term, NULL)) qFatal("Failed to install SIGTERM handler"); + usr1.sa_handler = usr1SignalHandler; + sigemptyset(&usr1.sa_mask); + usr1.sa_flags = SA_RESTART; + + if (sigaction(SIGUSR1, &usr1, NULL)) + qFatal("Failed to install SIGUSR1 handler"); + umask(S_IRWXO); } UnixMurmur::~UnixMurmur() { delete qsnHup; delete qsnTerm; + delete qsnUsr1; qsnHup = NULL; qsnTerm = NULL; + qsnUsr1 = NULL; close(iHupFd[0]); close(iHupFd[1]); close(iTermFd[0]); close(iTermFd[1]); + close(iUsr1Fd[0]); + close(iUsr1Fd[1]); } void UnixMurmur::hupSignalHandler(int) { @@ -149,6 +166,12 @@ void UnixMurmur::termSignalHandler(int) { Q_UNUSED(len); } +void UnixMurmur::usr1SignalHandler(int) { + char a = 1; + ssize_t len = ::write(iUsr1Fd[0], &a, sizeof(a)); + Q_UNUSED(len); +} + // Keep these two synchronized with matching actions in DBus.cpp @@ -199,6 +222,17 @@ void UnixMurmur::handleSigTerm() { qsnTerm->setEnabled(true); } +void UnixMurmur::handleSigUsr1() { + qsnUsr1->setEnabled(false); + char tmp; + ssize_t len = ::read(iUsr1Fd[1], &tmp, sizeof(tmp)); + Q_UNUSED(len); + + qWarning("Received USR1 signal... Ignoring..."); + + qsnUsr1->setEnabled(true); +} + void UnixMurmur::setuid() { if (Meta::mp.uiUid != 0) { #ifdef Q_OS_DARWIN diff --git a/src/murmur/UnixMurmur.h b/src/murmur/UnixMurmur.h index d57bf80d2..71b5791f5 100644 --- a/src/murmur/UnixMurmur.h +++ b/src/murmur/UnixMurmur.h @@ -32,14 +32,16 @@ class UnixMurmur : public QObject { Q_DISABLE_COPY(UnixMurmur) protected: bool bRoot; - static int iHupFd[2], iTermFd[2]; - QSocketNotifier *qsnHup, *qsnTerm; + static int iHupFd[2], iTermFd[2], iUsr1Fd[2]; + QSocketNotifier *qsnHup, *qsnTerm, *qsnUsr1; static void hupSignalHandler(int); static void termSignalHandler(int); + static void usr1SignalHandler(int); public slots: void handleSigHup(); void handleSigTerm(); + void handleSigUsr1(); public: bool logToSyslog; |