From: Alan T. DeKok Date: Tue, 25 Jul 2017 13:35:01 +0000 (-0400) Subject: remove exfile_unlock() X-Git-Tag: release_3_0_16~204 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49ac73ef427650a542632f3630618b42cc9dfdfe;p=thirdparty%2Ffreeradius-server.git remove exfile_unlock() 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 --- diff --git a/src/include/exfile.h b/src/include/exfile.h index ccccfe97e68..c511100603a 100644 --- a/src/include/exfile.h +++ b/src/include/exfile.h @@ -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 } diff --git a/src/main/exfile.c b/src/main/exfile.c index 16fd15b81b7..c63c70ec8c5 100644 --- a/src/main/exfile.c +++ b/src/main/exfile.c @@ -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; -} diff --git a/src/modules/rlm_detail/rlm_detail.c b/src/modules/rlm_detail/rlm_detail.c index 801e6ada2b7..caa01749c06 100644 --- a/src/modules/rlm_detail/rlm_detail.c +++ b/src/modules/rlm_detail/rlm_detail.c @@ -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; @@ -412,11 +412,18 @@ skip_group: /* * 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; } @@ -426,7 +433,7 @@ skip_group: * Flush everything */ fclose(outfp); - exfile_unlock(inst->ef, outfd); /* do NOT close outfd */ + exfile_close(inst->ef, outfd); /* * And everything is fine.