]> go.fuhry.dev Git - fsnotify.git/commitdiff
Linux - fix possible problem on Close()
authorChris Howey <chris@howey.me>
Tue, 22 May 2012 14:12:07 +0000 (07:12 -0700)
committerChris Howey <chris@howey.me>
Tue, 22 May 2012 14:12:07 +0000 (07:12 -0700)
The Close() call should remove all watches BEFORE the call to close
the inotify instance.

fsnotify_linux.go

index 17ce195c8fb6ee4dc497da52b0a85584f949fa63..879dcef97bc898b1216cc31d158f1bac8d2e28e8 100644 (file)
@@ -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