From 46e48c60e9d524bf71631561e193c443613a2bb5 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Tue, 4 Mar 2008 20:39:41 +0000 Subject: [PATCH] Bug squashes --- backend.ml | 13 +++++++++---- conffile.ml | 12 +++++++++++- directfifowatcher.ml | 1 + dirwatcher.ml | 28 ++++++++++++++-------------- frontend.ml | 3 +++ main.ml | 2 +- 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/backend.ml b/backend.ml index d85ee7d..6bf6796 100644 --- a/backend.ml +++ b/backend.ml @@ -93,6 +93,8 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = with _ -> None + method is_acl fname = Str.string_match acl_file_regexp fname 0 + (** Gets called every time there's an inotify event at the backend @param dirname Name of the backend directory @param evlist Description of what happened @@ -152,7 +154,9 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = let cont = ref true in while (!cont) do try - let curfile = readdir dir_handle in + let curfile = readdir dir_handle in + if (not (this#is_acl curfile)) then + begin let fqp = String.concat "/" [dir;curfile] in let acl_fqp = String.concat "." [fqp;"acl"] in let acl_filter = this#make_filter acl_fqp in @@ -161,7 +165,7 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = | None -> frontend_lst | Some(filter) -> List.filter (fun fe->Hashtbl.mem filter (fe#get_slice_name ())) frontend_lst in - if (Str.string_match file_regexp curfile 0 && not (Str.string_match acl_file_regexp curfile 0)) then + if (Str.string_match file_regexp curfile 0) then let s = Unix.stat fqp in begin match s.st_kind with @@ -173,8 +177,9 @@ class backendHandler dir_root (frontend_lst: frontendHandler list) = | _ -> fprintf logfd "Don't know what to do with %s\n" curfile;flush logfd end - with - _->cont:=false;() + end + with _ + ->cont:=false;() done in begin diff --git a/conffile.ml b/conffile.ml index 21175e9..d9fe129 100644 --- a/conffile.ml +++ b/conffile.ml @@ -5,13 +5,23 @@ open Scanf let split_conf_line s = sscanf s "%s %s" (fun s1 s2->(s1,s2)) +let rec in_list elt lst = + match lst with + | car::cdr -> + if (elt = car) then true else in_list elt cdr + | [] -> false + let read_frontends f = 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 = 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) + | 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 + in + read_conf_file new_list | None -> cur_list in read_conf_file [] diff --git a/directfifowatcher.ml b/directfifowatcher.ml index 29694ec..3972292 100644 --- a/directfifowatcher.ml +++ b/directfifowatcher.ml @@ -76,6 +76,7 @@ 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 | None ->fprintf logfd "Error executing service: %s\n" execpath;flush logfd;reopenentry fqp_in diff --git a/dirwatcher.ml b/dirwatcher.ml index 67a8c92..e96c4e9 100644 --- a/dirwatcher.ml +++ b/dirwatcher.ml @@ -28,11 +28,12 @@ let handle_dir_event dirname evlist str = let add_watch dir events handler = let evcheck = list_check events in - let oneshot = if (evcheck S_Oneshot) then true else false - in let wd = Inotify.add_watch fd dir events in Hashtbl.add masks dir (wd,handler); - Hashtbl.add wdmap wd (dir,Some(handler),oneshot) + Hashtbl.add wdmap wd (dir,Some(handler)) + + (* Ignore the possibility that the whole directory can disappear and come + * back while it is masked *) let mask_watch dir = try @@ -43,7 +44,7 @@ let mask_watch dir = () let unmask_watch dir events = - let _,handler = Hashtbl.find masks dir in + let _,handler = try Hashtbl.find masks dir with Not_found->fprintf logfd "unmask called without mask: %s\n" dir;flush logfd;raise Not_found in try Hashtbl.remove masks dir; add_watch dir events handler @@ -65,16 +66,15 @@ let receive_event (eventdescriptor:fname_and_fd) (bla:fname_and_fd) = List.iter (fun x-> match x with | (wd,evlist,_,Some(str)) -> - let purestr = asciiz(str) in - let (dirname,handler,oneshot) = - try Hashtbl.find wdmap wd with Not_found->("",None,false) - in - if (oneshot) then Hashtbl.remove wdmap wd; - ( - match handler with - | None->fprintf logfd "Unhandled watch descriptor\n";flush logfd - | Some(handler)->handler wd dirname evlist purestr - ) + begin + let purestr = asciiz(str) in + let (dirname,handler) = + try Hashtbl.find wdmap wd with Not_found->("",None) + in + match handler with + | None->fprintf logfd "Unhandled watch descriptor\n";flush logfd + | Some(handler)->handler wd dirname evlist purestr + end | _ -> ()) evs diff --git a/frontend.ml b/frontend.ml index 43c2ffa..e8526cc 100644 --- a/frontend.ml +++ b/frontend.ml @@ -77,6 +77,7 @@ object(this) 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 initializer + ( try let s = Unix.stat root_dir in if (s.st_kind<>S_DIR) then @@ -90,8 +91,10 @@ object(this) Unix.mkdir root_dir 0o700 end; with Unix.Unix_error(_,_,_) -> + begin try Unix.mkdir root_dir 0o700; with _ -> (); + end); Directfifowatcher.add_dir_watch root_dir end diff --git a/main.ml b/main.ml index a70a473..bbc9b06 100644 --- a/main.ml +++ b/main.ml @@ -51,7 +51,7 @@ let _ = input_file_list:=List.concat [!input_file_list;frontends] end; - let felst = List.map (fun lst->let (x,y)=lst in printf "Slice %s (%s)\n" x y;flush logfd;new frontendHandler lst) !input_file_list in + let felst = List.map (fun lst->let (x,y)=lst in fprintf logfd "Slice %s (%s)\n" x y;flush logfd;new frontendHandler lst) !input_file_list in let _ = new backendHandler !Globals.backend felst in Fdwatcher.start_watch () end -- 2.43.0