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
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
| 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
| _ ->
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
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 []
(
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
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
()
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
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
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
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
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