16 |
|
|
17 |
|
int Main(const app::Options& options) |
18 |
|
{ |
19 |
< |
ext::String config("spectre.xml"), pid("spectre.pid"); |
19 |
> |
api::Path config(Spectre2::prefix + "/etc/spectre.xml"); |
20 |
|
bool fork(false); |
21 |
|
|
22 |
|
_foreach (const app::ArgumentList, arg, app::GetArguments()) |
27 |
|
config = matcher[1]; |
28 |
|
else if (*arg == "-fork") |
29 |
|
fork = true; |
30 |
– |
else if (*arg == matcher("^-pid=(.*)$")) |
31 |
– |
pid = matcher[1]; |
30 |
|
else if (*arg == "-D") |
31 |
|
Spectre2::debug = true; |
32 |
|
else |
33 |
|
{ |
34 |
< |
api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-pid=pid] [-D]" << ios::NewLine; |
34 |
> |
api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-D]" << ios::NewLine; |
35 |
|
|
36 |
|
return 1; |
37 |
|
} |
38 |
|
} |
39 |
|
|
40 |
+ |
if (!config.Exists()) |
41 |
+ |
{ |
42 |
+ |
api::Cerr << Spectre2::program << ": configuration file " << config.GetPath() << " does not exist." << ios::NewLine; |
43 |
+ |
|
44 |
+ |
return 2; |
45 |
+ |
} |
46 |
+ |
|
47 |
|
if (fork && api::Posix::CheckError(::fork())) |
48 |
|
return 0; |
49 |
|
|
50 |
< |
api::Cerr << "Here!" << ios::NewLine; |
46 |
< |
|
47 |
< |
Spectre2(config, pid); |
50 |
> |
Spectre2 spectre(config); |
51 |
|
|
52 |
|
return 0; |
53 |
|
} |
58 |
|
void stop(int signal, ::siginfo_t* info, void* uap); |
59 |
|
} |
60 |
|
|
61 |
< |
Spectre2::Spectre2(const ext::String& config, const ext::String& pid) : pid(pid) |
61 |
> |
Spectre2::Spectre2(const api::Path& config) |
62 |
|
{ |
63 |
|
{ |
64 |
+ |
_H<xml::Document> document(xml::Parse(config.GetPath())); |
65 |
+ |
|
66 |
+ |
pid = *document/"spectre"/"pid"; |
67 |
+ |
} |
68 |
+ |
|
69 |
+ |
{ |
70 |
|
api::FileWriter out(pid); |
71 |
|
ios::FormatWriter fout(out); |
72 |
|
|