Continuation...
authorSapan Bhatia <sapanb@cs.princeton.edu>
Sat, 28 Jun 2008 22:28:33 +0000 (22:28 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Sat, 28 Jun 2008 22:28:33 +0000 (22:28 +0000)
backend.ml
conffile.ml
directfifowatcher.ml
dirwatcher.ml
fdwatcher.ml
frontend.ml
globals.ml
main.ml

index 34dde6b..535c549 100644 (file)
@@ -54,7 +54,7 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) =
                 Dirwatcher.add_watch fqp [S_Create;S_Delete] func 
               end
               with _ ->
-                fprintf logfd "Could not create %s. Looks like a slice shot itself in the foot\n" fqp;flush logfd;
+                logprint "Could not create %s. Looks like a slice shot itself in the foot\n" fqp;
            )
            slice_list
 
@@ -163,7 +163,7 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) =
                              | S_REG ->
                                  this#new_script slice_list fqp
                              | _ ->
-                                 fprintf logfd "Don't know what to do with %s\n" curfile;flush logfd
+                                 logprint "Don't know what to do with %s\n" curfile
                          end
                  end
            with _
index 6279d16..0d0f0f1 100644 (file)
@@ -8,7 +8,7 @@ let split_conf_line s =
 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
+      _ -> logprint "vsys directory not setup for slice %s\n" slice;None
   in
     match verdict with 
       | None->false 
@@ -22,7 +22,7 @@ let rec in_list elt lst =
 
 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
+  let f_file = try open_in f with e -> logprint "Could not open config file\n";raise e
   in
   let rec read_conf_file cur_list =
     let next_line = try Some(input_line f_file) with _ -> None in
index ea71ca1..3dd4b8a 100644 (file)
@@ -40,7 +40,7 @@ let rec list_check lst elt =
 let openentry_safet fifoin =
   let fdin =
     try openfile fifoin [O_RDONLY;O_NONBLOCK] 0o777 with 
-        e->fprintf logfd "Error opening and connecting FIFO: %s,%o\n" fifoin 0o777;flush logfd;raise e
+        e->logprint "Error opening and connecting FIFO: %s,%o\n" fifoin 0o777;raise e
   in
     fdin
 
@@ -77,7 +77,7 @@ let connect_file fqp_in =
             let fqp_out = String.concat "." [fqp;"out"] in
             let fifo_fdout =
               try openfile fqp_out [O_WRONLY;O_NONBLOCK] 0o777 with
-                  _->fprintf logfd "%s Output pipe not open, using stdout in place of %s\n" slice_name fqp_out;flush logfd;stdout
+                  _->logprint "%s Output pipe not open, using stdout in place of %s\n" slice_name fqp_out;stdout
             in
               ignore(sigprocmask SIG_BLOCK [Sys.sigchld]);
               (
@@ -87,7 +87,7 @@ let connect_file fqp_in =
                     | Some(pid) ->
                         if (fifo_fdout <> stdout) then close_if_open fifo_fdout;
                         Hashtbl.add pidmap pid (fqp_in,fifo_fdout)
-                    | None ->fprintf logfd "Error executing service: %s\n" execpath;flush logfd;reopenentry fqp_in
+                    | None ->logprint "Error executing service: %s\n" execpath;reopenentry fqp_in
               );
               ignore(sigprocmask SIG_UNBLOCK [Sys.sigchld]);
           end
@@ -96,7 +96,7 @@ let connect_file fqp_in =
 
 (** Make a pair of fifo entries *)
 let mkentry fqp abspath perm uname = 
-  fprintf logfd "Making entry %s->%s\n" fqp abspath;flush logfd;
+  logprint "Making entry %s->%s\n" fqp abspath;
   let fifoin=sprintf "%s.in" fqp in
   let fifoout=sprintf "%s.out" fqp in
     (try Unix.unlink fifoin with _ -> ());
@@ -114,7 +114,7 @@ let mkentry fqp abspath perm uname =
          );
          Success
      with 
-         e->fprintf logfd "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp fifoout;flush logfd;Failed)
+         e->logprint "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp fifoout;Failed)
 
 
 (** Close fifos that just got removed *)
index 667eba7..e06b6fb 100644 (file)
@@ -20,14 +20,13 @@ let rec list_check lst elt =
 
 let handle_dir_event dirname evlist str = 
   let fname = String.concat "/" [dirname;str] in
-    fprintf logfd "File: %s. " fname;List.iter 
-                                       (fun e -> 
-                                          fprintf logfd "Event: %s\n" (string_of_event e)) 
-                                       evlist;
-    flush logfd
+    logprint "File: %s. " fname;
+    List.iter 
+      (fun e -> 
+         logprint "Event: %s\n" (string_of_event e)) 
+      evlist
 
 let add_watch dir events handler =
