X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=dirwatcher.ml;h=e43de77b2f5a70a32103a32bf2a1c8df1e33c8b8;hb=a94e10d8cdc92ed752ad71888e13bb8ce9d42925;hp=3808e8bde2fcd97aa988bc19625b3afbd573443c;hpb=5648b4043b34c33111800aecba36f486627a30a0;p=vsys.git diff --git a/dirwatcher.ml b/dirwatcher.ml index 3808e8b..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) || @@ -34,7 +43,7 @@ let asciiz s = let nulterm = findfirstnul s 0 (String.length s) in String.sub s 0 nulterm -let receive_event (eventdescriptor:fd_and_fname) (bla:fd_and_fname) = +let receive_event (eventdescriptor:fname_and_fd) (bla:fname_and_fd) = let (_,fd) = eventdescriptor in let evs = Inotify.read fd in List.iter (fun x-> @@ -42,7 +51,7 @@ let receive_event (eventdescriptor:fd_and_fname) (bla:fd_and_fname) = | (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