// Spectre 2 // // Douglas Thrift // // $Id$ #include "SignalHandler.hpp" #include "Mounter.hpp" #include "Unmounter.hpp" #include "Matcher/Matcher.hpp" #include #include #include extern "C" { #include #include } struct Spectre2Command : public app::Application { virtual int Run(const app::ArgumentList& args) { ext::String config("spectre.xml"), pid("spectre.pid"); bool fork(false); _foreach (app::ArgumentList, arg, args) { Matcher matcher; if (*arg == matcher("^-config=(.*)$")) config = matcher[1]; else if (*arg == "-fork") fork = true; else if (*arg == matcher("^-pid=(.*)$")) pid = matcher[1]; else if (*arg == "-D") Spectre2::debug = true; else { api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-pid=pid] [-D]" << ios::NewLine; return 1; } } if (fork && api::Posix::CheckError(::fork())) return 0; Spectre2(config, pid); return 0; } } spectre; Spectre2::Spectre2(const ext::String& config, const ext::String& pid) : pid(pid) { { api::FileWriter out(pid); ios::FormatWriter fout(out); fout << ::getpid() << ios::NewLine; } Mounter mounter(config); Unmounter unmounter(config); Daemon* daemons[] = { static_cast(&mounter), static_cast(&unmounter) }; SignalHandler handler(daemons, sizeof (daemons) / sizeof (*daemons)); } Spectre2::~Spectre2() { api::Posix::CheckError(::unlink(pid.NullTerminate())); } ext::String Spectre2::program(api::GetExecutablePath().GetName()); bool Spectre2::debug(false);