7 |
|
#include "Mounter.hpp" |
8 |
|
|
9 |
|
#include <menes-api/environment.hpp> |
10 |
+ |
#include <menes-api/socket.hpp> |
11 |
+ |
|
12 |
+ |
#include <arpa/inet.h> |
13 |
|
|
14 |
|
Mounter::Mounter(const api::Path& config) : Daemon(), config(config) {} |
15 |
|
|
26 |
|
|
27 |
|
void Mounter::load() |
28 |
|
{ |
29 |
< |
if (Spectre2::debug) api::Cerr << "Mounter::load()" << ios::NewLine; |
29 |
> |
_synchronized (Spectre2::sharesLock) |
30 |
> |
Spectre2::shares.Clear(); |
31 |
> |
|
32 |
> |
_synchronized (Share::passwordsLock) |
33 |
> |
Share::passwords.Clear(); |
34 |
|
|
35 |
+ |
_H<xml::Document> document(xml::Parse(config.GetPath())); |
36 |
+ |
_H<xml::Node> spectre(*document/"spectre"); |
37 |
|
#ifdef __FreeBSD__ |
38 |
+ |
SecretFileWriter out(secret); |
39 |
+ |
ios::FormatWriter fout(out); |
40 |
+ |
#endif |
41 |
+ |
|
42 |
+ |
_foreach (const xml::NodeSet, host_, *spectre/"host") |
43 |
|
{ |
44 |
< |
SecretFileWriter file(secret); |
44 |
> |
ext::String host(**host_/"name"); |
45 |
|
|
46 |
< |
// |
47 |
< |
} |
46 |
> |
_foreach (const xml::NodeSet, share, **host_/"share") |
47 |
> |
{ |
48 |
> |
ext::String name(**share/"name"), owner(**share/"owner"), user(**share/"user"), group(**share/"group"); |
49 |
> |
|
50 |
> |
_synchronized (Spectre2::sharesLock) |
51 |
> |
Spectre2::shares.Insert(Share(host, name, owner, user, group)); |
52 |
> |
} |
53 |
> |
|
54 |
> |
#ifdef __FreeBSD__ |
55 |
> |
::addrinfo* info; |
56 |
> |
|
57 |
> |
api::Posix::CheckGaiError(::getaddrinfo(host.NullTerminate(), NULL, NULL, &info)); |
58 |
> |
|
59 |
> |
::sockaddr_in& sock(*reinterpret_cast< ::sockaddr_in*>(info->ai_addr)); |
60 |
> |
ext::Buffer buffer(128); |
61 |
> |
|
62 |
> |
fout << "[" << host << "]" << ios::NewLine << "addr=" << ::inet_ntop(sock.sin_family, &sock.sin_addr, buffer.Begin(), buffer.GetSize()) << ios::NewLine; |
63 |
> |
|
64 |
> |
::freeaddrinfo(info); |
65 |
|
#endif |
66 |
+ |
} |
67 |
+ |
|
68 |
+ |
_synchronized (Spectre2::sharesLock) |
69 |
+ |
Spectre2::shares.Output(api::Cout); |
70 |
|
|
71 |
|
loaded = true; |
72 |
|
} |
73 |
|
|
74 |
|
void Mounter::run() |
75 |
|
{ |
76 |
< |
if (Spectre2::debug) api::Cerr << "Mounter::run()" << ios::NewLine; |
76 |
> |
ext::ThreadSet<> workers; |
77 |
> |
|
78 |
> |
_synchronized (Spectre2::sharesLock) _foreach (const ext::RedBlackSet<Share>, share, Spectre2::shares) if (!share->mounted() && share->mountable()) |
79 |
> |
{ |
80 |
> |
api::Cerr << "STUB: mount " << *share << ios::NewLine; |
81 |
> |
} |
82 |
> |
|
83 |
> |
workers.Join(); |
84 |
|
|
85 |
|
::sleep(5); |
86 |
|
} |