check the stop channel while waiting on inotify

fixes http://bugs.activestate.com/show_bug.cgi?id=95718#c3
This commit is contained in:
Sridhar Ratnakumar 2012-10-11 21:47:58 -07:00
parent 3ff602e781
commit 5c84486ca3
1 changed files with 21 additions and 18 deletions

39
tail.go
View File

@ -146,30 +146,33 @@ func (tail *Tail) tailFileSync(end bool, retry bool) {
changes = tail.watcher.ChangeEvents() changes = tail.watcher.ChangeEvents()
} }
//log.Println("WAITING ", tail.Filename) select {
_, ok := <-changes case _, ok := <-changes:
//log.Println("RECEIVED ", tail.Filename) if !ok {
// file got deleted/renamed
if !ok { if retry {
// file got deleted/renamed log.Printf("File %s has been moved (logrotation?); reopening..", tail.Filename)
if retry { tail.reopen(retry)
log.Printf("File %s has been moved (logrotation?); reopening..", tail.Filename) log.Printf("File %s has been reopened.", tail.Filename)
tail.reopen(retry) tail.reader = bufio.NewReaderSize(tail.file, tail.maxlinesize)
log.Printf("File %s has been reopened.", tail.Filename) changes = nil
tail.reader = bufio.NewReaderSize(tail.file, tail.maxlinesize) continue
changes = nil } else {
continue log.Printf("File %s has gone away; skipping this file.\n", tail.Filename)
} else { tail.close()
log.Printf("File %s has gone away; skipping this file.\n", tail.Filename) return
tail.close() }
return
} }
case <-tail.stop:
// stop the tailer if requested.
// FIXME: respect DRY (see below)
return
} }
} }
} }
// stop the tailer if requested. // stop the tailer if requested.
// FIXME: won't happen promptly; http://bugs.activestate.com/show_bug.cgi?id=95718#c3
select { select {
case <-tail.stop: case <-tail.stop:
return return