mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
Merge branch 'fsync-shadow-files-before-rename' of https://github.com/awelzel/zeek
* 'fsync-shadow-files-before-rename' of https://github.com/awelzel/zeek: logging/writers/ascii: shadow files: Add fsync() before rename()
This commit is contained in:
commit
1b3b9a3cfc
5 changed files with 45 additions and 3 deletions
30
src/util.cc
30
src/util.cc
|
@ -2162,6 +2162,36 @@ bool safe_pwrite(int fd, const unsigned char* data, size_t len, size_t offset)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool safe_fsync(int fd)
|
||||
{
|
||||
int r;
|
||||
|
||||
/*
|
||||
* Failure cases of fsync(2) are EABDF, EINTR, ENOSPC, EROFS, EINVAL, EDQUOT.
|
||||
*
|
||||
* For EINTR, one can just retry until it is not interrupted. For the others
|
||||
* we report an error.
|
||||
*
|
||||
* Note that we don't use the reporter here to allow use from different threads.
|
||||
*/
|
||||
do
|
||||
{
|
||||
r = fsync(fd);
|
||||
} while ( r < 0 && errno == EINTR );
|
||||
|
||||
if ( r < 0 )
|
||||
{
|
||||
char buf[128];
|
||||
zeek_strerror_r(errno, buf, sizeof(buf));
|
||||
fprintf(stderr, "safe_fsync error %d: %s\n", errno, buf);
|
||||
abort();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void safe_close(int fd)
|
||||
{
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue