Added vsys.conf processing that Faiyaz requested.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Thu, 25 Oct 2007 02:11:41 +0000 (02:11 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Thu, 25 Oct 2007 02:11:41 +0000 (02:11 +0000)
Makefile
conffile.ml [new file with mode: 0644]
globals.ml
main.ml
vsyssh/vsyssh.c

index 90b6585..65e5736 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,8 +30,8 @@ docs: *.ml
 ocaml_inotify-0.4/inotify.cmxa:
        $(MAKE) -C ocaml_inotify-0.4 && cp -f ocaml_inotify-0.4/inotify_stubs.o ./
 
-vsys: ocaml_inotify-0.4/inotify.cmxa globals.cmx fdwatcher.cmx dirwatcher.cmx fifowatcher.cmx frontend.cmx backend.cmx main.cmx docs
-       ocamlopt -I ocaml_inotify-0.4 str.cmxa unix.cmxa inotify.cmxa globals.cmx fdwatcher.cmx dirwatcher.cmx fifowatcher.cmx frontend.cmx backend.cmx str.cmxa main.cmx -o vsys
+vsys: ocaml_inotify-0.4/inotify.cmxa globals.cmx fdwatcher.cmx conffile.cmx dirwatcher.cmx fifowatcher.cmx frontend.cmx backend.cmx main.cmx docs
+       ocamlopt -I ocaml_inotify-0.4 str.cmxa unix.cmxa inotify.cmxa globals.cmx fdwatcher.cmx dirwatcher.cmx fifowatcher.cmx frontend.cmx backend.cmx str.cmxa conffile.cmx main.cmx -o vsys
 
 vsys.b: inotify.cma inotify.cmi globals.ml fdwatcher.ml dirwatcher.ml fifowatcher.ml frontend.ml backend.ml main.ml
        ocamlc -g str.cma unix.cma inotify.cma globals.cmo fdwatcher.cmo dirwatcher.cmo fifowatcher.cmo frontend.cmo backend.cmo str.cma main.cmo -o vsys.b
diff --git a/conffile.ml b/conffile.ml
new file mode 100644 (file)
index 0000000..d7b8715
--- /dev/null
@@ -0,0 +1,17 @@
+open Printf
+open Scanf
+
+let split_conf_line s =
+  sscanf s "%s %s" (fun s1 s2->(s1,s2))
+
+let read_frontends f =
+  let f_file = try open_in f with e -> printf "Could not open config
+                                         file\n";flush Pervasives.stdout;raise e
+  in
+  let rec read_conf_file cur_list =
+    let next_line = try Some(input_line f_file) with _ -> None in
+      match next_line with
+        | Some(inp_line) -> read_conf_file (split_conf_line(inp_line)::cur_list)
+        | None -> cur_list
+  in
+    read_conf_file []
index 3ea4a32..4e2d332 100644 (file)
@@ -3,6 +3,7 @@ let backend = ref ""
 let debug = ref true
 let vsys_version = "0.5"
 let nochroot = ref false
+let conffile = ref ""
 
 type result = Success | Failed
 
diff --git a/main.ml b/main.ml
index be96b82..391074d 100644 (file)
--- a/main.ml
+++ b/main.ml
@@ -5,6 +5,7 @@ open Inotify
 open Backend
 open Frontend
 open Fifowatcher
+open Conffile
 
 let input_file_list = ref []
 let cur_dir = ref ""
@@ -12,6 +13,7 @@ let cur_slice = ref ""
 
 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")
@@ -22,13 +24,17 @@ let cont = ref true
 let _ =
   printf "Vsys v%s\n" Globals.vsys_version;flush stdout;
   Arg.parse cmdspeclist (fun x->()) "Usage: vsys <list of mount points>";  
-  if (!Globals.backend == "" || !input_file_list == []) then
+  if (!Globals.backend == "") then
       printf "Try vsys --help\n"
   else
     begin
     Dirwatcher.initialize ();
     Fifowatcher.initialize ();
-    let felst = List.map (fun lst->new frontendHandler lst) !input_file_list in
+    if (!Globals.conffile != "") then
+      let frontends = Conffile.read_frontends !Globals.conffile in
+        input_file_list:=List.concat [!input_file_list;frontends];
+
+    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 ()
     end
index 7ae4deb..105f565 100644 (file)
@@ -34,7 +34,7 @@ int main(int argc, char **argv, char **envp)
                inf=(char *)malloc(strlen(argv[1])+3);
                outf=(char *)malloc(strlen(argv[2])+4);
                strcpy(inf,argv[1]);
-               strcpy(inf,argv[2]);
+               strcpy(outf,argv[2]);
                strcat(inf,".in");
                strcat(outf,".out");