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