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;
/*
* 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;
+ }
}
}