Skip to content

Commit

Permalink
refactor: Move error handling of pipeOpen into that function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaqx0r committed Jul 12, 2024
1 parent 9716443 commit ae8f28f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/tailer/logstream/pipestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ func pipeOpen(pathname string) (*os.File, error) {
return os.Stdin, nil
}
// Open in nonblocking mode because the write end of the pipe may not have started yet.
return os.OpenFile(pathname, os.O_RDONLY|syscall.O_NONBLOCK, 0o600) // #nosec G304 -- path already validated by caller
fd, err := os.OpenFile(pathname, os.O_RDONLY|syscall.O_NONBLOCK, 0o600) // #nosec G304 -- path already validated by caller
if err != nil {
glog.Warningf("pipeOpen(%s): open failed: %v", pathname, err)
logErrors.Add(pathname, 1)
return nil, err
}
glog.V(2).Infof("pipeOpen(%s): opened new pipe %v", pathname, fd)
return fd, nil
}

// The read buffer size for pipes.
Expand All @@ -66,10 +73,8 @@ const defaultPipeReadBufferSize = 131072
func (ps *pipeStream) stream(ctx context.Context, wg *sync.WaitGroup, waker waker.Waker, _ os.FileInfo) error {
fd, err := pipeOpen(ps.pathname)
if err != nil {
logErrors.Add(ps.pathname, 1)
return err
}
glog.V(2).Infof("stream(%s): opened new pipe %v", ps.sourcename, fd)
b := make([]byte, defaultPipeReadBufferSize)
partial := bytes.NewBufferString("")
var total int
Expand Down

0 comments on commit ae8f28f

Please sign in to comment.