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 402 by douglas, 2004-12-29T22:38:37-08:00 vs.
Revision 415 by douglas, 2005-01-15T18:26:13-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 #include "SignalHandler.hpp"
7   #include "Mounter.hpp"
8   #include "Unmounter.hpp"
9   #include "Matcher/Matcher.hpp"
10  
11   #include <menes-api/exename.hpp>
13 #include <menes-api/files.hpp>
12   #include <menes-app/application.hpp>
13  
16 extern "C"
17 {
14   #include <sys/types.h>
15 < #include <unistd.h>
20 < }
15 > #include <signal.h>
16  
17   struct Spectre2Command : public app::Application
18   {
19          virtual int Run(const app::ArgumentList& args)
20          {
21                  ext::String config("spectre.xml"), pid("spectre.pid");
27                bool fork(false);
22  
23                  _foreach (app::ArgumentList, arg, args)
24                  {
25                          Matcher matcher;
26  
27                          if (*arg == matcher("^-config=(.*)$")) config = matcher[1];
34                        else if (*arg == "-fork") fork = true;
28                          else if (*arg == matcher("^-pid=(.*)$")) pid = matcher[1];
29                          else if (*arg == "-D") Spectre2::debug = true;
30                          else
31                          {
32 <                                api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-fork] [-pid=pid] [-D]" << ios::NewLine;
32 >                                api::Cerr << "Usage: " << Spectre2::program << " [-config=config] [-pid=pid] [-D]" << ios::NewLine;
33  
34                                  return 1;
35                          }
36                  }
37  
45                if (fork && api::Posix::CheckError(::fork())) return 0;
46
38                  Spectre2(config, pid);
39  
40                  return 0;
41          }
42   } spectre;
43  
44 + extern "C"
45 + {
46 +        void reload(int signal, ::siginfo_t* info, void* uap);
47 +        void stop(int signal, ::siginfo_t* info, void* uap);
48 + }
49 +
50   Spectre2::Spectre2(const ext::String& config, const ext::String& pid) : pid(pid)
51   {
52          {
# Line 61 | Line 58 | Spectre2::Spectre2(const ext::String& co
58  
59          Mounter mounter(config);
60          Unmounter unmounter(config);
61 <        Daemon* daemons[] = { static_cast<Daemon*>(&mounter), static_cast<Daemon*>(&unmounter) };
62 <        SignalHandler handler(daemons, sizeof (daemons) / sizeof (*daemons));
61 >
62 >        daemons.InsertLast(dynamic_cast<Daemon*>(&mounter));
63 >        daemons.InsertLast(dynamic_cast<Daemon*>(&unmounter));
64 >
65 >        {
66 >                struct ::sigaction action;
67 >
68 >                action.sa_sigaction = reload;
69 >                action.sa_flags = SA_SIGINFO;
70 >
71 >                api::Posix::CheckError(::sigemptyset(&action.sa_mask));
72 >                api::Posix::CheckError(::sigaction(SIGUSR1, &action, NULL));
73 >
74 >                action.sa_sigaction = stop;
75 >
76 >                api::Posix::CheckError(::sigaction(SIGTERM, &action, NULL));
77 >        }
78 >
79 >        _mforeach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->start();
80 >        _mforeach (ext::Vector<Daemon*>, daemon, daemons) (*daemon)->wait();
81   }
82  
83   Spectre2::~Spectre2()
# Line 70 | Line 85 | Spectre2::~Spectre2()
85          api::Posix::CheckError(::unlink(pid.NullTerminate()));
86   }
87  
88 < ext::String Spectre2::program(api::GetExecutablePath().GetName());
88 > ext::String Spectre2::program(api::GetExecutablePath().GetName()), Spectre2::prefix(_Spectre2_prefix_), Spectre2::root(_Spectre2_root_);
89   bool Spectre2::debug(false);
90 + ext::Vector<Daemon*> Spectre2::daemons;
91 +
92 + extern "C"
93 + {
94 +        void reload(int signal, ::siginfo_t* info, void* uap)
95 +        {
96 +                _mforeach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->reload();
97 +        }
98 +
99 +        void stop(int signal, ::siginfo_t* info, void* uap)
100 +        {
101 +                _mforeach (ext::Vector<Daemon*>, daemon, Spectre2::daemons) (*daemon)->stop();
102 +        }
103 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines