static void log_writer_start_watches(LogWriter *self) { gint fd; GIOCondition cond; if (self->watches_running) return; log_proto_client_prepare(self->proto, &fd, &cond); self->fd_watch.fd = fd; if (self->pollable_state < 0) { if (is_file_regular(fd)) self->pollable_state = 0; else self->pollable_state = !iv_fd_register_try(&self->fd_watch); } else if (self->pollable_state > 0) iv_fd_register(&self->fd_watch); log_writer_update_watches(self); self->watches_running = TRUE; }
static void control_connection_start_watches(ControlConnection *self, gint sock) { IV_FD_INIT(&self->control_io); self->control_io.cookie = self; self->control_io.fd = sock; iv_fd_register_try(&self->control_io); control_connection_update_watches(self); }
static gboolean _is_fd_pollable(gint fd) { struct iv_fd check_fd; gboolean pollable; IV_FD_INIT(&check_fd); check_fd.fd = fd; check_fd.cookie = NULL; pollable = (iv_fd_register_try(&check_fd) == 0); if (pollable) iv_fd_unregister(&check_fd); return pollable; }
/* NOTE: the return value is only used during initialization, and it is not * expected that it'd change once it returns success */ static gboolean log_reader_start_watches(LogReader *self) { gint fd; GIOCondition cond; log_proto_prepare(self->proto, &fd, &cond); if (self->options->follow_freq > 0) { /* follow freq specified (only the file source does that, go into timed polling */ /* NOTE: the fd may not be set here, as it may not have been opened yet */ iv_timer_register(&self->follow_timer); } else if (fd < 0) { msg_error("In order to poll non-yet-existing files, follow_freq() must be set", NULL); return FALSE; } else { /* we have an FD, it is possible to poll it, register it */ self->fd_watch.fd = fd; if (self->pollable_state < 0) { if (iv_fd_register_try(&self->fd_watch) == 0) self->pollable_state = 1; else self->pollable_state = 0; } else if (self->pollable_state > 0) { iv_fd_register(&self->fd_watch); } else { msg_error("Unable to determine how to monitor this fd, follow_freq() not set and it is not possible to poll it with the current ivykis polling method, try changing IV_EXCLUDE_POLL_METHOD environment variable", evt_tag_int("fd", fd), NULL); return FALSE; } } log_reader_update_watches(self); return TRUE; }