Files
pspy/internal/fswatcher/inotify/watcher.go
2018-03-12 08:58:01 +01:00

31 lines
515 B
Go

package inotify
import (
"fmt"
"io/ioutil"
"strconv"
"strings"
)
const maximumWatchersFile = "/proc/sys/fs/inotify/max_user_watches"
type Watcher struct {
WD int
Dir string
}
func GetLimit() (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
}