struct {
sd_event_source* sigterm;
sd_event_source* sigint;
+ sd_event_source* sighup;
sd_event_source* modules_init;
sd_event_source* flush;
} events;
STAILQ_HEAD(queue, collecty_queue_object) queue;
};
+static int collecty_daemon_flush(collecty_daemon* self) {
+ DEBUG(self->ctx, "Flushing the queue...\n");
+
+ // XXX TODO
+
+ return 0;
+}
+
static int collecty_daemon_modules_init(sd_event_source* source, void* data) {
collecty_daemon* daemon = data;
return sd_event_exit(sd_event_source_get_event(source), 0);
}
+static int collecty_daemon_SIGHUP(sd_event_source* source,
+ const struct signalfd_siginfo* si, void* data) {
+ collecty_daemon* self = data;
+
+ // Flush the queue
+ return collecty_daemon_flush(self);
+}
+
static int collecty_daemon_setup_loop(collecty_daemon* self) {
int r;
return r;
}
+ // Listen for SIGHUP
+ r = sd_event_add_signal(self->loop, &self->events.sighup,
+ SIGHUP|SD_EVENT_SIGNAL_PROCMASK, collecty_daemon_SIGHUP, self);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not register handling SIGHUP: %s\n", strerror(-r));
+ return r;
+ }
+
// Initialize all modules when the loop starts
r = sd_event_add_defer(self->loop, &self->events.modules_init,
collecty_daemon_modules_init, self);
free(o);
}
-static int collecty_daemon_flush(sd_event_source* source, uint64_t usec, void* data) {
+static int collecty_daemon_flush_timer(sd_event_source* source, uint64_t usec, void* data) {
collecty_daemon* self = data;
int r;
- DEBUG(self->ctx, "Flushing the queue...\n");
-
- // TODO
-
// Call again soon...
r = sd_event_source_set_time(source, usec + FLUSH_QUEUE_INTERVAL);
if (r < 0)
if (r < 0)
return r;
- return 0;
+ // Flush the queue
+ return collecty_daemon_flush(self);
}
static int collecty_daemon_setup_queue(collecty_daemon* self) {
// Create a timer which regularly flushes the queue
r = sd_event_add_time_relative(self->loop, &self->events.flush,
- CLOCK_MONOTONIC, FLUSH_QUEUE_INTERVAL, 0, collecty_daemon_flush, self);
+ CLOCK_MONOTONIC, FLUSH_QUEUE_INTERVAL, 0, collecty_daemon_flush_timer, self);
if (r < 0) {
ERROR(self->ctx, "Failed to set up the flush timer: %s\n", strerror(-r));
return r;
sd_event_source_unref(self->events.sigterm);
if (self->events.sigint)
sd_event_source_unref(self->events.sigint);
+ if (self->events.sighup)
+ sd_event_source_unref(self->events.sighup);
if (self->ctx)
collecty_ctx_unref(self->ctx);
if (self->loop)