Skip to content

Commit

Permalink
Try 3 times to lock it. If it fails, return an error
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Apr 1, 2015
1 parent 0add972 commit 611a2f7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/exfile.c
Expand Up @@ -131,7 +131,7 @@ exfile_t *exfile_init(TALLOC_CTX *ctx, uint32_t max_entries, uint32_t max_idle)
*/
int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool append)
{
uint32_t i;
uint32_t i, tries;
uint32_t hash;
time_t now = time(NULL);
struct stat st;
Expand Down Expand Up @@ -269,7 +269,9 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app
* locked it. So, we close the current file, re-open it,
* and try again/
*/
if (rad_lockfd_nonblock(ef->entries[i].fd, 0) < 0) {
tries = 0;
while ((rad_lockfd_nonblock(ef->entries[i].fd, 0) < 0) &&
(tries < 4)) {
if (errno != EAGAIN) {
fr_strerror_printf("Failed to lock file %s: %s", filename, strerror(errno));
goto error;
Expand All @@ -282,11 +284,11 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app
filename, strerror(errno));
goto error;
}
}

if (rad_lockfd(ef->entries[i].fd, 0) < 0) {
fr_strerror_printf("Failed to lock file %s: %s", filename, strerror(errno));
goto error;
}
if (tries >= 4) {
fr_strerror_printf("Failed to lock file %s: too many tries", filename);
goto error;
}

/*
Expand Down

0 comments on commit 611a2f7

Please sign in to comment.