2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "core/EventLoop.h"
44#include "core/DynamicLoader.h"
45#include "core/EventMultiplexer.h"
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
49#include "log/Logger.h"
50#include "utils/Config.h"
51#include "utils/Timeval.h"
52#include "utils/system/signal.h"
68 if (tick.length() < 13) {
69 tick.insert(0, 13 - tick.length(),
'0');
99 struct sigaction sact{};
100 sigemptyset(&sact.sa_mask);
102 sact.sa_handler = SIG_IGN;
104 struct sigaction oldPipeAct{};
105 sigaction(SIGPIPE, &sact, &oldPipeAct);
107 struct sigaction oldIntAct{};
108 sigaction(SIGINT, &sact, &oldIntAct);
110 struct sigaction oldTermAct{};
111 sigaction(SIGTERM, &sact, &oldTermAct);
113 struct sigaction oldAlarmAct{};
114 sigaction(SIGALRM, &sact, &oldAlarmAct);
116 struct sigaction oldHupAct{};
117 sigaction(SIGHUP, &sact, &oldHupAct);
121 if (utils::Config::init(argc, argv)) {
124 LOG(TRACE) <<
"SNode.C: Starting ... HELLO";
127 sigaction(SIGPIPE, &oldPipeAct,
nullptr);
128 sigaction(SIGINT, &oldIntAct,
nullptr);
129 sigaction(SIGTERM, &oldTermAct,
nullptr);
130 sigaction(SIGALRM, &oldAlarmAct,
nullptr);
131 sigaction(SIGHUP, &oldHupAct,
nullptr);
142 sigaddset(&newSet, SIGINT);
143 sigaddset(&newSet, SIGTERM);
144 sigaddset(&newSet, SIGALRM);
145 sigaddset(&newSet, SIGHUP);
148 sigprocmask(SIG_BLOCK, &newSet, &oldSet);
154 sigprocmask(SIG_SETMASK, &oldSet,
nullptr);
163 struct sigaction sact{};
164 sigemptyset(&sact.sa_mask);
166 sact.sa_handler = SIG_IGN;
168 struct sigaction oldPipeAct{};
169 sigaction(SIGPIPE, &sact, &oldPipeAct);
173 sigaction(SIGPIPE, &oldPipeAct,
nullptr);
178 PLOG(FATAL) <<
"Core: not initialized: No events will be processed\nCall SNodeC::init(argc, argv) before SNodeC::tick().";
185 struct sigaction sact{};
186 sigemptyset(&sact.sa_mask);
188 sact.sa_handler = SIG_IGN;
190 struct sigaction oldPipeAct{};
191 sigaction(SIGPIPE, &sact, &oldPipeAct);
195 struct sigaction oldIntAct{};
196 sigaction(SIGINT, &sact, &oldIntAct);
198 struct sigaction oldTermAct{};
199 sigaction(SIGTERM, &sact, &oldTermAct);
201 struct sigaction oldAlarmAct{};
202 sigaction(SIGALRM, &sact, &oldAlarmAct);
204 struct sigaction oldHupAct{};
205 sigaction(SIGHUP, &sact, &oldHupAct);
211 LOG(TRACE) <<
"Core::EventLoop: started";
217 switch (tickStatus) {
219 LOG(TRACE) <<
"Core::EventLoop: Stopped";
222 LOG(TRACE) <<
"Core::EventLoop: No Observer";
225 LOG(TRACE) <<
"Core::EventLoop: Interrupted";
228 PLOG(FATAL) <<
"Core::EventLoop: _tick()";
233 sigaction(SIGPIPE, &oldPipeAct,
nullptr);
234 sigaction(SIGTERM, &oldTermAct,
nullptr);
235 sigaction(SIGALRM, &oldAlarmAct,
nullptr);
236 sigaction(SIGHUP, &oldHupAct,
nullptr);
240 sigaction(SIGINT, &oldIntAct,
nullptr);
252 if (signal ==
"SIGUNKNOWN") {
253 signal = std::to_string(
stopsig);
257 LOG(TRACE) <<
"Core: Sending signal " << signal <<
" to all DescriptorEventReceivers";
268 auto t1 = std::chrono::system_clock::now();
269 const utils::
Timeval timeoutOp = timeout;
273 auto t2 = std::chrono::system_clock::now();
274 const std::chrono::duration<
double> seconds = t2 - t1;
276 timeout
-= seconds.count();
279 LOG(TRACE) <<
"Core: Terminate all stalled DescriptorEventReceivers";
283 LOG(TRACE) <<
"Core: Close all libraries opened during runtime";
287 LOG(TRACE) <<
"Core:: Clean up the filesystem";
289 utils::Config::terminate();
291 LOG(TRACE) <<
"Core:: All resources released";
293 LOG(TRACE) <<
"SNode.C: Ended ... BYE";
297 LOG(TRACE) <<
"Core: Received signal '" << strsignal(sig) <<
"' (SIG" << utils
::system::sigabbrev_np(sig
) <<
" = " << sig <<
")";
static void execDlCloseAll()
static unsigned long tickCounter
EventMultiplexer & getEventMultiplexer()
static core::State getEventLoopState()
TickStatus _tick(const utils::Timeval &timeOut)
static EventLoop & instance()
core::EventMultiplexer & eventMultiplexer
static core::State eventLoopState
static void stoponsig(int sig)
static int start(const utils::Timeval &timeOut)
static TickStatus tick(const utils::Timeval &timeOut)
static bool init(int argc, char *argv[])
static unsigned long getTickCounter()
TickStatus tick(const utils::Timeval &tickTimeOut, const sigset_t &sigMask)
bool operator>(const Timeval &timeVal) const
Timeval & operator-=(const Timeval &timeVal)
static std::string getTickCounterAsString(const el::LogMessage *logMessage)
std::string sigabbrev_np(int sig)