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