pass through arguments from command line

This commit is contained in:
Dominic Breuker
2018-02-13 21:41:41 +01:00
parent 2ed0991b9c
commit 91381d10a0
6 changed files with 60 additions and 23 deletions

View File

@@ -13,7 +13,7 @@ type Inotify struct {
paused bool
}
func NewInotify(ping chan struct{}) (*Inotify, error) {
func NewInotify(ping chan struct{}, print bool) (*Inotify, error) {
fd, errno := unix.InotifyInit1(unix.IN_CLOEXEC)
if fd == -1 {
return nil, fmt.Errorf("Can't init inotify: %d", errno)
@@ -25,15 +25,11 @@ func NewInotify(ping chan struct{}) (*Inotify, error) {
ping: ping,
paused: false,
}
go watch(i)
go watch(i, print)
return i, nil
}
func (i *Inotify) Start() {
go watch(i)
}
func (i *Inotify) Watch(dir string) error {
w, err := newWatcher(i.fd, dir, i.ping)
if err != nil {
@@ -79,10 +75,10 @@ type bufRead struct {
buf []byte
}
func watch(i *Inotify) {
func watch(i *Inotify, print bool) {
buf := make([]byte, 5*unix.SizeofInotifyEvent)
buffers := make(chan bufRead)
go eventLogger(i, buffers)
go eventLogger(i, buffers, print)
for {
n, _ := unix.Read(i.fd, buf)
if !i.paused {