9 |
|
#include "Matcher/Matcher.hpp" |
10 |
|
|
11 |
|
#include <menes-api/exename.hpp> |
12 |
< |
#include <menes-app/application.hpp> |
12 |
> |
#include <menes-app/simple.hpp> |
13 |
|
|
14 |
|
#include <sys/types.h> |
15 |
|
#include <signal.h> |
16 |
|
|
17 |
< |
struct Spectre2Command : public app::Application |
17 |
> |
int Main(const app::Options& options) |
18 |
|
{ |
19 |
< |
virtual int Run(const app::ArgumentList& args) |
19 |
> |
ext::String config("spectre.xml"), pid("spectre.pid"); |
20 |
> |
bool fork(false); |
21 |
> |
|
22 |
> |
_foreach (const app::ArgumentList, arg, app::GetArguments()) |
23 |
|
{ |
24 |
< |
ext::String config("spectre.xml"), pid("spectre.pid"); |
24 |
> |
Matcher matcher; |
25 |
|
|
26 |
< |
_foreach (app::ArgumentList, arg, args) |
26 |
> |
if (*arg == matcher("^-config=(.*)$")) |
27 |
> |
config = matcher[1]; |
28 |
> |
else if (*arg == "-fork") |
29 |
> |
fork = true; |
30 |
> |
else if (*arg == matcher("^-pid=(.*)$")) |
31 |
> |
pid = matcher[1]; |
32 |
> |
else if (*arg == "-D") |
33 |
> |
Spectre2::debug = true; |
34 |
> |
else |
35 |
|
{ |
36 |
< |
Matcher matcher; |
26 |
< |
|
27 |
< |
if (*arg == matcher("^-config=(.*)$")) config = matcher[1]; |
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] [-pid=pid] [-D]" << ios::NewLine; |
36 |
> |
api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-pid=pid] [-D]" << ios::NewLine; |
37 |
|
|
38 |
< |
return 1; |
35 |
< |
} |
38 |
> |
return 1; |
39 |
|
} |
40 |
+ |
} |
41 |
|
|
42 |
< |
Spectre2(config, pid); |
39 |
< |
|
42 |
> |
if (fork && api::Posix::CheckError(::fork())) |
43 |
|
return 0; |
44 |
< |
} |
45 |
< |
} spectre; |
44 |
> |
|
45 |
> |
api::Cerr << "Here!" << ios::NewLine; |
46 |
> |
|
47 |
> |
Spectre2(config, pid); |
48 |
> |
|
49 |
> |
return 0; |
50 |
> |
} |
51 |
|
|
52 |
|
extern "C" |
53 |
|
{ |
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(); |
87 |
> |
_foreach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->start(); |
88 |
> |
_foreach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->wait(); |
89 |
|
} |
90 |
|
|
91 |
|
Spectre2::~Spectre2() |
101 |
|
{ |
102 |
|
void reload(int signal, ::siginfo_t* info, void* uap) |
103 |
|
{ |
104 |
< |
_mforeach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->reload(); |
104 |
> |
_foreach (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(); |
109 |
> |
_foreach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->stop(); |
110 |
|
} |
111 |
|
} |