race condition bug. The bug would be triggered when tailing a file
with file pointer not at beginning of file, and where the file was
truncated to have a length of less than the initial offset at just
the right moment (between the two lseek calls in this function).
}
else
{
- off_t start_pos;
+ off_t start_pos = -1;
off_t end_pos;
/* Use file_lines only if FD refers to a regular file for
}
else
{
+ /* Under very unlikely circumstances, it is possible to reach
+ this point after positioning the file pointer to end of file
+ via the `lseek (...SEEK_END)' above. In that case, reposition
+ the file pointer back to start_pos before calling pipe_lines. */
+ if (start_pos != -1)
+ xlseek (fd, start_pos, SEEK_SET, pretty_filename);
+
return pipe_lines (pretty_filename, fd, n_lines, read_pos);
}
}