The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
exfile.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 144a532f67131130c1282bf05934108f89d18bab $
20 *
21 * @file lib/server/exfile.h
22 * @brief API for managing concurrent file access.
23 *
24 * @copyright 2014 The FreeRADIUS server project
25 */
26RCSIDH(exfile_h, "$Id: 144a532f67131130c1282bf05934108f89d18bab $")
27
28#include <freeradius-devel/server/request.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33/*
34 * Multiple threads logging to one or more files.
35 */
36typedef struct exfile_s exfile_t;
37
38exfile_t *exfile_init(TALLOC_CTX *ctx, uint32_t entries, fr_time_delta_t idle, bool locking);
39
42
43CC_ACQUIRE_HANDLE("exfile_fd")
44int exfile_open(exfile_t *lf, char const *filename, mode_t permissions, int flags, off_t *offset);
45
46int exfile_close(exfile_t *lf, CC_RELEASE_HANDLE("exfile_fd") int fd);
47
48#ifdef __COVERITY__
49void __coverity_exclusive_lock_acquire__(void *);
50void __coverity_exclusive_lock_release__(void *);
51#endif
52
53#ifndef _EXFILE_PRIVATE
54# ifdef __COVERITY__
55/*
56 * A successful exfile_open() returns holding a lock, which the
57 * caller releases with exfile_close(). Coverity's summary of
58 * exfile_open() loses the link between the lock and the return
59 * value, and reports the error path of every caller as a missing
60 * unlock.
61 *
62 * These macros make the contract visible at the call site, where
63 * Coverity can match the lock to the check of the return value.
64 * The lock is identified by ef, because exfile_t is opaque here.
65 * exfile.c tells Coverity that exfile_open() and exfile_close()
66 * leave ef->mutex unchanged.
67 */
68# define exfile_open(_ef, ...) ({ \
69 int _fd = (exfile_open)(_ef, __VA_ARGS__); \
70 if (_fd >= 0) __coverity_exclusive_lock_acquire__(_ef); \
71 _fd; \
72})
73
74# define exfile_close(_ef, _fd) ({ \
75 __coverity_exclusive_lock_release__(_ef); \
76 (exfile_close)(_ef, _fd); \
77})
78# endif
79#endif
80
81#ifdef __cplusplus
82}
83#endif
#define CC_RELEASE_HANDLE(_tag)
Definition build.h:520
#define RCSIDH(h, id)
Definition build.h:604
#define CC_ACQUIRE_HANDLE(_tag)
Definition build.h:518
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
bool locking
Definition exfile.c:72
char const * trigger_prefix
Trigger path in the global trigger section.
Definition exfile.c:74
exfile_entry_t * entries
Definition exfile.c:71
fr_pair_list_t trigger_args
Arguments to pass to trigger.
Definition exfile.c:75
int exfile_close(exfile_t *lf, CC_RELEASE_HANDLE("exfile_fd") int fd)
int exfile_open(exfile_t *lf, char const *filename, mode_t permissions, int flags, off_t *offset)
Open a new log file, or maybe an existing one.
Definition exfile.c:547
exfile_t * exfile_init(TALLOC_CTX *ctx, uint32_t entries, fr_time_delta_t idle, bool locking)
Initialize a way for multiple threads to log to one or more files.
Definition exfile.c:171
void exfile_enable_triggers(exfile_t *ef, CONF_SECTION *cs, char const *trigger_prefix, fr_pair_list_t *trigger_args)
Enable triggers for an exfiles handle.
Definition exfile.c:219
unsigned int uint32_t
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80