X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=directfifowatcher.ml;h=59b612783c7954b140ba8ff73365047e1f45289f;hb=acbdd1601fcfb161089d326e7e32b74b76f441e3;hp=29694ec9dd172679c0a3774c93f6556129a8a422;hpb=1a489047481c761be639e342c38326aeaca600f9;p=vsys.git diff --git a/directfifowatcher.ml b/directfifowatcher.ml index 29694ec..59b6127 100644 --- a/directfifowatcher.ml +++ b/directfifowatcher.ml @@ -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 @@ -77,7 +80,9 @@ 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 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]); @@ -121,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 =