]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Exfile allow immediate cleanup if idle_time is 0 developer/arr2036
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 29 Jan 2026 18:53:24 +0000 (10:53 -0800)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 29 Jan 2026 18:53:33 +0000 (10:53 -0800)
src/lib/server/exfile.c

index f0bb77f025e53a0cc0dcd0ce25a12f3fe946730f..1d3826b5ddb6bce9d37eb1ccb66d05e26bff8dc8 100644 (file)
@@ -32,6 +32,7 @@
 #include <freeradius-devel/util/misc.h>
 #include <freeradius-devel/util/perm.h>
 #include <freeradius-devel/util/syserror.h>
+#include <freeradius-devel/util/time.h>
 
 #include <fcntl.h>
 
@@ -63,6 +64,8 @@ typedef struct {
 struct exfile_s {
        uint32_t                max_entries;            //!< How many file descriptors we keep track of.
        fr_time_delta_t         max_idle;               //!< Maximum idle time for a descriptor.
+                                                       ///< If this is zero, the descriptor will be closed
+                                                       ///< immediately after it is unlocked.
        fr_time_t               last_cleaned;
        pthread_mutex_t         mutex;
        exfile_entry_t          *entries;
@@ -556,6 +559,17 @@ static int exfile_close_lock(exfile_t *ef, int fd)
 
                (void) lseek(ef->entries[i].fd, 0, SEEK_SET);
                (void) rad_unlockfd(ef->entries[i].fd, 0);
+
+               /*
+                *      If max idle is 0, then clean up the file immediately
+                *      this is mostly used for testing.
+                */
+               if (fr_time_delta_eq(ef->max_idle, fr_time_delta_from_sec(0))) {
+                       exfile_cleanup_entry(ef, &ef->entries[i]);
+                       pthread_mutex_unlock(&(ef->mutex));
+                       return 0;
+               }
+
                pthread_mutex_unlock(&(ef->mutex));
 
                exfile_trigger(ef, &ef->entries[i], EXFILE_TRIGGER_RELEASE);