-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ml
More file actions
71 lines (63 loc) · 2.29 KB
/
Copy pathmain.ml
File metadata and controls
71 lines (63 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(** main () *)
open Globals
open Printf
open Inotify
open Backend
open Frontend
open Conffile
let input_file_list = ref []
let cur_dir = ref ""
let cur_slice = ref ""
let daemonize = ref false
let cmdspeclist =
[
("-daemon",Arg.Set(daemonize), "Daemonize");
("-conffile",Arg.Set_string(Globals.conffile), "Config file");
("-logfile",Arg.Set_string(Globals.log_filepath), "Log file");
("-backend",Arg.Set_string(Globals.backend), "Backend directory");
("-frontend",Arg.Tuple[Arg.String(fun s->cur_dir:=s);
Arg.String(fun s->cur_slice:=s;
input_file_list:=(!cur_dir,!cur_slice)::!input_file_list)],
"frontendN,slicenameN");
("-nochroot",Arg.Set(Globals.nochroot), "Run in non-chroot environment");
("-failsafe",Arg.Set(Globals.failsafe), "Never crash. Be stupid, but never crash. Use at your own risk.");
]
let sighup_handle s =
print "Received sighup. Running GC major pass";
Gc.major ()
let _ =
Arg.parse cmdspeclist (fun x->()) "Usage: vsys <list of mount points>";
Globals.logfd:=open_out_gen [Open_append;Open_creat] 0o644 !log_filepath;
if (!Globals.backend == "") then
printf "Try vsys --help\n"
else
begin
logprint "Starting Vsys v%s\n" Globals.vsys_version;
if (!daemonize) then
begin
print "Daemonizing\n";
let child = Unix.fork () in
if (child <> 0) then
begin
let pidfile = open_out !Globals.pid_filepath in
fprintf pidfile "%d" child;
close_out pidfile;
exit(0)
end
end;
Dirwatcher.initialize ();
Directfifowatcher.initialize ();
if (!Globals.conffile <> "") then
begin
let frontends = Conffile.read_frontends !Globals.conffile in
input_file_list:=List.concat [!input_file_list;frontends]
end;
Sys.set_signal Sys.sigusr1 (Sys.Signal_handle sighup_handle);
let felst = List.map
(fun lst->let (x,y)=lst in
logprint "Slice %s (%s)\n" x y;
new frontendHandler lst)
!input_file_list in
let _ = new backendHandler !Globals.backend felst in
Fdwatcher.start_watch ()
end