]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_sslrehashsignal.cpp
f5b3563b25fd2d7653e28a3e7590a043a0629874
[user/henk/code/inspircd.git] / src / modules / extra / m_sslrehashsignal.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21
22 static volatile sig_atomic_t signaled;
23
24 class ModuleSSLRehashSignal : public Module
25 {
26  private:
27         static void SignalHandler(int)
28         {
29                 signaled = 1;
30         }
31
32  public:
33         ~ModuleSSLRehashSignal()
34         {
35                 signal(SIGUSR1, SIG_IGN);
36         }
37
38         void init()
39         {
40                 signal(SIGUSR1, SignalHandler);
41         }
42
43         void OnBackgroundTimer(time_t) CXX11_OVERRIDE
44         {
45                 if (!signaled)
46                         return;
47
48                 const std::string feedbackmsg = "Got SIGUSR1, reloading SSL credentials";
49                 ServerInstance->SNO->WriteGlobalSno('a', feedbackmsg);
50                 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, feedbackmsg);
51
52                 const std::string str = "ssl";
53                 FOREACH_MOD(OnModuleRehash, (NULL, str));
54                 signaled = 0;
55         }
56
57         Version GetVersion() CXX11_OVERRIDE
58         {
59                 return Version("Reloads SSL credentials on SIGUSR1", VF_VENDOR);
60         }
61 };
62
63 MODULE_INIT(ModuleSSLRehashSignal)