implement DoInotify; include "sys.m"; sys : Sys; include "draw.m"; draw : Draw; include "bufio.m"; bufio : Bufio; Iobuf : import bufio; include "inotify.m"; inotify :Inotify; Event, Watcher : import inotify; DoInotify: module { init: fn(ctxt: ref Draw->Context, args: list of string); }; debug : con 1; err_chan : chan of string; logger() { txt : string; while((txt = <- err_chan) != nil) { if(debug) sys->print("%s\n", txt); } if(debug) sys->print("Closing\n"); } init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH; inotify = load Inotify "inotify.dis"; err_chan = chan of string; spawn logger(); w := inotify->new_watcher("/tmp", err_chan); e : ref Event; e = <- w.events; while(e != nil) { if(e.matches(Inotify->ACCESS)) sys->print("Access %s %s\n", e.filename, e.target); if(e.matches(Inotify->CREATE)) sys->print("Create %s %s\n", e.filename, e.target); if(e.matches(Inotify->DELETE)) sys->print("Delete %s %s\n", e.filename, e.target); if(e.matches(Inotify->MODIFY)) sys->print("Modify %s %s\n", e.filename, e.target); if(e.matches(Inotify->ISDIR)) sys->print("ISDIR %s %s\n", e.filename, e.target); if(e.target == "exit") w.kill(); e = <- w.events; } } # Putall rm *.dis ; mk ; do; sleep 3; echo > exit && rm exit # kill Do; kill Inotify