Skip to content

Commit

Permalink
minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Feb 18, 2016
1 parent a7ca641 commit 95c2fa8
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/main/exfile.c
Expand Up @@ -136,13 +136,16 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app
*/
for (i = 0; i < ef->max_entries; i++) {
if (!ef->entries[i].filename) continue;

if ((ef->entries[i].last_used + ef->max_idle) < now) {
/*
* This will block forever if a thread is
* doing something stupid.
*/
TALLOC_FREE(ef->entries[i].filename);
ef->entries[i].hash = 0;
close(ef->entries[i].fd);
ef->entries[i].fd = -1;
}
}

Expand All @@ -152,23 +155,17 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app
for (i = 0; i < ef->max_entries; i++) {
if (!ef->entries[i].filename) continue;

if (ef->entries[i].hash == hash) {
/*
* Same hash but different filename. Give up.
*/
if (strcmp(ef->entries[i].filename, filename) != 0) {
pthread_mutex_unlock(&ef->mutex);
return -1;
}
/*
* Someone else failed to create the entry.
*/
if (!ef->entries[i].filename) {
pthread_mutex_unlock(&ef->mutex);
return -1;
}
goto do_return;
if (ef->entries[i].hash != hash) continue;

/*
* Same hash but different filename. Give up.
*/
if (strcmp(ef->entries[i].filename, filename) != 0) {
pthread_mutex_unlock(&ef->mutex);
return -1;
}

goto do_return;
}

/*
Expand Down

0 comments on commit 95c2fa8

Please sign in to comment.