Fail gracefully if inotify is not available

db4
Slava Pestov 2008-02-26 03:31:36 -06:00
parent 3d6cb9a90c
commit dddf4a0de8
1 changed files with 12 additions and 5 deletions

View File

@ -22,10 +22,12 @@ TUPLE: inotify watches ;
: wd>monitor ( wd -- monitor ) watches at ;
: <inotify> ( -- port )
: <inotify> ( -- port/f )
H{ } clone
inotify_init dup io-error inotify <buffered-port>
{ set-inotify-watches set-delegate } inotify construct ;
inotify_init dup 0 < [ 2drop f ] [
inotify <buffered-port>
{ set-inotify-watches set-delegate } inotify construct
] if ;
: inotify-fd inotify get-global port-handle ;
@ -45,7 +47,13 @@ TUPLE: inotify watches ;
dup simple-monitor-handle watches delete-at
simple-monitor-handle inotify-fd swap inotify_rm_watch io-error ;
: check-inotify
inotify get [
"inotify is not supported by this Linux release" throw
] unless ;
M: linux-io <monitor> ( path recursive? -- monitor )
check-inotify
drop IN_CHANGE_EVENTS add-watch ;
M: linux-monitor dispose ( monitor -- )
@ -103,8 +111,7 @@ TUPLE: inotify-task ;
f inotify-task <input-task> ;
: init-inotify ( mx -- )
<inotify>
dup inotify set-global
<inotify> dup inotify set-global
<inotify-task> swap register-io-task ;
M: inotify-task do-io-task ( task -- )