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
}
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;
-}
*/
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;
/*
* 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;
}
* Flush everything
*/
fclose(outfp);
- exfile_unlock(inst->ef, outfd); /* do NOT close outfd */
+ exfile_close(inst->ef, outfd);
/*
* And everything is fine.