9 |
|
#include "Matcher/Matcher.hpp" |
10 |
|
|
11 |
|
#include <menes-api/exename.hpp> |
12 |
– |
#include <menes-api/files.hpp> |
12 |
|
#include <menes-app/application.hpp> |
13 |
|
|
15 |
– |
extern "C" |
16 |
– |
{ |
14 |
|
#include <sys/types.h> |
18 |
– |
#include <unistd.h> |
15 |
|
#include <signal.h> |
20 |
– |
} |
16 |
|
|
17 |
|
struct Spectre2Command : public app::Application |
18 |
|
{ |
19 |
|
virtual int Run(const app::ArgumentList& args) |
20 |
|
{ |
21 |
|
ext::String config("spectre.xml"), pid("spectre.pid"); |
27 |
– |
bool fork(false); |
22 |
|
|
23 |
|
_foreach (app::ArgumentList, arg, args) |
24 |
|
{ |
25 |
|
Matcher matcher; |
26 |
|
|
27 |
|
if (*arg == matcher("^-config=(.*)$")) config = matcher[1]; |
34 |
– |
else if (*arg == "-fork") fork = true; |
28 |
|
else if (*arg == matcher("^-pid=(.*)$")) pid = matcher[1]; |
29 |
|
else if (*arg == "-D") Spectre2::debug = true; |
30 |
|
else |
31 |
|
{ |
32 |
< |
api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-pid=pid] [-D]" << ios::NewLine; |
32 |
> |
api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-pid=pid] [-D]" << ios::NewLine; |
33 |
|
|
34 |
|
return 1; |
35 |
|
} |
36 |
|
} |
37 |
|
|
45 |
– |
if (fork && api::Posix::CheckError(::fork())) return 0; |
46 |
– |
|
38 |
|
Spectre2(config, pid); |
39 |
|
|
40 |
|
return 0; |
69 |
|
action.sa_flags = SA_SIGINFO; |
70 |
|
|
71 |
|
api::Posix::CheckError(::sigemptyset(&action.sa_mask)); |
72 |
< |
api::Posix::CheckError(::sigaction(SIGHUP, &action, NULL)); |
72 |
> |
api::Posix::CheckError(::sigaction(SIGUSR1, &action, NULL)); |
73 |
|
|
74 |
|
action.sa_sigaction = stop; |
75 |
|
|
77 |
|
} |
78 |
|
|
79 |
|
_mforeach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->start(); |
80 |
+ |
_mforeach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->wait(); |
81 |
|
} |
82 |
|
|
83 |
|
Spectre2::~Spectre2() |
85 |
|
api::Posix::CheckError(::unlink(pid.NullTerminate())); |
86 |
|
} |
87 |
|
|
88 |
< |
ext::String Spectre2::program(api::GetExecutablePath().GetName()); |
88 |
> |
ext::String Spectre2::program(api::GetExecutablePath().GetName()), Spectre2::prefix(_Spectre2_prefix_), Spectre2::root(_Spectre2_root_); |
89 |
|
bool Spectre2::debug(false); |
90 |
|
ext::Vector<Daemon*> Spectre2::daemons; |
91 |
|
|