X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=dirwatcher.ml;h=e43de77b2f5a70a32103a32bf2a1c8df1e33c8b8;hb=c9636f84acdab799ccfc5d50824138db70d0a5d3;hp=f01cb3324dacab4f22848dd019d5b19cb14b9363;hpb=892d26d4e05de55ae94d21a586e6a0bfa724e327;p=vsys.git diff --git a/dirwatcher.ml b/dirwatcher.ml index f01cb33..e43de77 100644 --- a/dirwatcher.ml +++ b/dirwatcher.ml @@ -1,3 +1,5 @@ +(** Watches directories for events. Agnostic to vsys semantics of backends and +frontends *) open Inotify open Fdwatcher open Printf @@ -13,17 +15,24 @@ let fd = Inotify.init () let handle_dir_event dirname evlist str = let fname = String.concat "/" [dirname;str] in - printf "File: %s. " fname;List.iter + fprintf logfd "File: %s. " fname;List.iter (fun e -> - printf "Event: %s\n" (string_of_event e)) + fprintf logfd "Event: %s\n" (string_of_event e)) evlist; - flush Pervasives.stdout + flush logfd let add_watch dir events handler = printf "Adding watch for %s\n" dir;flush Pervasives.stdout; let wd = Inotify.add_watch fd dir events in Hashtbl.add wdmap wd (dir,handler) + (* XXX +let del_watch dir = + fprintf logfd "Removing watch for %s\n" dir;flush logfd; + let wd = Inotify.rm_watch fd dir in + Hashtbl.remove wdmap wd + *) + let asciiz s = let rec findfirstnul str idx len = if ((idx==len) || @@ -42,7 +51,7 @@ let receive_event (eventdescriptor:fname_and_fd) (bla:fname_and_fd) = | (wd,evlist,_,Some(str)) -> let purestr = asciiz(str) in let (dirname,handler) = - try Hashtbl.find wdmap wd with Not_found->printf "Unknown watch descriptor\n";raise Not_found + try Hashtbl.find wdmap wd with Not_found->fprintf logfd "Unknown watch descriptor\n";raise Not_found in ( match handler with