summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-09-08 20:40:10 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-09-08 20:40:10 -0600
commiteed575704b9277b71fb85846cb16dfa94549465c (patch)
treee3fb2dafcd92190b18c7695fb274c39e55a4ef94 /src
parentbdfdfb549ca887340ceb5e2d0024954dc9c4cee9 (diff)
I am dumb, fix inotify bindings
Diffstat (limited to 'src')
-rw-r--r--src/inotify/bits.go11
-rw-r--r--src/inotify/inotify.go18
-rw-r--r--src/nshd/hackers_git/hackers.go4
3 files changed, 15 insertions, 18 deletions
diff --git a/src/inotify/bits.go b/src/inotify/bits.go
index 9162435..432933c 100644
--- a/src/inotify/bits.go
+++ b/src/inotify/bits.go
@@ -1,7 +1,5 @@
package inotify
-import "sync/atomic"
-
const (
// Flags for the parameter of InotifyInit1().
// These, oddly, appear to be 24-bit numbers.
@@ -11,15 +9,8 @@ const (
// Logically, Fd and Wd should be 'int', not 'int64', to match the OS.
// But, because there's no 'sync/atomic.SwapInt', we cast up to int64.
-type Wd int64
type Fd int64
-
-func swapFd(addr *Fd, new Fd) (old Fd) {
- return Fd(atomic.SwapInt64((*int64)(addr), int64(new)))
-}
-func loadFd(addr *Fd) Fd {
- return Fd(atomic.LoadInt64((*int64)(addr)))
-}
+type Wd int64
type Mask uint32
const (
diff --git a/src/inotify/inotify.go b/src/inotify/inotify.go
index f7db1b0..9cbae17 100644
--- a/src/inotify/inotify.go
+++ b/src/inotify/inotify.go
@@ -8,6 +8,7 @@ import (
type Inotify struct {
fd Fd
+ fdLock sync.RWMutex
fullbuff [4096]byte
buff []byte
@@ -40,15 +41,22 @@ func InotifyInit1(flags int) (*Inotify, error) {
}
func (o *Inotify) AddWatch(path string, mask Mask) (Wd, error) {
- return inotify_add_watch(loadFd(&o.fd), path, mask)
+ o.fdLock.RLock()
+ defer o.fdLock.RUnlock()
+ return inotify_add_watch(o.fd, path, mask)
}
func (o *Inotify) RmWatch(wd Wd) error {
- return inotify_rm_watch(loadFd(&o.fd), wd)
+ o.fdLock.RLock()
+ defer o.fdLock.RUnlock()
+ return inotify_rm_watch(o.fd, wd)
}
func (o *Inotify) Close() error {
- return sysclose(swapFd(&o.fd, -1))
+ o.fdLock.Lock()
+ defer o.fdLock.Unlock()
+ defer func() { o.fd = -1; }()
+ return sysclose(o.fd)
}
func (o *Inotify) Read() (Event, error) {
@@ -56,7 +64,9 @@ func (o *Inotify) Read() (Event, error) {
defer o.buffLock.Unlock()
if len(o.buff) == 0 {
- len, err := sysread(loadFd(&o.fd), o.buff)
+ o.fdLock.RLock()
+ len, err := sysread(o.fd, o.fullbuff[:])
+ o.fdLock.RUnlock()
if len == 0 {
return Event{Wd: -1}, o.Close()
} else if len < 0 {
diff --git a/src/nshd/hackers_git/hackers.go b/src/nshd/hackers_git/hackers.go
index f84b110..88f27ed 100644
--- a/src/nshd/hackers_git/hackers.go
+++ b/src/nshd/hackers_git/hackers.go
@@ -24,7 +24,6 @@ type Hackers struct {
util.NullBackend
cfg Config
lock sync.RWMutex
- workers sync.WaitGroup
users map[int32]user
groups map[string]map[string]bool
@@ -48,17 +47,14 @@ func NewHackers(config Config) *Hackers {
logger.Err("Could not initialize hackers.git: %v", err)
return nil
}
- o.workers.Add(1)
go func() {
defer lsb.Recover()
- defer o.workers.Done()
o.worker()
}()
return &o
}
func (o *Hackers) Close() {
- defer o.workers.Wait()
logger.Info("Closing hackers.git session")
o.lock.Lock()
defer o.lock.Unlock()