From: Alan T. DeKok Date: Wed, 17 Feb 2016 16:22:36 +0000 (-0500) Subject: Clean up old files only once a second X-Git-Tag: release_3_0_12~219 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca705121155a1928bd7293f80ce9f33fcfe82646;p=thirdparty%2Ffreeradius-server.git Clean up old files only once a second --- diff --git a/src/main/exfile.c b/src/main/exfile.c index e63a4268fcf..1684c2bf246 100644 --- a/src/main/exfile.c +++ b/src/main/exfile.c @@ -41,6 +41,7 @@ typedef struct exfile_entry_t { struct exfile_t { uint32_t max_entries; //!< How many file descriptors we keep track of. uint32_t max_idle; //!< Maximum idle time for a descriptor. + time_t last_cleaned; #ifdef HAVE_PTHREAD_H pthread_mutex_t mutex; @@ -151,18 +152,22 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app /* * Clean up old entries. */ - for (i = 0; i < ef->max_entries; i++) { - if (!ef->entries[i].filename) continue; - - if ((ef->entries[i].last_used + ef->max_idle) < now) { - /* - * This will block forever if a thread is - * doing something stupid. - */ - TALLOC_FREE(ef->entries[i].filename); - ef->entries[i].hash = 0; - close(ef->entries[i].fd); - ef->entries[i].fd = -1; + if (now > (ef->last_cleaned + 1)) { + ef->last_cleaned = now; + + for (i = 0; i < ef->max_entries; i++) { + if (!ef->entries[i].filename) continue; + + if ((ef->entries[i].last_used + ef->max_idle) < now) { + /* + * This will block forever if a thread is + * doing something stupid. + */ + TALLOC_FREE(ef->entries[i].filename); + ef->entries[i].hash = 0; + close(ef->entries[i].fd); + ef->entries[i].fd = -1; + } } }