X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=main.ml;h=5ec2952cedcf273b04edec4dee1a8760c709571a;hb=87c0dc3957634fe643267904d0cedfed80a03f68;hp=391074d3ea6ca58a2e383199c2b52e756849c9f4;hpb=8e8e13b87b5d592621be0a15a19b5ea0a1fad0b5;p=vsys.git diff --git a/main.ml b/main.ml index 391074d..5ec2952 100644 --- a/main.ml +++ b/main.ml @@ -10,9 +10,11 @@ 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"); ("-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"); @@ -28,13 +30,28 @@ let _ = printf "Try vsys --help\n" else begin - Dirwatcher.initialize (); - Fifowatcher.initialize (); - if (!Globals.conffile != "") then - let frontends = Conffile.read_frontends !Globals.conffile in - input_file_list:=List.concat [!input_file_list;frontends]; + if (!daemonize) then + begin + printf "Daemonizing\n";flush Pervasives.stdout; + 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; - let felst = List.map (fun lst->let (x,y)=lst in printf "Slice %s (%s)\n" x y;flush Pervasives.stdout;new frontendHandler lst) !input_file_list in - let _ = new backendHandler !Globals.backend felst in - Fdwatcher.start_watch () + Dirwatcher.initialize (); + Fifowatcher.initialize (); + if (!Globals.conffile <> "") then + begin + let frontends = Conffile.read_frontends !Globals.conffile in + input_file_list:=List.concat [!input_file_list;frontends] + end; + + let felst = List.map (fun lst->let (x,y)=lst in printf "Slice %s (%s)\n" x y;flush logfd;new frontendHandler lst) !input_file_list in + let _ = new backendHandler !Globals.backend felst in + Fdwatcher.start_watch () end