X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=dirwatcher.ml;h=e43de77b2f5a70a32103a32bf2a1c8df1e33c8b8;hb=c9636f84acdab799ccfc5d50824138db70d0a5d3;hp=b33b890e6aa7812851e834e59e5e0fd17109d73f;hpb=29f0ca740297bf929d328b9f17a8ce36aff06e1f;p=vsys.git diff --git a/dirwatcher.ml b/dirwatcher.ml index b33b890..e43de77 100644 --- a/dirwatcher.ml +++ b/dirwatcher.ml @@ -15,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) || @@ -44,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