&& worker->thread_num == 0
#endif
) {
- if(!dt_io_thread_start(dtenv->dtio)) {
+ if(!dt_io_thread_start(dtenv->dtio, comm_base_internal(
+ worker->base))) {
log_err("could not start dnstap io thread");
worker_delete(worker);
return 0;
wsvc_desetup_worker(worker);
#endif /* UB_ON_WINDOWS */
}
- comm_base_delete(worker->base);
#ifdef USE_DNSTAP
if(worker->daemon->cfg->dnstap
#ifndef THREADS_DISABLED
}
dt_deinit(&worker->dtenv);
#endif /* USE_DNSTAP */
+ comm_base_delete(worker->base);
ub_randfree(worker->rndstate);
alloc_clear(&worker->alloc);
regional_destroy(worker->env.scratch);
{
struct timeval tv;
int msec;
+ if(dtio->want_to_exit) return;
if(dtio->reconnect_is_added)
return; /* already done */
}
}
+#ifndef THREADS_DISABLED
/** setup the event base for the dnstap io thread */
static void dtio_setup_base(struct dt_io_thread* dtio, time_t* secs,
struct timeval* now)
fatal_exit("dnstap io: could not create event_base");
}
}
+#endif /* THREADS_DISABLED */
/** setup the cmd event for dnstap io */
static void dtio_setup_cmd(struct dt_io_thread* dtio)
dtio_reconnect_del(dtio);
ub_event_free(dtio->reconnect_timer);
dtio_cur_msg_free(dtio);
+#ifndef THREADS_DISABLED
ub_event_base_free(dtio->event_base);
+#endif
}
/** setup a start control message */
#endif /* HAVE_SYS_UN_H */
}
+#ifndef THREADS_DISABLED
/** the IO thread function for the DNSTAP IO */
static void* dnstap_io(void* arg)
{
dtio_desetup(dtio);
return NULL;
}
+#endif /* THREADS_DISABLED */
-int dt_io_thread_start(struct dt_io_thread* dtio)
+int dt_io_thread_start(struct dt_io_thread* dtio, void* event_base_nothr)
{
/* set up the thread, can fail */
#ifndef USE_WINSOCK
/* start the thread */
dtio->started = 1;
+#ifndef THREADS_DISABLED
ub_thread_create(&dtio->tid, dnstap_io, dtio);
+#else
+ dtio->event_base = event_base_nothr;
+ dtio_setup_cmd(dtio);
+ dtio_setup_reconnect(dtio);
+ dtio_open_output(dtio);
+ dtio_add_output_event_write(dtio);
+#endif
return 1;
}
void dt_io_thread_stop(struct dt_io_thread* dtio)
{
+#ifndef THREADS_DISABLED
uint8_t cmd = DTIO_COMMAND_STOP;
+#endif
if(!dtio) return;
if(!dtio->started) return;
verbose(VERB_ALGO, "dnstap io: send stop cmd");
+#ifndef THREADS_DISABLED
while(1) {
ssize_t r = write(dtio->commandpipe[1], &cmd, sizeof(cmd));
if(r == -1) {
break;
}
dtio->started = 0;
+#endif /* THREADS_DISABLED */
#ifndef USE_WINSOCK
close(dtio->commandpipe[1]);
_close(dtio->commandpipe[1]);
#endif
dtio->commandpipe[1] = -1;
+#ifndef THREADS_DISABLED
ub_thread_join(dtio->tid);
+#else
+ dtio->want_to_exit = 1;
+ dtio_desetup(dtio);
+#endif
}
/**
* Start the io thread
* @param dtio: the io thread.
+ * @param event_base_nothr: the event base to attach the events to, in case
+ * we are running without threads. With threads, this is ignored
+ * and a thread is started to process the dnstap log messages.
* @return false on failure.
*/
-int dt_io_thread_start(struct dt_io_thread* dtio);
+int dt_io_thread_start(struct dt_io_thread* dtio, void* event_base_nothr);
/**
* Stop the io thread