vsys won't fail if the frontend is not set up.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 13 Jun 2008 20:47:38 +0000 (20:47 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 13 Jun 2008 20:47:38 +0000 (20:47 +0000)
conffile.ml
globals.ml
inotify_stubs.o
main.ml

index d9fe129..6279d16 100644 (file)
@@ -5,6 +5,15 @@ open Scanf
 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 ->
@@ -12,6 +21,7 @@ let rec in_list elt lst =
     | [] -> 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 =
@@ -19,7 +29,7 @@ let read_frontends f =
       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
index e8dca75..2dd7fe9 100644 (file)
@@ -6,6 +6,7 @@ let nochroot = ref false
 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
index 82c7c60..714490f 100644 (file)
Binary files a/inotify_stubs.o and b/inotify_stubs.o differ
diff --git a/main.ml b/main.ml
index bbc9b06..58e13b6 100644 (file)
--- a/main.ml
+++ b/main.ml
@@ -17,7 +17,8 @@ let cmdspeclist =
     ("-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