Skip to content

Commit

Permalink
warn if user is using inotify to tail a symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus committed Mar 8, 2024
1 parent 44ec3b9 commit 53fb10a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/acquisition/modules/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ func (f *FileSource) StreamingAcquisition(out chan types.Event, t *tomb.Tomb) er
}
}

filink, err := os.Lstat(file)

if err != nil {
f.logger.Errorf("Could not lstat() new file %s, ignoring it : %s", file, err)
continue
}

if filink.Mode()&os.ModeSymlink == os.ModeSymlink && inotifyPoll {
f.logger.Warnf("File %s is a symlink, but inotify poll is enabled. Crowdsec will not be able to detect rotation. Consider setting poll_without_inotify to true in your configuration", file)
}

tail, err := tail.TailFile(file, tail.Config{ReOpen: true, Follow: true, Poll: inotifyPoll, Location: &tail.SeekInfo{Offset: 0, Whence: io.SeekEnd}, Logger: log.NewEntry(log.StandardLogger())})
if err != nil {
f.logger.Errorf("Could not start tailing file %s : %s", file, err)
Expand Down Expand Up @@ -455,6 +466,17 @@ func (f *FileSource) monitorNewFiles(out chan types.Event, t *tomb.Tomb) error {
}
}

filink, err := os.Lstat(event.Name)

if err != nil {
logger.Errorf("Could not lstat() new file %s, ignoring it : %s", event.Name, err)
continue
}

if filink.Mode()&os.ModeSymlink == os.ModeSymlink && inotifyPoll {
logger.Warnf("File %s is a symlink, but inotify poll is enabled. Crowdsec will not be able to detect rotation. Consider setting poll_without_inotify to true in your configuration", event.Name)
}

//Slightly different parameters for Location, as we want to read the first lines of the newly created file
tail, err := tail.TailFile(event.Name, tail.Config{ReOpen: true, Follow: true, Poll: inotifyPoll, Location: &tail.SeekInfo{Offset: 0, Whence: io.SeekStart}})
if err != nil {
Expand Down

0 comments on commit 53fb10a

Please sign in to comment.