]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
remove exfile_unlock()
authorAlan T. DeKok <aland@freeradius.org>
Tue, 25 Jul 2017 13:35:01 +0000 (09:35 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 25 Jul 2017 14:04:40 +0000 (10:04 -0400)
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

src/include/exfile.h
src/main/exfile.c
src/modules/rlm_detail/rlm_detail.c

index ccccfe97e689a44bc5dfd0044454c025f3d55431..c511100603a3e699dccc4f7e9f648e153e87ce7b 100644 (file)
@@ -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
 }
index 16fd15b81b7c2e51f709b1e12eecdd2fd00ceb21..c63c70ec8c5d96648d900102705dffd8b99b5b38 100644 (file)
@@ -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;
-}
index 801e6ada2b7143fee4c647eb732a686d01c72c36..caa01749c06faacc345ab021d36eaabe577e5be7 100644 (file)
@@ -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.