From b59836fe7bde99cacd73379d286551ba01e88f9f Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Tue, 22 May 2012 07:12:07 -0700 Subject: [PATCH] Linux - fix possible problem on Close() The Close() call should remove all watches BEFORE the call to close the inotify instance. --- fsnotify_linux.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fsnotify_linux.go b/fsnotify_linux.go index 17ce195..879dcef 100644 --- a/fsnotify_linux.go +++ b/fsnotify_linux.go @@ -81,12 +81,14 @@ func (w *Watcher) Close() error { } w.isClosed = true - // Send "quit" message to the reader goroutine - w.done <- true + // Remove all watches for path := range w.watches { w.RemoveWatch(path) } + // Send "quit" message to the reader goroutine + w.done <- true + return nil } @@ -153,14 +155,12 @@ func (w *Watcher) readEvents() { // If EOF or a "done" message is received if n == 0 || done { - errno := syscall.Close(w.fd) - if errno != nil { - w.Error <- os.NewSyscallError("close", errno) - } + syscall.Close(w.fd) close(w.Event) close(w.Error) return } + if n < 0 { w.Error <- os.NewSyscallError("read", errno) continue -- 2.50.1