-  let evcheck = list_check events in
   let wd = Inotify.add_watch fd dir events in
     Hashtbl.add wdmap wd (dir,Some(handler))
       (* Ignore the possibility that the whole directory can disappear and come
@@ -35,6 +34,7 @@ let add_watch dir events handler =
 
 let mask_watch fqp =
   try 
+    print "Masking %s %d\n" fqp (String.length fqp);
     Hashtbl.replace masks fqp true
   with _ ->
     ()
@@ -45,7 +45,7 @@ let unmask_watch fqp =
       Hashtbl.remove masks fqp
     end
   else
-    fprintf logfd "WARNING: %s -- Unpaired unmask\n" fqp;flush logfd
+    logprint "WARNING: %s -- Unpaired unmask\n" fqp
   
 let asciiz s =
   let rec findfirstnul str idx len =
@@ -69,14 +69,18 @@ let receive_event (eventdescriptor:fname_and_fd) (bla:fname_and_fd) =
                                  try Hashtbl.find wdmap wd with Not_found->("",None)
                                in
                                    match handler with
-                                     | None->fprintf logfd "Unhandled watch descriptor\n";flush logfd
+                                     | None->logprint "Unhandled watch descriptor\n"
                                      | Some(handler)->
                                          let fqp = String.concat "/" [dirname;purestr] in
                                          let mask_filter = Hashtbl.mem masks fqp in
-                                           if (not mask_filter) then
-                                             begin
+                                           begin
+                                           (*print "Received event for - %s\n"
+                                            * fqp;*)
+                                           if ((not mask_filter) && false) then
                                                 handler wd dirname evlist purestr
-                                             end
+                                           else
+                                             print "%s is masked\n" fqp
+                                           end
                        end
                    | _ -> ()) 
       evs
index 95d4be4..a85baaa 100644 (file)
@@ -30,6 +30,6 @@ let start_watch () =
                        func evd fd_other
                      with e->
                        let wtf = Printexc.to_string e in
-                         fprintf logfd "%s\n" wtf
+                         logprint "%s\n" wtf
                 ) fds
   done
index ba5ca4d..ad36172 100644 (file)
@@ -61,7 +61,7 @@ object(this)
           Unix.unlink fqp_in;
           Unix.unlink fqp_out
         with _ ->
-          fprintf logfd "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ());flush logfd
+          logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
 
   method rmdir rp =
     match rp with Relpath(rel) ->
@@ -70,7 +70,7 @@ object(this)
         try
           Unix.rmdir fqp
         with _ ->
-          fprintf logfd "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ());flush logfd
+          logprint "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
 
   initializer 
     (
index 4c04057..1506e01 100644 (file)
@@ -9,6 +9,9 @@ let log_filepath = ref "/var/log/vsys"
 let failsafe = ref false
 
 let logfd = open_out_gen [Open_append;Open_creat] 0o644 !log_filepath
+let logprint fmt = Printf.fprintf logfd (fmt ^^ "%!")
+let print fmt = Printf.printf (fmt ^^ "%!")
+
 type result = Success | Failed
 type fname_and_fd = string option * Unix.file_descr
 
diff --git a/main.ml b/main.ml
index 0abccdb..872dc59 100644 (file)
--- a/main.ml
+++ b/main.ml
@@ -25,8 +25,8 @@ let cmdspeclist =
   ]
 
 let _ =
-  printf "Starting Vsys v%s\n" Globals.vsys_version;flush stdout;
-  fprintf logfd "Starting Vsys v%s\n" Globals.vsys_version;flush logfd;
+  logprint "Starting Vsys v%s\n" Globals.vsys_version;
+  print "Starting Vsys v%s\n" Globals.vsys_version;
   Arg.parse cmdspeclist (fun x->()) "Usage: vsys <list of mount points>";  
   if (!Globals.backend == "") then
     printf "Try vsys --help\n"
@@ -34,7 +34,7 @@ let _ =
     begin
       if (!daemonize) then
         begin
-          printf "Daemonizing\n";flush Pervasives.stdout;
+          print "Daemonizing\n";
           let child = Unix.fork () in
             if (child <> 0) then
               begin
@@ -56,8 +56,7 @@ let _ =
 
       let felst = List.map 
                     (fun lst->let (x,y)=lst in 
-                       fprintf logfd "Slice %s (%s)\n" x y;
-                       flush logfd;
+                       logprint "Slice %s (%s)\n" x y;
                        new frontendHandler lst) 
                     !input_file_list in
       let _ = new backendHandler !Globals.backend felst in