4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
– |
#include "SignalHandler.hpp" |
7 |
|
#include "Mounter.hpp" |
8 |
|
#include "Unmounter.hpp" |
9 |
|
#include "Matcher/Matcher.hpp" |
10 |
|
|
11 |
|
#include <menes-api/exename.hpp> |
13 |
– |
#include <menes-api/files.hpp> |
12 |
|
#include <menes-app/application.hpp> |
13 |
|
|
16 |
– |
extern "C" |
17 |
– |
{ |
14 |
|
#include <sys/types.h> |
15 |
< |
#include <unistd.h> |
20 |
< |
} |
15 |
> |
#include <signal.h> |
16 |
|
|
17 |
|
struct Spectre2Command : public app::Application |
18 |
|
{ |
45 |
|
} |
46 |
|
} spectre; |
47 |
|
|
48 |
+ |
extern "C" |
49 |
+ |
{ |
50 |
+ |
void reload(int signal, ::siginfo_t* info, void* uap); |
51 |
+ |
void stop(int signal, ::siginfo_t* info, void* uap); |
52 |
+ |
} |
53 |
+ |
|
54 |
|
Spectre2::Spectre2(const ext::String& config, const ext::String& pid) : pid(pid) |
55 |
|
{ |
56 |
|
{ |
62 |
|
|
63 |
|
Mounter mounter(config); |
64 |
|
Unmounter unmounter(config); |
65 |
< |
Daemon* daemons[] = { static_cast<Daemon*>(&mounter), static_cast<Daemon*>(&unmounter) }; |
66 |
< |
SignalHandler handler(daemons, sizeof (daemons) / sizeof (*daemons)); |
65 |
> |
|
66 |
> |
daemons.InsertLast(dynamic_cast<Daemon*>(&mounter)); |
67 |
> |
daemons.InsertLast(dynamic_cast<Daemon*>(&unmounter)); |
68 |
> |
|
69 |
> |
{ |
70 |
> |
struct ::sigaction action; |
71 |
> |
|
72 |
> |
action.sa_sigaction = reload; |
73 |
> |
action.sa_flags = SA_SIGINFO; |
74 |
> |
|
75 |
> |
api::Posix::CheckError(::sigemptyset(&action.sa_mask)); |
76 |
> |
api::Posix::CheckError(::sigaction(SIGHUP, &action, NULL)); |
77 |
> |
|
78 |
> |
action.sa_sigaction = stop; |
79 |
> |
|
80 |
> |
api::Posix::CheckError(::sigaction(SIGTERM, &action, NULL)); |
81 |
> |
} |
82 |
> |
|
83 |
> |
_mforeach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->start(); |
84 |
> |
_mforeach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->wait(); |
85 |
|
} |
86 |
|
|
87 |
|
Spectre2::~Spectre2() |
91 |
|
|
92 |
|
ext::String Spectre2::program(api::GetExecutablePath().GetName()); |
93 |
|
bool Spectre2::debug(false); |
94 |
+ |
ext::Vector<Daemon*> Spectre2::daemons; |
95 |
+ |
|
96 |
+ |
extern "C" |
97 |
+ |
{ |
98 |
+ |
void reload(int signal, ::siginfo_t* info, void* uap) |
99 |
+ |
{ |
100 |
+ |
_mforeach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->reload(); |
101 |
+ |
} |
102 |
+ |
|
103 |
+ |
void stop(int signal, ::siginfo_t* info, void* uap) |
104 |
+ |
{ |
105 |
+ |
_mforeach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->stop(); |
106 |
+ |
} |
107 |
+ |
} |