26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/exfile.h>
46 pthread_mutex_t mutex;
54 #define PTHREAD_MUTEX_LOCK pthread_mutex_lock
55 #define PTHREAD_MUTEX_UNLOCK pthread_mutex_unlock
61 #define PTHREAD_MUTEX_LOCK(_x)
62 #define PTHREAD_MUTEX_UNLOCK(_x)
65 #define MAX_TRY_LOCK 4
105 if (!ef)
return NULL;
113 #ifdef HAVE_PTHREAD_H
146 time_t now = time(NULL);
149 if (!ef || !filename)
return -1;
216 ef->
entries[i].
fd = open(filename, O_RDWR | O_APPEND | O_CREAT, permissions);
225 dir = talloc_strdup(ef, filename);
226 if (!dir)
goto error;
227 p = strrchr(dir, FR_DIR_SEP);
238 dirperm = permissions;
239 if ((dirperm & 0600) != 0) dirperm |= 0100;
240 if ((dirperm & 0060) != 0) dirperm |= 0010;
241 if ((dirperm & 0006) != 0) dirperm |= 0001;
243 if (
rad_mkdir(dir, dirperm, -1, -1) < 0) {
245 dir, strerror(errno));
251 ef->
entries[i].
fd = open(filename, O_WRONLY | O_CREAT, permissions);
254 filename, strerror(errno));
263 if (lseek(ef->
entries[i].
fd, 0, SEEK_SET) < 0) {
286 if (errno != EAGAIN) {
292 ef->
entries[i].
fd = open(filename, O_WRONLY | O_CREAT, permissions);
295 filename, strerror(errno));
300 if (tries >= MAX_TRY_LOCK) {
315 if (st.st_nlink == 0) {
317 ef->
entries[i].
fd = open(filename, O_WRONLY | O_CREAT, permissions);
320 filename, strerror(errno));
329 if (append) lseek(ef->
entries[i].
fd, 0, SEEK_END);
#define pthread_mutex_init(_x, _y)
uint32_t max_idle
Maximum idle time for a descriptor.
#define PTHREAD_MUTEX_LOCK(_x)
exfile_t * exfile_init(TALLOC_CTX *ctx, uint32_t max_entries, uint32_t max_idle, bool locking)
Initialize a way for multiple threads to log to one or more files.
uint32_t hash
Hash for cheap comparison.
int rad_mkdir(char *directory, mode_t mode, uid_t uid, gid_t gid)
Create possibly many directories.
uint32_t fr_hash_string(char const *p)
static unsigned int hash(char const *username, unsigned int tablesize)
static int _exfile_free(exfile_t *ef)
int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool append)
Open a new log file, or maybe an existing one.
#define PTHREAD_MUTEX_UNLOCK(_x)
int fd
File descriptor associated with an entry.
int exfile_close(exfile_t *ef, int fd)
Close the log file.
int exfile_unlock(exfile_t *ef, int fd)
#define MAX_TRY_LOCK
How many times we attempt to acquire a lock.
int rad_unlockfd(int fd, int lock_len)
uint32_t max_entries
How many file descriptors we keep track of.
void fr_strerror_printf(char const *,...) CC_HINT(format(printf
struct exfile_entry_t exfile_entry_t
time_t last_used
Last time the entry was used.
int rad_lockfd_nonblock(int fd, int lock_len)
#define pthread_mutex_destroy(_x)