/* the main */ int main(void){ /* the base directory to be used/created */ const char *base_dir = "data"; /* the default test db connection string */ char DEFAULT_TEST_DB_CONN_STR[] = "@localhost"; char *test_db = DEFAULT_TEST_DB_CONN_STR; /* create the target directory where the dump(s) will be stored */ if( 0 > mkdir_recursive(base_dir)) { LOGGER_ERROR("Failed to create target directory: [%s]", base_dir); exit(EXIT_FAILURE); } LOGGER_INFO("target directory: [%s]", base_dir); /* the mysql_login_info struct will be used to access the database */ struct mysql_login_info login_db_test; /* parse the test_db connection string in case of any errors */ /* not necessarily used in this example unless you use a database connection string other than '@localhost' */ if (0 > ribs_mysql_parse_db_conn_str(test_db, &login_db_test)) { LOGGER_ERROR("failed to parse DB connection string: [%s]", test_db); exit(EXIT_FAILURE); } login_db_test.db = DB_TEST; /* initialize the event loop */ if( 0 > epoll_worker_init()) { LOGGER_ERROR("epoll_worker_init failed"); exit(EXIT_FAILURE); } /* initialize the client pool */ http_client_pool_init(&client_pool, 10, 10); /* initialize the query buffer used in dump_test_data() */ struct vmbuf query = VMBUF_INITIALIZER; vmbuf_init(&query, 65536); /* dump the test db data table into its target directory */ if( 0 > dump_test_data(base_dir, login_db_test, &query)) { LOGGER_ERROR("Faied to dump data from test db"); exit(EXIT_FAILURE); } /* return when successful */ LOGGER_INFO("completed successfully"); exit(EXIT_SUCCESS); return 0; }
int main(int argc, char *argv[]) { size_t num_files = 0; char **files = (char **) calloc(MAX_FILE_SUPPORT, MAX_FILE_SUPPORT * sizeof(char *)); if (0 > init_log_config(&logconf, argc, argv)) { exit(EXIT_FAILURE); } if (!SSTRISEMPTY(logconf.target) && !SSTRISEMPTY(logconf.interface)) { LOGGER_ERROR("%s", "cannot write to target and interface together. please choose one"); exit(EXIT_FAILURE); } char *f = logconf.watch_files; if (!SSTRISEMPTY(f)) { while (f != NULL) { char *fprime = strsep(&f, ","); if (fprime != NULL) { files[num_files] = strdup(fprime); ++num_files; } } } else { LOGGER_ERROR("%s", "no files..no watch!"); exit(EXIT_FAILURE); } if (0 > epoll_worker_init()) { LOGGER_ERROR("%s", "epoll_worker_init"); exit(EXIT_FAILURE); } ribs_timer(60*1000, dump_stats); tab_event_fds = thashtable_create(); delta_push = thashtable_create(); vmbuf_init(&write_buffer, 4096); vmbuf_init(&mb, 4096); if (SSTRISEMPTY(logconf.interface) && !SSTRISEMPTY(logconf.target)) { file_writer_make(&fw); if (0 > file_writer_init(&fw, logconf.target)) { LOGGER_ERROR("%s", "flie_writer"); exit(EXIT_FAILURE); } write_to_file = true; } else if (!SSTRISEMPTY(logconf.interface)) { if (0 > http_client_pool_init(&client_pool, 20, 20)) { LOGGER_ERROR("http_client_pool_init"); exit(EXIT_FAILURE); } memset(&eserv, 0, sizeof(eserv)); vmbuf_reset(&write_buffer); _replace(logconf.interface, &write_buffer, "http://www.", ""); _replace(logconf.interface, &write_buffer, "http://", ""); char *interface = vmbuf_data(&write_buffer); eserv.context = ribs_strdup(strstr(interface, "/")); char *ln = strchr(interface, '/'); ln = ribs_malloc_sprintf("%.*s", ((int)strlen(interface) - (int)strlen(ln)), interface); if (0 > parse_host_to_inet(ln, eserv.hostname, &eserv.server, &eserv.port)) { LOGGER_ERROR("%s", "server details invalid. cannot parse server"); exit(EXIT_FAILURE); } } else { LOGGER_ERROR("%s", "no target defined. please use target or interface"); exit(EXIT_FAILURE); } char _hostname[1024]; gethostname(_hostname, 1024); hostname = ribs_strdup(_hostname); int wd = inotify_init1(IN_NONBLOCK); if (0 >= wd) { LOGGER_ERROR("%s", "failed to init inotify. cannot proceed. make sure you've inotify and is accessible to this user."); exit(EXIT_FAILURE); } if (!recursive_flush_events(wd, files, num_files)) { LOGGER_ERROR("%s", "collection failed"); abort(); } return 0; }