From 8264b725de40ca81cfa5dbba9363eca70145137f Mon Sep 17 00:00:00 2001 From: Dominic Breuker Date: Sun, 11 Aug 2019 23:01:53 +0200 Subject: [PATCH] improve read syscall reliability by inreasing buffer size and handling old kernel errors --- internal/fswatcher/inotify/inotify.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/fswatcher/inotify/inotify.go b/internal/fswatcher/inotify/inotify.go index 476769d..3d2e85e 100644 --- a/internal/fswatcher/inotify/inotify.go +++ b/internal/fswatcher/inotify/inotify.go @@ -17,7 +17,8 @@ const maximumWatchersFile = "/proc/sys/fs/inotify/max_user_watches" // set to -1 if the number cannot be determined var MaxWatchers int = -1 -const EventSize int = unix.SizeofInotifyEvent +// sizeof(struct inotify_event) + NAME_MAX + 1 +const EventSize int = unix.SizeofInotifyEvent + 255 + 1 func init() { mw, err := getMaxWatchers() @@ -71,7 +72,7 @@ func (i *Inotify) Watch(dir string) error { func (i *Inotify) Read(buf []byte) (int, error) { n, errno := unix.Read(i.FD, buf) - if n < 0 { + if n < 1 { return n, fmt.Errorf("reading from inotify fd %d: errno: %d", i.FD, errno) } return n, nil