This change is the result of a code audit. The changes are not drastic, but should...
[vsys.git] / directfifowatcher.ml
index 3972292..59b6127 100644 (file)
@@ -21,9 +21,8 @@ open Splice
 
 let close_if_open fd = (try (ignore(close fd);) with _ -> ())
 
-
 let direct_fifo_table: (string,(string*string*string*Unix.file_descr) option) Hashtbl.t = Hashtbl.create 1024
-let pidmap: (int,string) Hashtbl.t = Hashtbl.create 1024
+let pidmap: (int,string*Unix.file_descr) Hashtbl.t = Hashtbl.create 1024
 
 let rec list_check lst elt =
   match lst with
@@ -39,10 +38,13 @@ let openentry_int fifoin =
 
 
 (** Open fifos for a session. SHOULD NOt shutdown vsys if the fifos don't exist *)
-let openentry_in root_dir fqp_in backend_spec =
-    Dirwatcher.mask_watch root_dir;
+let openentry_in rp root_dir fqp_in backend_spec =
+  match rp with 
+    | 
+    | 
+    Dirwatcher.mask_watch root_dir fqp_in;
   let fd_in = openentry_int fqp_in in
-    Dirwatcher.unmask_watch root_dir [S_Open];
+    Dirwatcher.unmask_watch root_dir fqp_in;
   let (fqp,slice_name) = backend_spec in
     Hashtbl.replace direct_fifo_table fqp_in (Some(root_dir,fqp,slice_name,fd_in))
 
@@ -63,7 +65,8 @@ let connect_file fqp_in =
     Hashtbl.find direct_fifo_table fqp_in with _ -> None in
     match entry_info with
       | Some(_,execpath,slice_name,fifo_fdin) ->
-          fprintf logfd "Executing %s for slice %s\n" execpath slice_name;flush logfd;
+          (*fprintf logfd "Executing %s for slice %s\n" execpath
+           * slice_name;flush logfd;*)
           begin
             let len = String.length fqp_in in
             let fqp = String.sub fqp_in 0 (len-3) in
@@ -76,9 +79,10 @@ let connect_file fqp_in =
             (
             clear_nonblock fifo_fdin;
             let pid=try Some(create_process execpath [|execpath;slice_name|] fifo_fdin fifo_fdout fifo_fdout) with e -> None in
-              if (fifo_fdout <> stdout) then close_if_open fifo_fdout;
               match pid with 
-                | Some(pid) ->Hashtbl.add pidmap pid 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
             );
             ignore(sigprocmask SIG_UNBLOCK [Sys.sigchld]);
@@ -122,8 +126,11 @@ let closeentry fqp =
 let sigchld_handle s =
   let pid,_=Unix.waitpid [Unix.WNOHANG] 0 in
     try
-      let fqp_in = Hashtbl.find pidmap pid in
+      let fqp_in,fd_out = Hashtbl.find pidmap pid in
+        begin
         reopenentry fqp_in
+        end
+
     with _ -> ()
 
 let rec add_dir_watch fqp =