From: Pieter Droogendijk Date: Sat, 7 Feb 2015 21:18:46 +0000 (+0100) Subject: Generate inotify fd in NewWatcher, pass fd into newFdPoller X-Git-Tag: v1.7.2~234 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=0f446c0e676434af0837e0004d7bb71ef876d0ec;p=fsnotify.git Generate inotify fd in NewWatcher, pass fd into newFdPoller --- diff --git a/inotify.go b/inotify.go index d33b96a..e02bf12 100644 --- a/inotify.go +++ b/inotify.go @@ -32,7 +32,13 @@ type Watcher struct { // NewWatcher establishes a new watcher with the underlying OS and begins waiting for events. func NewWatcher() (*Watcher, error) { - poller, err := newFdPoller() + // Create inotify fd + fd, errno := syscall.InotifyInit() + if fd == -1 { + return nil, errno + } + // Create epoll + poller, err := newFdPoller(fd) if err != nil { return nil, err } diff --git a/inotify_poller.go b/inotify_poller.go index fbd664e..726818c 100644 --- a/inotify_poller.go +++ b/inotify_poller.go @@ -19,15 +19,11 @@ type fdPoller struct { // Create a new inotify poller. // This creates an inotify handler, and an epoll handler. -func newFdPoller() (*fdPoller, error) { +func newFdPoller(fd int) (*fdPoller, error) { var errno error poller := new(fdPoller) + poller.fd = fd - // Create inotify fd - poller.fd, errno = syscall.InotifyInit() - if poller.fd == -1 { - return nil, errno - } // Create epoll fd poller.epfd, errno = syscall.EpollCreate(1) if poller.epfd == -1 {