static void poll_fd_events_stop_watches(PollEvents *s) { PollFdEvents *self = (PollFdEvents *) s; if (iv_fd_registered(&self->fd_watch)) iv_fd_unregister(&self->fd_watch); }
static gboolean afsocket_dd_connected(AFSocketDestDriver *self) { gchar buf1[256], buf2[256]; int error = 0; socklen_t errorlen = sizeof(error); LogTransport *transport; LogProtoClient *proto; main_loop_assert_main_thread(); if (iv_fd_registered(&self->connect_fd)) iv_fd_unregister(&self->connect_fd); if (self->transport_mapper->sock_type == SOCK_STREAM) { if (getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &error, &errorlen) == -1) { msg_error("getsockopt(SOL_SOCKET, SO_ERROR) failed for connecting socket", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, errno), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } if (error) { msg_error("Syslog connection failed", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, error), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } } msg_notice("Syslog connection established", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_str("local", g_sockaddr_format(self->bind_addr, buf1, sizeof(buf1), GSA_FULL)), NULL); transport = afsocket_dd_construct_transport(self, self->fd); if (!transport) goto error_reconnect; proto = log_proto_client_factory_construct(self->proto_factory, transport, &self->writer_options.proto_options.super); log_writer_reopen(self->writer, proto); return TRUE; error_reconnect: close(self->fd); self->fd = -1; afsocket_dd_start_reconnect_timer(self); return FALSE; }
static void log_reader_stop_watches(LogReader *self) { if (iv_fd_registered(&self->fd_watch)) iv_fd_unregister(&self->fd_watch); if (iv_timer_registered(&self->follow_timer)) iv_timer_unregister(&self->follow_timer); if (iv_task_registered(&self->restart_task)) iv_task_unregister(&self->restart_task); }
void control_server_unix_free(ControlServer *s) { ControlServerUnix *self = (ControlServerUnix *)s; if (iv_fd_registered(&self->control_listen)) { iv_fd_unregister(&self->control_listen); } if (self->control_socket != -1) { close(self->control_socket); } }
static void afsocket_dd_stop_watches(AFSocketDestDriver *self) { main_loop_assert_main_thread(); if (iv_fd_registered(&self->connect_fd)) { iv_fd_unregister(&self->connect_fd); /* need to close the fd in this case as it wasn't established yet */ msg_verbose("Closing connecting fd", evt_tag_int("fd", self->fd)); close(self->fd); } if (iv_timer_registered(&self->reconnect_timer)) iv_timer_unregister(&self->reconnect_timer); }
static void log_writer_stop_watches(LogWriter *self) { if (self->watches_running) { if (iv_timer_registered(&self->suspend_timer)) iv_timer_unregister(&self->suspend_timer); if (iv_fd_registered(&self->fd_watch)) iv_fd_unregister(&self->fd_watch); if (iv_task_registered(&self->immed_io_task)) iv_task_unregister(&self->immed_io_task); log_queue_reset_parallel_push(self->queue); self->watches_running = FALSE; } }
static void afsocket_sd_stop_watches(AFSocketSourceDriver *self) { if (iv_fd_registered (&self->listen_fd)) iv_fd_unregister(&self->listen_fd); }
static void log_reader_update_watches(LogReader *self) { gint fd; GIOCondition cond; gboolean free_to_send; main_loop_assert_main_thread(); self->suspended = FALSE; free_to_send = log_source_free_to_send(&self->super); if (!free_to_send || self->immediate_check || log_proto_prepare(self->proto, &fd, &cond)) { /* we disable all I/O related callbacks here because we either know * that we can continue (e.g. immediate_check == TRUE) or we know * that we can't continue even if data would be available (e.g. * free_to_send == FALSE) */ self->immediate_check = FALSE; if (iv_fd_registered(&self->fd_watch)) { iv_fd_set_handler_in(&self->fd_watch, NULL); iv_fd_set_handler_out(&self->fd_watch, NULL); /* we disable the error handler too, as it might be * triggered even when we don't want to read data * (e.g. log_source_free_to_send() is FALSE). * * And at least on Linux, it may happen that EPOLLERR is * set, while there's still data in the socket buffer. Thus * in reaction to an EPOLLERR, we could possibly send * further messages without validating the * log_source_free_to_send() would allow us to, potentially * overflowing our window (and causing a failed assertion in * log_source_queue(). */ iv_fd_set_handler_err(&self->fd_watch, NULL); } if (iv_timer_registered(&self->follow_timer)) iv_timer_unregister(&self->follow_timer); if (free_to_send) { /* we have data in our input buffer, we need to start working * on it immediately, without waiting for I/O events */ if (!iv_task_registered(&self->restart_task)) { iv_task_register(&self->restart_task); } } else { self->suspended = TRUE; } return; } if (iv_fd_registered(&self->fd_watch)) { /* this branch is executed when our fd is connected to a non-file * source (e.g. TCP, UDP socket). We set up I/O callbacks here. * files cannot be polled using epoll, as it causes an I/O error * (thus abort in ivykis). */ if (cond & G_IO_IN) iv_fd_set_handler_in(&self->fd_watch, log_reader_io_process_input); else iv_fd_set_handler_in(&self->fd_watch, NULL); if (cond & G_IO_OUT) iv_fd_set_handler_out(&self->fd_watch, log_reader_io_process_input); else iv_fd_set_handler_out(&self->fd_watch, NULL); if (cond & (G_IO_IN + G_IO_OUT)) iv_fd_set_handler_err(&self->fd_watch, log_reader_io_process_input); else iv_fd_set_handler_err(&self->fd_watch, NULL); } else { if (self->options->follow_freq > 0) { if (iv_timer_registered(&self->follow_timer)) iv_timer_unregister(&self->follow_timer); iv_validate_now(); self->follow_timer.expires = iv_now; timespec_add_msec(&self->follow_timer.expires, self->options->follow_freq); iv_timer_register(&self->follow_timer); } else { /* NOTE: we don't need to unregister the timer here as follow_freq * never changes during runtime, thus if ever it was registered that * also means that we go into the if branch above. */ } } }
static gboolean afsocket_dd_connected(AFSocketDestDriver *self) { gchar buf1[256], buf2[256]; int error = 0; socklen_t errorlen = sizeof(error); LogTransport *transport; LogProto *proto; guint32 transport_flags = 0; main_loop_assert_main_thread(); if (iv_fd_registered(&self->connect_fd)) iv_fd_unregister(&self->connect_fd); if (self->flags & AFSOCKET_STREAM) { transport_flags |= LTF_SHUTDOWN; if (getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &error, &errorlen) == -1) { msg_error("getsockopt(SOL_SOCKET, SO_ERROR) failed for connecting socket", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, errno), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } if (error) { msg_error("Syslog connection failed", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, error), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } } msg_notice("Syslog connection established", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_str("local", g_sockaddr_format(self->bind_addr, buf1, sizeof(buf1), GSA_FULL)), NULL); #if ENABLE_SSL if (self->tls_context) { TLSSession *tls_session; tls_session = tls_context_setup_session(self->tls_context); if (!tls_session) { goto error_reconnect; } tls_session_set_verify(tls_session, afsocket_dd_tls_verify_callback, self, NULL); transport = log_transport_tls_new(tls_session, self->fd, transport_flags); } else #endif transport = log_transport_plain_new(self->fd, transport_flags); if (self->flags & AFSOCKET_SYSLOG_PROTOCOL) { if (self->flags & AFSOCKET_STREAM) proto = log_proto_framed_client_new(transport); else proto = log_proto_text_client_new(transport); } else { proto = log_proto_text_client_new(transport); } log_writer_reopen(self->writer, proto); return TRUE; error_reconnect: close(self->fd); self->fd = -1; afsocket_dd_start_reconnect_timer(self); return FALSE; }