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