Opened 6 hours ago
#854 new defect
Avoid using lseek() to set file position
| Reported by: | Olly Betts | Owned by: | Olly Betts |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.1.1 |
| Component: | Backend-Glass | Version: | 2.1.0 |
| Severity: | normal | Keywords: | |
| Cc: | Blocked By: | ||
| Blocking: | Operating System: | All |
Description
Constructing a Database object for a glass database from a file descriptor currently uses lseek() to set the file position before reading the version file.
That's not such a problem when we're opening the database as the current file position is used as the offset in the file to read the database from, but a call to Database::reopen() will also do this.
We should ideally only make one call to lseek() to read (and not change) the file position when the database is opened, and then use pread() for all reads of the version file (like we already do for the database tables).
This would make it safer to use dup() to create an fd to pass to Xapian (since such an fd shares its file position with the fd it was created from).
Background: https://github.com/openzim/libzim/pull/1119
