From f25c2e80f95ae4f1162ade4275e33e5fb578af8d Mon Sep 17 00:00:00 2001 From: slava Date: Fri, 16 May 2008 01:44:52 -0500 Subject: [PATCH] Fix Linux monitors --- core/debugger/debugger.factor | 4 +++- extra/io/monitors/monitors-tests.factor | 3 ++- extra/io/unix/linux/monitors/monitors.factor | 13 ++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/debugger/debugger.factor b/core/debugger/debugger.factor index ad74889236..e6dfb79e07 100755 --- a/core/debugger/debugger.factor +++ b/core/debugger/debugger.factor @@ -7,7 +7,7 @@ splitting math.parser classes.tuple continuations continuations.private combinators generic.math classes.builtin classes compiler.units generic.standard vocabs threads threads.private init kernel.private libc io.encodings -mirrors accessors math.order ; +mirrors accessors math.order destructors ; IN: debugger GENERIC: error. ( error -- ) @@ -300,6 +300,8 @@ M: bad-create summary drop "Bad parameters to create" ; M: attempt-all-error summary drop "Nothing to attempt" ; +M: already-disposed summary drop "Attempting to operate on disposed object" ; + ] with-monitors dispose + [ ] [ [ "" resource-path f ] with-monitors dispose ] unit-test + [ ] [ [ "" resource-path t ] with-monitors dispose ] unit-test ] when diff --git a/extra/io/unix/linux/monitors/monitors.factor b/extra/io/unix/linux/monitors/monitors.factor index 17d3041aaf..136a892aa6 100644 --- a/extra/io/unix/linux/monitors/monitors.factor +++ b/extra/io/unix/linux/monitors/monitors.factor @@ -5,7 +5,7 @@ io.files io.buffers io.monitors io.ports io.timeouts io.unix.backend io.unix.select io.encodings.utf8 unix.linux.inotify assocs namespaces threads continuations init math math.bitfields sets alien alien.strings alien.c-types -vocabs.loader accessors system hashtables ; +vocabs.loader accessors system hashtables destructors ; IN: io.unix.linux.monitors SYMBOL: watches @@ -23,9 +23,9 @@ TUPLE: linux-monitor < monitor wd inotify watches disposed ; : wd>monitor ( wd -- monitor ) watches get at ; : ( -- port/f ) - inotify_init dup 0 < [ drop f ] [ ] if ; + inotify_init dup 0 < [ drop f ] [ ] if ; -: inotify-fd inotify get handle>> ; +: inotify-fd inotify get handle>> handle-fd ; : check-existing ( wd -- ) watches get key? [ @@ -57,8 +57,10 @@ M: linux (monitor) ( path recursive? mailbox -- monitor ) M: linux-monitor dispose* ( monitor -- ) [ [ wd>> ] [ watches>> ] bi delete-at ] [ - [ inotify>> handle>> ] [ wd>> ] bi - inotify_rm_watch io-error + dup inotify>> disposed>> [ drop ] [ + [ inotify>> handle>> handle-fd ] [ wd>> ] bi + inotify_rm_watch io-error + ] if ] bi ; : ignore-flags? ( mask -- ? ) @@ -108,6 +110,7 @@ M: linux-monitor dispose* ( monitor -- ) ] if ; : inotify-read-loop ( port -- ) + dup check-disposed dup wait-to-read 0 over buffer>> parse-file-notifications 0 over buffer>> buffer-reset