53 tv.tv_sec = next_interval;
66 time_t now = time(NULL);
70 int r =
event->fn(now, options);
71 int next_interval = 0;
73 if (!periodic_event_is_enabled(event)) {
81 log_err(
LD_BUG,
"Invalid return value for periodic event from %s.",
85 event->last_action_time = now;
100 struct timeval tv = { next_interval , 0 };
109 if (event->
ev && periodic_event_is_enabled(event)) {
120 log_err(
LD_BUG,
"Initial dispatch should only be done once.");
135 log_err(
LD_BUG,
"periodic_event_launch without periodic_event_connect");
139 if (periodic_event_is_enabled(event)) {
140 log_err(
LD_BUG,
"periodic_event_launch on an already enabled event");
160 mainloop_event_free(event->
ev);
161 event->last_action_time = 0;
172 if (periodic_event_is_enabled(event)) {
189 if (!periodic_event_is_enabled(event)) {
204 if (!periodic_event_is_enabled(event))
243 } SMARTLIST_FOREACH_END(item);
264 } SMARTLIST_FOREACH_END(item);
278 if (strcmp(
name, item->name) == 0)
280 } SMARTLIST_FOREACH_END(item);
300 int enable = !!(item->roles & roles);
304 (item->flags & PERIODIC_EVENT_FLAG_NEED_NET)) {
311 log_debug(
LD_GENERAL,
"Launching periodic event %s", item->name);
314 log_debug(
LD_GENERAL,
"Disabling periodic event %s", item->name);
315 if (item->flags & PERIODIC_EVENT_FLAG_RUN_ON_DISABLE) {
321 } SMARTLIST_FOREACH_END(item);
338 } SMARTLIST_FOREACH_END(item);
343 #define LONGEST_TIMER_PERIOD (30 * 86400)
360 tor_assert(next > TIME_MIN + LONGEST_TIMER_PERIOD);
362 if (next - LONGEST_TIMER_PERIOD > now)
363 return LONGEST_TIMER_PERIOD;
364 return (
int)(next - now);
void mainloop_event_cancel(mainloop_event_t *event)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *tv)
void mainloop_event_activate(mainloop_event_t *event)
Header for compat_libevent.c.
const or_options_t * get_options(void)
Header file for config.c.
void update_current_time(time_t now)
Header file for mainloop.c.
Master header file for Tor-specific functionality.
void periodic_event_disable(periodic_event_item_t *event)
static const int MAX_INTERVAL
void periodic_events_rescan_by_roles(int roles, bool net_disabled)
static void periodic_event_dispatch(mainloop_event_t *ev, void *data)
static void periodic_event_set_interval(periodic_event_item_t *event, time_t next_interval)
void periodic_event_schedule_and_disable(periodic_event_item_t *event)
void periodic_event_enable(periodic_event_item_t *event)
static smartlist_t * the_periodic_events
void periodic_events_connect_all(void)
void periodic_events_register(periodic_event_item_t *item)
void periodic_event_launch(periodic_event_item_t *event)
void periodic_event_connect(periodic_event_item_t *event)
int safe_timer_diff(time_t now, time_t next)
void periodic_events_disconnect_all(void)
void periodic_event_reschedule(periodic_event_item_t *event)
void periodic_events_reset_all(void)
static void periodic_event_disconnect(periodic_event_item_t *event)
periodic_event_item_t * periodic_events_find(const char *name)
smartlist_t * smartlist_new(void)
int smartlist_contains(const smartlist_t *sl, const void *element)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
struct mainloop_event_t * ev