Skip to content

Commit

Permalink
Check if Filebeat log harvester tries to open named pipe (#20450) (#2…
Browse files Browse the repository at this point in the history
…2423)

## What does this PR do?

This PR adds a check before opening a file for harvester Filebeat. If the file is a named pipe, an error is returned and the file is not opened.

## Why is it important?

Previously if someone wanted to open a named pipe without a writer, Filebeat hangs.

## Related issues

Closes #18682

(cherry picked from commit a89d81f)
  • Loading branch information
kvch authored Nov 6, 2020
1 parent 560a126 commit 8d5318e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions filebeat/input/log/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@ func (h *Harvester) shouldExportLine(line string) bool {
// is returned and the harvester is closed. The file will be picked up again the next time
// the file system is scanned
func (h *Harvester) openFile() error {
fi, err := os.Stat(h.state.Source)
if err != nil {
return fmt.Errorf("failed to stat source file %s: %v", h.state.Source, err)
}
if fi.Mode()&os.ModeNamedPipe != 0 {
return fmt.Errorf("failed to open file %s, named pipes are not supported", h.state.Source)
}

f, err := file_helper.ReadOpen(h.state.Source)
if err != nil {
return fmt.Errorf("Failed opening %s: %s", h.state.Source, err)
Expand Down

0 comments on commit 8d5318e

Please sign in to comment.