28 RCSID(
"$Id: 6d2e28c463485709e1f215e66c6ab12f65b96bd7 $")
30 #include <freeradius-devel/server/cf_parse.h>
31 #include <freeradius-devel/server/main_loop.h>
32 #include <freeradius-devel/util/debug.h>
33 #include <freeradius-devel/server/state.h>
34 #include <freeradius-devel/server/trigger.h>
35 #include <freeradius-devel/server/util.h>
37 #include <freeradius-devel/util/misc.h>
38 #include <freeradius-devel/util/syserror.h>
43 #ifdef HAVE_SYS_WAIT_H
44 # include <sys/wait.h>
51 #ifdef HAVE_SYSTEMD_WATCHDOG
52 #include <systemd/sd-daemon.h>
64 DEBUG(
"Emitting systemd watchdog notification");
66 sd_notify(0,
"WATCHDOG=1");
70 sd_watchdog_event, ctx) < 0) {
71 ERROR(
"Failed to insert watchdog event");
91 for (i = 0; i < rcode; i++) {
110 INFO(
"Signalled to exit");
113 INFO(
"Signalled to terminate");
129 INFO(
"Ignoring HUP (less than 5s since last one)");
133 INFO(
"Received HUP signal");
152 if (rcode <= 0)
return;
170 #ifdef HAVE_SYSTEMD_WATCHDOG
171 void main_loop_set_sd_watchdog_interval(
void)
173 uint64_t interval_usec;
175 if (sd_watchdog_enabled(0, &interval_usec) > 0) {
185 INFO(
"systemd watchdog is disabled");
199 #ifdef HAVE_SYSTEMD_WATCHDOG
200 bool under_systemd = (getenv(
"NOTIFY_SOCKET") != NULL);
205 #ifdef HAVE_SYSTEMD_WATCHDOG
209 if (under_systemd) sd_notify(0,
"READY=1");
218 #ifdef HAVE_SYSTEMD_WATCHDOG
221 INFO(
"Informing systemd we're stopping");
222 sd_notify(0,
"STOPPING=1");
272 if ((fcntl(
self_pipe[0], F_SETFL, O_NONBLOCK) < 0) ||
277 if ((fcntl(
self_pipe[1], F_SETFL, O_NONBLOCK) < 0) ||
289 PERROR(
"Failed creating self-signal pipe handler");
static int const char char buffer[256]
#define fr_exit(_x)
Exit, producing a log message in debug builds.
#define FR_FAULT_LOG(_fmt,...)
#define fr_event_fd_insert(...)
@ FR_EVENT_FILTER_IO
Combined filter for read/write functions/.
#define fr_event_timer_in(...)
unlang_interpret_t * unlang_interpret_get_thread_default(void)
Get the default interpreter for this thread.
fr_event_list_t * fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_cb_t status, void *status_uctx)
Initialise a new event list.
int fr_event_timer_delete(fr_event_timer_t const **ev_p)
Delete a timer event from the event list.
void fr_event_loop_exit(fr_event_list_t *el, int code)
Signal an event loop exit with the specified code.
int fr_event_fd_delete(fr_event_list_t *el, int fd, fr_event_filter_t filter)
Remove a file descriptor from the event loop.
int fr_event_loop(fr_event_list_t *el)
Run an event loop.
Stores all information relating to an event list.
int main_loop_start(void)
static void main_loop_signal_process(int flag)
static fr_event_list_t * event_list
static int _loop_status(UNUSED fr_time_t now, fr_time_delta_t wake, UNUSED void *ctx)
fr_event_list_t * main_loop_event_list(void)
Return the main loop event list.
void main_loop_signal_raise(int flag)
static void main_loop_signal_recv(UNUSED fr_event_list_t *xel, UNUSED int fd, UNUSED int flags, UNUSED void *ctx)
I/O handler listening on the signal pipe.
int main_loop_init(void)
Initialise the main event loop, setting up signal handlers.
void main_loop_free(void)
@ RADIUS_SIGNAL_SELF_EXIT
@ RADIUS_SIGNAL_SELF_TERM
Signals that can be sent to a request.
#define fr_time()
Allow us to arbitrarily manipulate time.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
#define fr_time_delta_lt(_a, _b)
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
#define fr_time_delta_wrap(_time)
#define fr_time_wrap(_time)
#define fr_time_delta_ispos(_a)
#define fr_time_sub(_a, _b)
Subtract one time from another.
A time delta, a difference in time measured in nanoseconds.
int trigger_exec(unlang_interpret_t *intp, CONF_SECTION const *cs, char const *name, bool rate_limit, fr_pair_list_t *args)
Execute a trigger - call an executable to process an event.
#define fr_box_time_delta(_val)