Skip to content

Commit

Permalink
remove exfile_unlock()
Browse files Browse the repository at this point in the history
It was only used in the detail file, when the detail file
called fdopen().  The exfile API called dup() just so that the
detail module could call fclose() on the fdopen'd FILE pointer,
and not have the underlying FD close.

It's better to just have the detail module dup() the FD itself,
and leave the main FD unchanged
  • Loading branch information
alandekok committed Jul 25, 2017
1 parent 57870c4 commit 49ac73e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/include/exfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ typedef struct exfile_t exfile_t;
exfile_t *exfile_init(TALLOC_CTX *ctx, uint32_t entries, uint32_t idle, bool locking);
int exfile_open(exfile_t *lf, char const *filename, mode_t permissions, bool append);
int exfile_close(exfile_t *lf, int fd);
int exfile_unlock(exfile_t *lf, int fd);

#ifdef __cplusplus
}
Expand Down
19 changes: 0 additions & 19 deletions src/main/exfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,3 @@ int exfile_close(exfile_t *ef, int fd)
fr_strerror_printf("Attempt to unlock file which is not tracked");
return -1;
}

int exfile_unlock(exfile_t *ef, int fd)
{
uint32_t i;

for (i = 0; i < ef->max_entries; i++) {
if (!ef->entries[i].filename) continue;

if (ef->entries[i].fd == fd) {
PTHREAD_MUTEX_UNLOCK(&(ef->mutex));
return 0;
}
}

PTHREAD_MUTEX_UNLOCK(&(ef->mutex));

fr_strerror_printf("Attempt to unlock file which does not exist");
return -1;
}
15 changes: 11 additions & 4 deletions src/modules/rlm_detail/rlm_detail.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static int detail_write(FILE *out, rlm_detail_t *inst, REQUEST *request, RADIUS_
*/
static rlm_rcode_t CC_HINT(nonnull) detail_do(void *instance, REQUEST *request, RADIUS_PACKET *packet, bool compat)
{
int outfd;
int outfd, dupfd;
char buffer[DIRLEN];

FILE *outfp;
Expand Down Expand Up @@ -412,11 +412,18 @@ static rlm_rcode_t CC_HINT(nonnull) detail_do(void *instance, REQUEST *request,
/*
* Open the output fp for buffering.
*/
if ((outfp = fdopen(outfd, "a")) == NULL) {
outfp = NULL;
dupfd = dup(outfd);
if (dupfd < 0) {
RERROR("Failed to dup() file descriptor for detail file");
goto fail;
}

if ((outfp = fdopen(dupfd, "a")) == NULL) {
RERROR("Couldn't open file %s: %s", buffer, fr_syserror(errno));
fail:
if (outfp) fclose(outfp);
exfile_unlock(inst->ef, outfd);
exfile_close(inst->ef, outfd);
return RLM_MODULE_FAIL;
}

Expand All @@ -426,7 +433,7 @@ static rlm_rcode_t CC_HINT(nonnull) detail_do(void *instance, REQUEST *request,
* Flush everything
*/
fclose(outfp);
exfile_unlock(inst->ef, outfd); /* do NOT close outfd */
exfile_close(inst->ef, outfd);

/*
* And everything is fine.
Expand Down

0 comments on commit 49ac73e

Please sign in to comment.