static void log_writer_io_flush_output(gpointer s) { LogWriter *self = (LogWriter *) s; main_loop_assert_main_thread(); log_writer_stop_watches(self); log_pipe_ref(&self->super); if ((self->options->options & LWO_THREADED)) { main_loop_io_worker_job_submit(&self->io_job); } else { /* Checking main_loop_io_worker_job_quit() helps to speed up the * reload process. If reload/shutdown is requested we shouldn't do * anything here, a final flush will be attempted in * log_writer_deinit(). * * Our current understanding is that it doesn't prevent race * conditions of any kind. */ if (!main_loop_io_worker_job_quit()) { log_writer_work_perform(s); log_writer_work_finished(s); } } }
static void log_reader_io_process_input(gpointer s) { LogReader *self = (LogReader *) s; log_reader_stop_watches(self); log_pipe_ref(&self->super.super); if ((self->options->flags & LR_THREADED)) { main_loop_io_worker_job_submit(&self->io_job); } else { /* Checking main_loop_io_worker_job_quit() helps to speed up the * reload process. If reload/shutdown is requested we shouldn't do * anything here, outstanding messages will be processed by the new * configuration. * * Our current understanding is that it doesn't prevent race * conditions of any kind. */ if (!main_loop_io_worker_job_quit()) { log_reader_work_perform(s); log_reader_work_finished(s); } } }
/* returns: notify_code (NC_XXXX) or 0 for success */ static gint log_reader_fetch_log(LogReader *self) { GSockAddr *sa; gint msg_count = 0; gboolean may_read = TRUE; if (self->waiting_for_preemption) may_read = FALSE; /* NOTE: this loop is here to decrease the load on the main loop, we try * to fetch a couple of messages in a single run (but only up to * fetch_limit). */ while (msg_count < self->options->fetch_limit && !main_loop_io_worker_job_quit()) { const guchar *msg; gsize msg_len; LogProtoStatus status; msg = NULL; sa = NULL; /* NOTE: may_read is used to implement multi-read checking. It * is initialized to TRUE to indicate that the protocol is * allowed to issue a read(). If multi-read is disallowed in the * protocol, it resets may_read to FALSE after the first read was issued. */ status = log_proto_fetch(self->proto, &msg, &msg_len, &sa, &may_read); switch (status) { case LPS_EOF: case LPS_ERROR: g_sockaddr_unref(sa); return status == LPS_ERROR ? NC_READ_ERROR : NC_CLOSE; case LPS_SUCCESS: break; default: g_assert_not_reached(); break; } if (!msg) { /* no more messages for now */ break; } if (msg_len > 0 || (self->options->flags & LR_EMPTY_LINES)) { msg_count++; if (!log_reader_handle_line(self, msg, msg_len, sa)) { /* window is full, don't generate further messages */ log_proto_queued(self->proto); g_sockaddr_unref(sa); break; } } log_proto_queued(self->proto); g_sockaddr_unref(sa); } if (self->options->flags & LR_PREEMPT) { if (log_proto_is_preemptable(self->proto)) { self->waiting_for_preemption = FALSE; log_pipe_notify(self->control, &self->super.super, NC_FILE_SKIP, self); } else { self->waiting_for_preemption = TRUE; } } if (msg_count == self->options->fetch_limit) self->immediate_check = TRUE; return 0; }