ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Spectre2/Spectre2.cpp
(Generate patch)

Comparing Spectre2/Spectre2.cpp (file contents):
Revision 418 by douglas, 2005-03-02T22:36:24-08:00 vs.
Revision 429 by douglas, 2005-03-25T18:47:25-08:00

# Line 6 | Line 6
6  
7   #include "Mounter.hpp"
8   #include "Unmounter.hpp"
9 #include "Matcher/Matcher.hpp"
9  
10   #include <menes-api/exename.hpp>
11   #include <menes-app/simple.hpp>
# Line 17 | Line 16
16   int Main(const app::Options& options)
17   {
18          api::Path config(Spectre2::prefix + "/etc/spectre.xml");
19 <        bool fork(false);
19 >        enum Mode { none, pid = 1, fork } mode(none);
20  
21          _foreach (const app::ArgumentList, arg, app::GetArguments())
22          {
# Line 25 | Line 24 | int Main(const app::Options& options)
24  
25                  if (*arg == matcher("^-config=(.*)$"))
26                          config = matcher[1];
27 +                else if (*arg == "-pid")
28 +                        mode = pid;
29                  else if (*arg == "-fork")
30 <                        fork = true;
30 >                        mode = fork;
31                  else if (*arg == "-D")
32                          Spectre2::debug = true;
33                  else
34                  {
35 <                        api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-D]" << ios::NewLine;
35 >                        api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-pid|-fork] [-D]" << ios::NewLine;
36  
37                          return 1;
38                  }
# Line 44 | Line 45 | int Main(const app::Options& options)
45                  return 2;
46          }
47  
48 <        if (fork && api::Posix::CheckError(::fork()))
49 <                return 0;
48 >        switch (mode)
49 >        {
50 >        case pid:
51 >                try
52 >                {
53 >                        _H<xml::Document> document(xml::Parse(config.GetPath()));
54 >                        api::FileReader in(*document/"spectre"/"pid");
55  
56 <        Spectre2 spectre(config);
56 >                        ios::ReadToWrite(in, api::Cout);
57 >                }
58 >                catch (const api::Error&)
59 >                {
60 >                        return 1;
61 >                }
62 >                break;
63 >        case fork:
64 >                if (api::Posix::CheckError(::fork()))
65 >                        return 0;
66 >        default:
67 >                {
68 >                        Spectre2 spectre(config);
69 >                }
70 >        }
71  
72          return 0;
73   }
# Line 62 | Line 82 | Spectre2::Spectre2(const api::Path& conf
82   {
83          {
84                  _H<xml::Document> document(xml::Parse(config.GetPath()));
85 +                _H<xml::Node> spectre(*document/"spectre");
86  
87 <                pid = *document/"spectre"/"pid";
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";
97          }
98  
99          {
# Line 73 | Line 103 | Spectre2::Spectre2(const api::Path& conf
103                  fout << ::getpid() << ios::NewLine;
104          }
105  
106 <        Mounter mounter(config);
77 <        Unmounter unmounter(config);
106 >        Daemon daemon_(config);
107  
108 <        daemons.InsertLast(dynamic_cast<Daemon*>(&mounter));
80 <        daemons.InsertLast(dynamic_cast<Daemon*>(&unmounter));
108 >        daemon = &daemon_;
109  
110          {
111                  struct ::sigaction action;
# Line 90 | Line 118 | Spectre2::Spectre2(const api::Path& conf
118  
119                  action.sa_sigaction = stop;
120  
121 +                api::Posix::CheckError(::sigaction(SIGINT, &action, NULL));
122                  api::Posix::CheckError(::sigaction(SIGTERM, &action, NULL));
123          }
95
96        _foreach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->start();
97        _foreach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->wait();
124   }
125  
126   Spectre2::~Spectre2()
# Line 102 | Line 128 | Spectre2::~Spectre2()
128          api::Posix::CheckError(::unlink(pid.NullTerminate()));
129   }
130  
131 < ext::String Spectre2::program(api::GetExecutablePath().GetName()), Spectre2::prefix(_Spectre2_prefix_), Spectre2::root(_Spectre2_root_);
131 > ext::String Spectre2::program(api::GetExecutablePath().GetName()), Spectre2::prefix(_Spectre2_prefix_), Spectre2::root(_Spectre2_root_), Spectre2::mount(_Spectre2_mount_);
132   bool Spectre2::debug(false);
133 < ext::Vector<Daemon*> Spectre2::daemons;
133 > Daemon* Spectre2::daemon;
134  
135   extern "C"
136   {
137          void reload(int signal, ::siginfo_t* info, void* uap)
138          {
139 <                _foreach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->reload();
139 >                Spectre2::daemon->reload();
140          }
141  
142          void stop(int signal, ::siginfo_t* info, void* uap)
143          {
144 <                _foreach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->stop();
144 >                Spectre2::daemon->stop();
145          }
146   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines