summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-09-03 13:49:22 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-09-03 13:49:22 -0600
commit959055420845d7c63148fd5be8f9cf4285e2446b (patch)
treed0a64e601f458feae6873e982f87b56a0ad33923 /src
parent9463f76baa6012fe6abb6f8ce229caa6d54c1216 (diff)
Fix issues in inotify bindings
Diffstat (limited to 'src')
-rw-r--r--src/inotify/inotify.go27
-rw-r--r--src/nshd/hackers_git/hackers_watch.go2
2 files changed, 16 insertions, 13 deletions
diff --git a/src/inotify/inotify.go b/src/inotify/inotify.go
index 976bdae..8c99a28 100644
--- a/src/inotify/inotify.go
+++ b/src/inotify/inotify.go
@@ -29,7 +29,7 @@ func InotifyInit() (*Inotify, error) {
fd: Cint(fd),
isClosed: false,
}
- o.buff = o.fullbuff[:]
+ o.buff = o.fullbuff[:0]
return &o, err
}
@@ -39,7 +39,7 @@ func InotifyInit1(flags Cint) (*Inotify, error) {
fd: Cint(fd),
isClosed: false,
}
- o.buff = o.fullbuff[:]
+ o.buff = o.fullbuff[:0]
return &o, err
}
@@ -65,30 +65,33 @@ func (o *Inotify) Close() error {
return sysclose(o.fd)
}
-func (o *Inotify) Read() (*Event, error) {
+func (o *Inotify) Read() (Event, error) {
if len(o.buff) == 0 {
if o.isClosed {
- return nil, InotifyAlreadyClosedError
+ return Event{Wd: -1}, InotifyAlreadyClosedError
}
+
len, err := sysread(o.fd, o.buff)
if len == 0 {
- return nil, o.Close()
+ return Event{Wd: -1}, o.Close()
} else if len <= 0 {
- return nil, err
+ return Event{Wd: -1}, err
}
o.buff = o.fullbuff[0:len]
}
+
raw := (*syscall.InotifyEvent)(unsafe.Pointer(&o.buff[0]))
- var ret Event
- ret.Wd = Cint(raw.Wd)
- ret.Mask = Mask(raw.Mask)
- ret.Cookie = raw.Cookie
- ret.Name = nil
+ ret := Event{
+ Wd: Cint(raw.Wd),
+ Mask: Mask(raw.Mask),
+ Cookie: raw.Cookie,
+ Name: nil,
+ }
if raw.Len > 0 {
bytes := (*[syscall.NAME_MAX]byte)(unsafe.Pointer(&o.buff[syscall.SizeofInotifyEvent]))
name := string(bytes[:raw.Len-1])
ret.Name = &name
}
o.buff = o.buff[0 : syscall.SizeofInotifyEvent+raw.Len]
- return &ret, nil
+ return ret, nil
}
diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go
index 3d72f94..f902229 100644
--- a/src/nshd/hackers_git/hackers_watch.go
+++ b/src/nshd/hackers_git/hackers_watch.go
@@ -137,7 +137,7 @@ func (o *Hackers) worker() {
if err != nil {
worker_error("failed to load %q: %v", o.cfg.Yamldir, err)
}
- for event, _ := o.in_fd.Read(); event != nil; event, _ = o.in_fd.Read() {
+ for event, err := o.in_fd.Read(); err == nil; event, err = o.in_fd.Read() {
switch event.Wd {
case o.in_wd_yaml:
// handle updates to yaml files