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

Comparing Spectre2/Daemon.cpp (file contents):
Revision 429 by douglas, 2005-03-25T18:47:25-08:00 vs.
Revision 439 by douglas, 2005-04-07T15:56:53-07:00

# Line 13 | Line 13
13  
14   #include <arpa/inet.h>
15  
16 + extern "C"
17 + {
18 +        void authenticate(const char* server, const char* share, char* work, int workSize, char* user, int userSize, char* password, int passwordSize);
19 + }
20 +
21   Daemon::~Daemon()
22   {
23          thread->Join();
24  
25 +        ::smbc_free_context(::smbc_set_context(NULL), 1);
26 +
27   #ifdef __FreeBSD__
28          api::Posix::CheckError(::unlink(secret.NullTerminate()));
29 + #else
30 +        _foreach (const ext::RedBlackMap<ext::String>, secret, secrets)
31 +                api::Posix::CheckError(::unlink(secret.NullTerminate()));
32   #endif
33   }
34  
35 + ext::RedBlackSet<Share> Daemon::shares;
36 + //api::ThreadMutex Daemon::smbcLock;
37   #ifdef __FreeBSD__
38   ext::String Daemon::secret(api::TheEnvironment.Get("HOME") + "/.nsmbrc");
39 + api::ThreadMutex Daemon::secretLock;
40 + #else
41 + ext::RedBlackMap<ext::String> Daemon::secrets;
42 + api::ThreadMutex Daemon::secretsLock;
43   #endif
44  
45   int Daemon::loop()
# Line 48 | Line 64 | void Daemon::load()
64  
65          _H<xml::Document> document(xml::Parse(config.GetPath()));
66          _H<xml::Node> spectre(*document/"spectre");
67 +                
68 +        if (!(*spectre/"prefix").IsEmpty())
69 +                Spectre2::prefix = *spectre/"prefix";
70 +
71 +        if (!(*spectre/"root").IsEmpty())
72 +                Spectre2::root = *spectre/"root";
73 +
74 +        if (!(*spectre/"mount").IsEmpty())
75 +                Spectre2::mount = *spectre/"mount";
76 +
77 +        if (!(*spectre/"umount").IsEmpty())
78 +                Spectre2::umount = *spectre/"umount";
79 +
80 +        if (!(*spectre/"interval").IsEmpty())
81 +                interval = lexical_cast<unsigned>(ext::String(*spectre/"interval"));
82 +
83 +        CheckError(::smbc_init(authenticate, Spectre2::debug ? 2 : 0));
84 +
85   #ifdef __FreeBSD__
86 <        SecretFileWriter out(secret);
86 >        api::FileWriter out(secret, O_WRONLY | O_CREAT | O_TRUNC, 0600);
87          ios::FormatWriter fout(out);
88   #endif
89  
# Line 78 | Line 112 | void Daemon::load()
112   #endif
113          }
114  
115 <        shares.Output(api::Cout);
115 >        if (Spectre2::debug)
116 >                shares.Output(api::Cout);
117          
118          loaded = true;
119   }
# Line 90 | Line 125 | int Daemon::work()
125          {
126                  ext::ThreadSet<> workers;
127  
128 <                _foreach (const ext::RedBlackSet<Share>, share, shares) if (Worker::workable(*share))
129 <                        workers.Add(etl::BindAll(&Worker::work, *share));
128 >                _foreach (const ext::RedBlackSet<Share>, share, shares)
129 >                        workers.Add(etl::BindAll(&Daemon::work_<Worker>, this, *share));
130 >
131 >                // XXX: not useful for solving the problem it was supposed to solve
132 >                /*_synchronized (smbcLock) if (++count % 8 == 0) try
133 >                {
134 >                        ::SMBCCTX* context(::smbc_new_context());
135 >
136 >                        context->debug = Spectre2::debug ? 2 : 0;
137 >                        context->callbacks.auth_fn = authenticate;
138 >
139 >                        CheckError(::smbc_init_context(context));
140 >
141 >                        ::SMBCCTX* old(::smbc_set_context(context));
142 >
143 >                        CheckError(::smbc_free_context(old, 0));
144 >                }
145 >                catch (const Error&) { --count; }*/
146 >
147 >                if (running && loaded)
148 >                        sleep();
149  
150                  workers.Join();
151          }
152  
153          return 0;
154   }
155 +
156 + template <typename Worker>
157 + int Daemon::work_(const Share& share)
158 + {
159 +        Worker worker(share);
160 +
161 +        if (worker)
162 +                worker();
163 +
164 +        return 0;
165 + }
166 +
167 + void Daemon::sleep()
168 + {
169 +        ::timespec wait = { interval, 0 };
170 +
171 +        ::nanosleep(&wait, NULL);
172 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines