diff --git a/pkg/watcher/linux.go b/pkg/watcher/linux.go index a3b4e02..f12fd04 100644 --- a/pkg/watcher/linux.go +++ b/pkg/watcher/linux.go @@ -9,6 +9,8 @@ import ( const CrDelMask uint32 = syscall.IN_CREATE | syscall.IN_DELETE +const inotifyCount = 16 + type FSWatcher struct { fd int wds []int @@ -41,9 +43,9 @@ func (fsw *FSWatcher) AddWatch(path string, mask uint32) error { // WatchForMask checking for events from mask and returns inotify mask to channel. func (fsw *FSWatcher) WatchForMask(fired chan uint32, mask uint32) { - buffer := make([]byte, syscall.SizeofInotifyEvent) go func() { for !fsw.closed { + buffer := make([]byte, syscall.SizeofInotifyEvent*inotifyCount) n, err := syscall.Read(fsw.fd, buffer) if err != nil { break @@ -53,9 +55,11 @@ func (fsw *FSWatcher) WatchForMask(fired chan uint32, mask uint32) { continue } - event := (*syscall.InotifyEvent)(unsafe.Pointer(&buffer[0])) - if event.Mask&mask > 0 { - fired <- event.Mask + for offset := 0; offset < len(buffer); offset += syscall.SizeofInotifyEvent { + event := (*syscall.InotifyEvent)(unsafe.Pointer(&buffer[offset])) + if event.Mask&mask > 0 { + fired <- event.Mask + } } } }()