Merge branch '42wim-namedpipe'

This commit is contained in:
Nino Khodabandeh 2015-10-28 10:03:00 -07:00
commit 0f289693ec
1 changed files with 11 additions and 5 deletions

16
tail.go
View File

@ -58,6 +58,7 @@ type Config struct {
ReOpen bool // Reopen recreated files (tail -F) ReOpen bool // Reopen recreated files (tail -F)
MustExist bool // Fail early if the file does not exist MustExist bool // Fail early if the file does not exist
Poll bool // Poll for file changes instead of using inotify Poll bool // Poll for file changes instead of using inotify
Pipe bool // Is a named pipe (mkfifo)
RateLimiter *ratelimiter.LeakyBucket RateLimiter *ratelimiter.LeakyBucket
// Generic IO // Generic IO
@ -223,13 +224,18 @@ func (tail *Tail) tailFileSync() {
tail.openReader() tail.openReader()
var offset int64 = 0
var err error
// Read line by line. // Read line by line.
for { for {
// grab the position in case we need to back up in the event of a half-line // do not seek in named pipes
offset, err := tail.Tell() if !tail.Pipe {
if err != nil { // grab the position in case we need to back up in the event of a half-line
tail.Kill(err) offset, err = tail.Tell()
return if err != nil {
tail.Kill(err)
return
}
} }
line, err := tail.readLine() line, err := tail.readLine()