ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Spectre2/Spectre2.cpp
Revision: 402
Committed: 2004-12-29T22:38:37-08:00 (20 years, 5 months ago) by douglas
File size: 1630 byte(s)
Log Message:
It bogles the mind!

File Contents

# User Rev Content
1 douglas 402 // Spectre 2
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "SignalHandler.hpp"
8     #include "Mounter.hpp"
9     #include "Unmounter.hpp"
10     #include "Matcher/Matcher.hpp"
11    
12     #include <menes-api/exename.hpp>
13     #include <menes-api/files.hpp>
14     #include <menes-app/application.hpp>
15    
16     extern "C"
17     {
18     #include <sys/types.h>
19     #include <unistd.h>
20     }
21    
22     struct Spectre2Command : public app::Application
23     {
24     virtual int Run(const app::ArgumentList& args)
25     {
26     ext::String config("spectre.xml"), pid("spectre.pid");
27     bool fork(false);
28    
29     _foreach (app::ArgumentList, arg, args)
30     {
31     Matcher matcher;
32    
33     if (*arg == matcher("^-config=(.*)$")) config = matcher[1];
34     else if (*arg == "-fork") fork = true;
35     else if (*arg == matcher("^-pid=(.*)$")) pid = matcher[1];
36     else if (*arg == "-D") Spectre2::debug = true;
37     else
38     {
39     api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-pid=pid] [-D]" << ios::NewLine;
40    
41     return 1;
42     }
43     }
44    
45     if (fork && api::Posix::CheckError(::fork())) return 0;
46    
47     Spectre2(config, pid);
48    
49     return 0;
50     }
51     } spectre;
52    
53     Spectre2::Spectre2(const ext::String& config, const ext::String& pid) : pid(pid)
54     {
55     {
56     api::FileWriter out(pid);
57     ios::FormatWriter fout(out);
58    
59     fout << ::getpid() << ios::NewLine;
60     }
61    
62     Mounter mounter(config);
63     Unmounter unmounter(config);
64     Daemon* daemons[] = { static_cast<Daemon*>(&mounter), static_cast<Daemon*>(&unmounter) };
65     SignalHandler handler(daemons, sizeof (daemons) / sizeof (*daemons));
66     }
67    
68     Spectre2::~Spectre2()
69     {
70     api::Posix::CheckError(::unlink(pid.NullTerminate()));
71     }
72    
73     ext::String Spectre2::program(api::GetExecutablePath().GetName());
74     bool Spectre2::debug(false);

Properties

Name Value
svn:eol-style native
svn:keywords Id