static gboolean log_db_parser_deinit(LogPipe *s) { LogDBParser *self = (LogDBParser *) s; GlobalConfig *cfg = log_pipe_get_config(s); if (iv_timer_registered(&self->tick)) { iv_timer_unregister(&self->tick); } cfg_persist_config_add(cfg, log_db_parser_format_persist_name(self), self->db, (GDestroyNotify) pattern_db_free, FALSE); self->db = NULL; return TRUE; }
static gboolean log_db_parser_init(LogParser *s, GlobalConfig *cfg) { LogDBParser *self = (LogDBParser *) s; if (self->initialized) { return TRUE; } self->initialized = TRUE; self->db = cfg_persist_config_fetch(cfg, log_db_parser_format_persist_name(self)); if (self->db) { struct stat st; if (stat(self->db_file, &st) < 0) { msg_error("Error stating pattern database file, no automatic reload will be performed", evt_tag_str("error", g_strerror(errno)), NULL); } else { self->db_file_inode = st.st_ino; self->db_file_mtime = st.st_mtime; } } else { self->db = pattern_db_new(); log_db_parser_reload_database(self); } if (self->db) pattern_db_set_emit_func(self->db, log_db_parser_emit, self); #if GLIB_MAJOR_VERSION > 2 && GLIB_MINOR_VERSION > 13 self->timer_tick_id = g_timeout_add_seconds(1, log_db_parser_timer_tick, self); #else self->timer_tick_id = g_timeout_add(1000, log_db_parser_timer_tick, self); #endif return self->db != NULL; }
static gboolean log_db_parser_init(LogPipe *s) { LogDBParser *self = (LogDBParser *) s; GlobalConfig *cfg = log_pipe_get_config(s); self->db = cfg_persist_config_fetch(cfg, log_db_parser_format_persist_name(self)); if (self->db) { struct stat st; if (stat(self->db_file, &st) < 0) { msg_error("Error stating pattern database file, no automatic reload will be performed", evt_tag_str("error", g_strerror(errno)), NULL); } else if (self->db_file_inode != st.st_ino || self->db_file_mtime != st.st_mtime) { self->db = pattern_db_new(); log_db_parser_reload_database(self); self->db_file_inode = st.st_ino; self->db_file_mtime = st.st_mtime; } } else { self->db = pattern_db_new(); log_db_parser_reload_database(self); } if (self->db) pattern_db_set_emit_func(self->db, log_db_parser_emit, self); iv_validate_now(); IV_TIMER_INIT(&self->tick); self->tick.cookie = self; self->tick.handler = log_db_parser_timer_tick; self->tick.expires = iv_now; self->tick.expires.tv_sec++; self->tick.expires.tv_nsec = 0; iv_timer_register(&self->tick); return self->db != NULL; }
static void log_db_parser_deinit(LogParser *s, GlobalConfig *cfg) { LogDBParser *self = (LogDBParser *) s; if (self->initialized) { if (self->timer_tick_id) { GSource *source = g_main_context_find_source_by_id(NULL, self->timer_tick_id); g_source_destroy(source); self->timer_tick_id = 0; } cfg_persist_config_add(cfg, log_db_parser_format_persist_name(self), self->db, (GDestroyNotify) pattern_db_free, FALSE); self->db = NULL; self->initialized = FALSE; } }