add some hacky experiments for inotify event parsing

This commit is contained in:
Dominic Breuker
2018-02-11 22:15:10 +01:00
parent e681208a4a
commit 22df28ae1d
8 changed files with 214 additions and 31 deletions

View File

@@ -2,11 +2,15 @@ package inotify
import (
"fmt"
"io/ioutil"
"strconv"
"strings"
"golang.org/x/sys/unix"
)
const events = unix.IN_ALL_EVENTS
const MaximumWatchersFile = "/proc/sys/fs/inotify/max_user_watches"
type watcher struct {
wd int
@@ -23,3 +27,18 @@ func newWatcher(fd int, dir string, ping chan struct{}) (*watcher, error) {
dir: dir,
}, nil
}
func WatcherLimit() (int, error) {
b, err := ioutil.ReadFile(MaximumWatchersFile)
if err != nil {
return 0, fmt.Errorf("reading from %s: %v", MaximumWatchersFile, err)
}
s := strings.TrimSpace(string(b))
m, err := strconv.Atoi(s)
if err != nil {
return 0, fmt.Errorf("converting to integer: %v", err)
}
return m, nil
}