None of the above. This is actually much simpler:
1) Open the file
2) call read() ) again in non-blocking mode to read the data.
3) If you get -EWOULDBLOCK , then do a select() . If the data is ready to read, return to step 2.
4) If the timing expires (say, 1 second timeout), check if the file has been rotated. (Easy way: check ctime on the new file, but probably the best way. Look at the tail -F .. sources.) If a new file has been created, call close() and go to 1. Otherwise, go to 3.
Also, see fail2ban .
source share