let split_conf_line s =
sscanf s "%s %s" (fun s1 s2->(s1,s2))
+let check_dir fe =
+ let (vsysdir,slice) = fe in
+ let verdict = try Some(Unix.stat vsysdir) with
+ _ -> fprintf logfd "vsys directory not setup for slice %s\n" slice;flush logfd;None
+ in
+ match verdict with
+ | None->false
+ | Some(_) -> true
+
let rec in_list elt lst =
match lst with
| car::cdr ->
| [] -> false
let read_frontends f =
+ let setup_ok = if (!Globals.failsafe) then check_dir else fun _ -> true in
let f_file = try open_in f with e -> fprintf logfd "Could not open config file\n";flush logfd;raise e
in
let rec read_conf_file cur_list =
match next_line with
| Some(inp_line) ->
let fe = split_conf_line inp_line in
- let new_list = if (not (in_list fe cur_list)) then (fe::cur_list) else cur_list
+ let new_list = if (not (in_list fe cur_list) && (setup_ok(fe))) then (fe::cur_list) else cur_list
in
read_conf_file new_list
| None -> cur_list
let conffile = ref ""
let pid_filepath = ref "/var/run/vsys.pid"
let log_filepath = ref "/var/log/vsys"
+let failsafe = ref false
let logfd = open_out_gen [Open_append;Open_creat] 0o644 !log_filepath
type result = Success | Failed
("-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");
- ("-nochroot",Arg.Set(Globals.nochroot), "Run in non-chroot environment")
+ ("-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 cont = ref true