30 |
|
mode = fork; |
31 |
|
else if (*arg == "-D") |
32 |
|
Spectre2::debug = true; |
33 |
< |
else |
33 |
> |
else if (*arg != matcher("^--.*$")) |
34 |
|
{ |
35 |
|
api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-pid|-fork] [-D]" << ios::NewLine; |
36 |
|
|
85 |
|
_H<xml::Node> spectre(*document/"spectre"); |
86 |
|
|
87 |
|
pid = *spectre/"pid"; |
88 |
– |
|
89 |
– |
if (!(*spectre/"prefix").IsEmpty()) |
90 |
– |
prefix = *spectre/"prefix"; |
91 |
– |
|
92 |
– |
if (!(*spectre/"root").IsEmpty()) |
93 |
– |
root = *spectre/"root"; |
94 |
– |
|
95 |
– |
if (!(*spectre/"mount").IsEmpty()) |
96 |
– |
mount = *spectre/"mount"; |
88 |
|
} |
89 |
|
|
90 |
|
{ |
94 |
|
fout << ::getpid() << ios::NewLine; |
95 |
|
} |
96 |
|
|
97 |
< |
Mounter mounter(config); |
107 |
< |
Unmounter unmounter(config); |
97 |
> |
Daemon daemon_(config); |
98 |
|
|
99 |
< |
daemons.InsertLast(dynamic_cast<Daemon*>(&mounter)); |
110 |
< |
daemons.InsertLast(dynamic_cast<Daemon*>(&unmounter)); |
99 |
> |
daemon = &daemon_; |
100 |
|
|
101 |
|
{ |
102 |
|
struct ::sigaction action; |
112 |
|
api::Posix::CheckError(::sigaction(SIGINT, &action, NULL)); |
113 |
|
api::Posix::CheckError(::sigaction(SIGTERM, &action, NULL)); |
114 |
|
} |
126 |
– |
|
127 |
– |
_foreach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->start(); |
128 |
– |
_foreach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->wait(); |
115 |
|
} |
116 |
|
|
117 |
|
Spectre2::~Spectre2() |
119 |
|
api::Posix::CheckError(::unlink(pid.NullTerminate())); |
120 |
|
} |
121 |
|
|
122 |
< |
ext::String Spectre2::program(api::GetExecutablePath().GetName()), Spectre2::prefix(_Spectre2_prefix_), Spectre2::root(_Spectre2_root_), Spectre2::mount(_Spectre2_mount_); |
122 |
> |
ext::String Spectre2::program(api::GetExecutablePath().GetName()), Spectre2::prefix(_Spectre2_prefix_), Spectre2::root(_Spectre2_root_), Spectre2::mount(_Spectre2_mount_), Spectre2::umount(_Spectre2_umount_); |
123 |
|
bool Spectre2::debug(false); |
124 |
< |
ext::Vector<Daemon*> Spectre2::daemons; |
139 |
< |
ext::RedBlackSet<Share> Spectre2::shares; |
140 |
< |
api::ThreadMutex Spectre2::sharesLock; |
124 |
> |
Daemon* Spectre2::daemon; |
125 |
|
|
126 |
|
extern "C" |
127 |
|
{ |
128 |
|
void reload(int signal, ::siginfo_t* info, void* uap) |
129 |
|
{ |
130 |
< |
_foreach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->reload(); |
130 |
> |
if (Spectre2::debug) |
131 |
> |
api::Cout << "Reload" << ios::NewLine; |
132 |
> |
|
133 |
> |
Spectre2::daemon->reload(); |
134 |
|
} |
135 |
|
|
136 |
|
void stop(int signal, ::siginfo_t* info, void* uap) |
137 |
|
{ |
138 |
< |
_foreach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->stop(); |
138 |
> |
if (Spectre2::debug) |
139 |
> |
api::Cout << "Stop" << ios::NewLine; |
140 |
> |
|
141 |
> |
Spectre2::daemon->stop(); |
142 |
|
} |
143 |
|
} |