static void _get_dir_once(void) { relocated_prefix = (_prelude_prefix) ? _prelude_prefix : relocate(INSTALLPREFIX); relative_spool_dir = get_relpath(PRELUDE_SPOOL_DIR); relative_profile_dir = get_relpath(PRELUDE_PROFILE_DIR); relative_config_default_dir = get_relpath(PRELUDE_CONFIG_DEFAULT_DIR); prelude_log_debug(2, "install prefix=%s", INSTALLPREFIX); prelude_log_debug(2, "relocated prefix=%s\n", relocated_prefix); prelude_log_debug(2, "relative spool=%s\n", relative_spool_dir ? relative_spool_dir : PRELUDE_SPOOL_DIR); prelude_log_debug(2, "relative config=%s\n", relative_config_default_dir ? relative_config_default_dir : PRELUDE_CONFIG_DEFAULT_DIR); prelude_log_debug(2, "relative profile=%s\n", relative_profile_dir ? relative_profile_dir : PRELUDE_PROFILE_DIR); }
/** * lml_dispatch_log: * @list: List of regex. * @str: The log. * @from: Where does this log come from. * * This function is to be called by module reading log devices. * It will take appropriate action. */ void lml_dispatch_log(lml_log_source_t *ls, const char *str, size_t size) { int ret; char *out; struct regex_data rdata; lml_log_entry_t *log_entry; ret = lml_log_source_preprocess_input(ls, str, size, &out, &size); if ( ret < 0 ) return; prelude_log_debug(3, "[LOG] %s\n", out); log_entry = lml_log_entry_new(); if ( ! log_entry ) return; lml_log_entry_set_log(log_entry, ls, out, size); rdata.log_source = ls; rdata.log_entry = log_entry; regex_exec(lml_log_source_get_regex_list(ls), ®ex_match_cb, &rdata, lml_log_entry_get_message(log_entry), lml_log_entry_get_message_len(log_entry)); lml_log_entry_destroy(log_entry); config.line_processed++; }
int main(int argc, char **argv) { int ret; ev_timer evt; struct timeval end; struct sigaction action; /* * Initialize libev. */ ev_default_loop(EVFLAG_AUTO); /* * make sure we ignore sighup until acceptable. */ #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) action.sa_flags = 0; action.sa_handler = SIG_IGN; sigemptyset(&action.sa_mask); sigaction(SIGHUP, &action, NULL); #endif memset(&start, 0, sizeof(start)); memset(&end, 0, sizeof(end)); prelude_init(&argc, argv); global_argv = argv; PRELUDE_PLUGIN_SET_PRELOADED_SYMBOLS(); ret = prelude_option_new_root(&lml_root_optlist); if ( ret < 0 ) return ret; ret = log_plugins_init(LOG_PLUGIN_DIR, lml_root_optlist); if (ret < 0) return ret; prelude_log_debug(1, "Initialized %d logs plugins.\n", ret); ret = lml_options_init(lml_root_optlist, argc, argv); if ( ret < 0 ) exit(1); /* * setup signal handling */ action.sa_flags = 0; sigemptyset(&action.sa_mask); action.sa_handler = sig_handler; #ifdef SA_INTERRUPT action.sa_flags |= SA_INTERRUPT; #endif sigaction(SIGTERM, &action, NULL); sigaction(SIGINT, &action, NULL); sigaction(SIGABRT, &action, NULL); #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) sigaction(SIGUSR1, &action, NULL); sigaction(SIGQUIT, &action, NULL); sigaction(SIGHUP, &action, NULL); #endif ret = file_server_start_monitoring(); if ( ret < 0 && ! config.udp_nserver ) { prelude_log(PRELUDE_LOG_WARN, "No file or UDP server available for monitoring: terminating.\n"); return -1; } if ( config.daemon_mode ) { prelude_daemonize(config.pidfile); if ( config.pidfile ) free(config.pidfile); ev_default_fork(); } ev_timer_init(&evt, libev_timer_cb, 1, 1); ev_timer_start(&evt); /* * Whether we are using batch-mode or file notification, we need * to process the currently un-processed entry. */ gettimeofday(&start, NULL); do { ret = file_server_read_once(); prelude_timer_wake_up(); } while ( ret > 0 ); /* * if either FAM or UDP server is enabled, we use polling to know * if there are data available for reading. if batch_mode is set, * then we revert to reading every data at once. */ if ( ! config.batch_mode ) wait_for_event(); else { gettimeofday(&end, NULL); /* * only call prelude_client_destroy in case we are running in batch * mode, causing an heartbeat to be sent to notice of a normal exit. */ if ( ! config.dry_run ) prelude_client_destroy(config.lml_client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS); print_stats("", &end); } prelude_deinit(); return 0; }