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_worker_job_quit()) { log_writer_work_perform(s); log_writer_work_finished(s); } } }
static gint _fetch_log(JournalReader *self) { gint msg_count = 0; gint result = 0; self->immediate_check = TRUE; while (msg_count < self->options->fetch_limit && !main_loop_worker_job_quit()) { gint rc = journald_next(self->journal); if (rc > 0) { Bookmark *bookmark = ack_tracker_request_bookmark(self->super.ack_tracker); _fill_bookmark(self, bookmark); msg_count++; if (!_handle_message(self)) { break; } } else { self->immediate_check = FALSE; /* rc == 0 means EOF */ if (rc < 0) { msg_error("Error occurred while getting next message from journal", evt_tag_errno("error", errno)); result = NC_READ_ERROR; } break; } } return result; }
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_worker_job_quit()) { log_reader_work_perform(s); log_reader_work_finished(s); } } }
static void _io_process_input(gpointer s) { JournalReader *self = (JournalReader *) s; _stop_watches(self); log_pipe_ref(&self->super.super); if ((self->options->flags & JR_THREADED)) { main_loop_io_worker_job_submit(&self->io_job); } else { if (!main_loop_worker_job_quit()) { _work_perform(s); _work_finished(s); } } }
/* returns: notify_code (NC_XXXX) or 0 for success */ static gint log_reader_fetch_log(LogReader *self) { gint msg_count = 0; gboolean may_read = TRUE; LogTransportAuxData aux; log_transport_aux_data_init(&aux); if (log_proto_server_handshake_in_progress(self->proto)) { return log_reader_process_handshake(self); } /* 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_worker_job_quit()) { Bookmark *bookmark; const guchar *msg; gsize msg_len; LogProtoStatus status; msg = 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. */ log_transport_aux_data_reinit(&aux); bookmark = ack_tracker_request_bookmark(self->super.ack_tracker); status = log_proto_server_fetch(self->proto, &msg, &msg_len, &may_read, &aux, bookmark); switch (status) { case LPS_EOF: g_sockaddr_unref(aux.peer_addr); return NC_CLOSE; case LPS_ERROR: g_sockaddr_unref(aux.peer_addr); return NC_READ_ERROR; 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++; ScratchBuffersMarker mark; scratch_buffers_mark(&mark); if (!log_reader_handle_line(self, msg, msg_len, &aux)) { scratch_buffers_reclaim_marked(mark); /* window is full, don't generate further messages */ break; } scratch_buffers_reclaim_marked(mark); } } log_transport_aux_data_destroy(&aux); if (msg_count == self->options->fetch_limit) self->immediate_check = TRUE; return 0; }