diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/inotify/bits.go | 1 | ||||
-rw-r--r-- | src/inotify/inotify.go | 15 | ||||
-rw-r--r-- | src/inotify/inutil/inotify_util.go | 84 | ||||
-rw-r--r-- | src/nshd/hackers_git/hackers_watch.go | 2 | ||||
-rw-r--r-- | src/nslcd_systemd/nslcd_systemd.go | 4 |
5 files changed, 53 insertions, 53 deletions
diff --git a/src/inotify/bits.go b/src/inotify/bits.go index 2c65736..eb0270f 100644 --- a/src/inotify/bits.go +++ b/src/inotify/bits.go @@ -11,6 +11,7 @@ type Fd int type Wd int type Mask uint32 + const ( // Supported events suitable for the `mask` parameter of Inotify.AddWatch(). IN_ACCESS Mask = (1<< 0) // File was accessed. diff --git a/src/inotify/inotify.go b/src/inotify/inotify.go index 9cbae17..0d67b44 100644 --- a/src/inotify/inotify.go +++ b/src/inotify/inotify.go @@ -1,16 +1,15 @@ package inotify import ( + "sync" "syscall" "unsafe" - "sync" ) type Inotify struct { fd Fd fdLock sync.RWMutex - - fullbuff [4096]byte + buffFull [4096]byte buff []byte buffLock sync.Mutex } @@ -27,7 +26,7 @@ func InotifyInit() (*Inotify, error) { o := Inotify{ fd: fd, } - o.buff = o.fullbuff[:0] + o.buff = o.buffFull[:0] return &o, err } @@ -36,7 +35,7 @@ func InotifyInit1(flags int) (*Inotify, error) { o := Inotify{ fd: fd, } - o.buff = o.fullbuff[:0] + o.buff = o.buffFull[:0] return &o, err } @@ -55,7 +54,7 @@ func (o *Inotify) RmWatch(wd Wd) error { func (o *Inotify) Close() error { o.fdLock.Lock() defer o.fdLock.Unlock() - defer func() { o.fd = -1; }() + defer func() { o.fd = -1 }() return sysclose(o.fd) } @@ -65,14 +64,14 @@ func (o *Inotify) Read() (Event, error) { if len(o.buff) == 0 { o.fdLock.RLock() - len, err := sysread(o.fd, o.fullbuff[:]) + len, err := sysread(o.fd, o.buffFull[:]) o.fdLock.RUnlock() if len == 0 { return Event{Wd: -1}, o.Close() } else if len < 0 { return Event{Wd: -1}, err } - o.buff = o.fullbuff[0:len] + o.buff = o.buffFull[0:len] } raw := (*syscall.InotifyEvent)(unsafe.Pointer(&o.buff[0])) diff --git a/src/inotify/inutil/inotify_util.go b/src/inotify/inutil/inotify_util.go index 46146f5..3a5eed5 100644 --- a/src/inotify/inutil/inotify_util.go +++ b/src/inotify/inutil/inotify_util.go @@ -1,78 +1,78 @@ package inutil import ( - "inotify" - "os" - "syscall" + "inotify" + "os" + "syscall" ) const ( // Flags for the parameter of InotifyInit1(). // These, oddly, appear to be 24-bit numbers. - IN_CLOEXEC = inotify.IN_CLOEXEC + IN_CLOEXEC = inotify.IN_CLOEXEC ) type Watcher struct { - Events <-chan inotify.Event - events chan<- inotify.Event - Errors <-chan error - errors chan<- error - in *inotify.Inotify + Events <-chan inotify.Event + events chan<- inotify.Event + Errors <-chan error + errors chan<- error + in *inotify.Inotify } func WatcherInit() (*Watcher, error) { - in, err := inotify.InotifyInit() - return newWatcher(in, err) + in, err := inotify.InotifyInit() + return newWatcher(in, err) } func WatcherInit1(flags int) (*Watcher, error) { - in, err := inotify.InotifyInit1(flags&^inotify.IN_NONBLOCK) - return newWatcher(in, err) + in, err := inotify.InotifyInit1(flags &^ inotify.IN_NONBLOCK) + return newWatcher(in, err) } func newWatcher(in *inotify.Inotify, err error) (*Watcher, error) { - events := make(chan inotify.Event, 1) - errors := make(chan error, 1) - o := &Watcher{ - Events: events, - events: events, - Errors: errors, - errors: errors, - in: in, - } - go o.worker() - return o, err + events := make(chan inotify.Event) + errors := make(chan error) + o := &Watcher{ + Events: events, + events: events, + Errors: errors, + errors: errors, + in: in, + } + go o.worker() + return o, err } func (o *Watcher) AddWatch(path string, mask inotify.Mask) (inotify.Wd, error) { - return o.in.AddWatch(path, mask); + return o.in.AddWatch(path, mask) } func (o *Watcher) RmWatch(wd inotify.Wd) error { - return o.in.RmWatch(wd); + return o.in.RmWatch(wd) } func (o *Watcher) Close() { - func() { - defer recover() - close(o.events) - close(o.errors) - }() - go o.in.Close() + func() { + defer recover() + close(o.events) + close(o.errors) + }() + go o.in.Close() } func (o *Watcher) worker() { - defer recover() - for { - ev, err := o.in.Read(); + defer recover() + for { + ev, err := o.in.Read() if ev.Wd >= 0 { - o.events <- ev - } - if err != nil { - if err.(*os.SyscallError).Err == syscall.EBADF { - o.Close() - } - o.errors <- err + o.events <- ev + } + if err != nil { + if err.(*os.SyscallError).Err == syscall.EBADF { + o.Close() + } + o.errors <- err } } } diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go index 0fa45c9..8559f88 100644 --- a/src/nshd/hackers_git/hackers_watch.go +++ b/src/nshd/hackers_git/hackers_watch.go @@ -192,7 +192,7 @@ Loop: if event.Name == nil { panic("recieved child event from inotify, but no child name") } - o.load_yaml_file(o.Cfg.Yamldir + "/" + *event.Name, true) + o.load_yaml_file(o.Cfg.Yamldir+"/"+*event.Name, true) } else { panic("recieved non-subscribed inotify event from kernel") } diff --git a/src/nslcd_systemd/nslcd_systemd.go b/src/nslcd_systemd/nslcd_systemd.go index 7caee26..be465bb 100644 --- a/src/nslcd_systemd/nslcd_systemd.go +++ b/src/nslcd_systemd/nslcd_systemd.go @@ -72,7 +72,7 @@ func Main(backend Backend) uint8 { } }() - sigs := make(chan os.Signal, 1) + sigs := make(chan os.Signal) signal.Notify(sigs, syscall.SIGTERM, syscall.SIGHUP) disable_nss_module() @@ -91,7 +91,7 @@ func Main(backend Backend) uint8 { sd.Notify(false, "STOPPING=1") return lsb.EXIT_NOTRUNNING } - sock := make(chan *net.UnixConn, 1) + sock := make(chan *net.UnixConn) go func() { defer lsb.Recover() for { |