/** * Test main methode */ int main(int argc, char **argv) { //Initialize signal handler struct sigaction new_sa; new_sa.sa_handler = sigwait_handler; sigemptyset(&new_sa.sa_mask); new_sa.sa_flags = 0; if (sigaction(SIGCHLD, &new_sa, NULL) == -1) { THROWEXCEPTION("Could not install signal handler."); } #ifdef OBJECT_CACHE_DEBUG struct sigaction term; term.sa_handler = sigterm_handler; sigemptyset(&term.sa_mask); term.sa_flags |= SA_RESTART; sigaction(SIGTERM, &term, 0); sigaction(SIGINT, &term, 0); #endif //Process command line parameters parse_command_line_parameters(argc,argv); //Read config file config_file_descriptor* conf = read_config(config_file); //Init exporter ipfix_exporter* send_exporter; int ret = ipfix_init_exporter(conf->observation_domain_id, &send_exporter); if (ret != 0) { THROWEXCEPTION("ipfix_init_exporter failed!\n"); } #ifdef SUPPORT_COMPRESSION if (conf->compression_method && strlen(conf->compression_method) > 0) { ret = ipfix_init_compression(send_exporter, conf->compression_method, conf->compression_method_params); if (ret) THROWEXCEPTION("Failed to initialize compression module."); } #endif #ifdef SUPPORT_DTLS ipfix_set_dtls_certificate(send_exporter, conf->certificate, conf->certificate_key); ipfix_set_ca_locations(send_exporter, conf->ca, conf->ca_path); #endif //Add collectors from config file init_collectors(conf,send_exporter); //Generate templates msg(MSG_INFO, "Generating templates from config"); generate_templates_from_config(send_exporter,conf); msg(MSG_DIALOG, "LInEx is up and running. Press Ctrl-C to exit."); // Start capturing sessions if (conf->flow_sampling_mode == CRC32SamplingMode && conf->flow_sampling_polynom) set_sampling_polynom(conf->flow_sampling_polynom); msg(MSG_INFO, "Sampling mode is %d and threshold is %d", conf->flow_sampling_mode, conf->flow_sampling_max_value); if (start_flow_capture_session(&flow_session, conf->flow_inactive_timeout, conf->flow_active_timeout, conf->flow_object_cache_size, conf->flow_sampling_mode, conf->flow_sampling_max_value)) msg(MSG_ERROR, "Failed to start capture session."); olsr_capture_session = start_capture_session(); if (!olsr_capture_session) msg(MSG_ERROR, "Failed to start OLSR capture session."); bind_to_interfaces(conf); // Register timer to readd interfaces in case they go down event_loop_add_timer(120000, (event_timer_callback) &bind_to_interfaces, conf); #ifdef SUPPORT_ANONYMIZATION if (conf->anonymization_enabled && init_cryptopan(&flow_session.cryptopan, conf->anonymization_key, conf->anonymization_pad)) { msg(MSG_ERROR, "Failed to initialize CryptoPAN."); return 1; } else if (!conf->anonymization_enabled) { msg(MSG_INFO, "CryptoPAN disabled"); } else { msg(MSG_INFO, "CryptoPAN enabled"); } #endif // Declare IPFIX templates to export monitoring information if (declare_templates(send_exporter)) msg(MSG_ERROR, "Failed to export templates."); //Open XML file FILE* xmlfh = NULL; if(conf->xmlfile != NULL) { xmlfh = fopen(conf->xmlfile, "w"); if (xmlfh == NULL) THROWEXCEPTION("Could not open XML file %s", conf->xmlfile); } // Add timer to export routing tables node_set = kh_init(2); struct export_parameters params = { send_exporter, node_set }; event_loop_add_timer(conf->export_olsr_interval, (void (*)(void *)) &export_full, ¶ms); // Add timer to export flows struct export_flow_parameter flow_param = { send_exporter, &flow_session }; event_loop_add_timer(conf->export_flow_interval, (void (*)(void *)) &export_flows, &flow_param); // Add timer to export records struct export_record_parameters record_params = { send_exporter, conf, xmlfh }; event_loop_add_timer(conf->interval * 1000, (void (*)(void *)) &export_records, &record_params); // Add timer to export capture statistics struct export_capture_parameter capture_statistics_param = { send_exporter, flow_session.capture_session, olsr_capture_session }; event_loop_add_timer(10000, (void (*) (void *)) &export_capture_statistics, &capture_statistics_param); return event_loop_run(); }
int main(int argc, char *argv[]) { struct program_config * config = parse_command_line_parameters(argc, argv); dump_current_values(config); }
int main(int argc, char **argv) { memset(&globalconf, 0, sizeof(globalconf)); globalconf.connection = xcb_connect(NULL, &globalconf.screen_nbr); if(xcb_connection_has_error(globalconf.connection)) fatal("Cannot open display"); /* Get the root window */ globalconf.screen = xcb_aux_get_screen(globalconf.connection, globalconf.screen_nbr); /* Set up signal handlers and function called on normal exit */ struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_handler = exit_on_signal; sa.sa_flags = 0; sigaction(SIGHUP, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); atexit(exit_cleanup); /** * First round-trip */ /* Send requests for EWMH atoms initialisation */ xcb_intern_atom_cookie_t *ewmh_cookies = atoms_init(); parse_command_line_parameters(argc, argv); /* Prefetch the extensions data */ xcb_prefetch_extension_data(globalconf.connection, &xcb_composite_id); xcb_prefetch_extension_data(globalconf.connection, &xcb_damage_id); xcb_prefetch_extension_data(globalconf.connection, &xcb_xfixes_id); /* Initialise errors handlers */ xcb_event_handlers_init(globalconf.connection, &globalconf.evenths); event_init_start_handlers(); /* Pre-initialisation of the rendering backend */ if(!rendering_load()) { free(ewmh_cookies); fatal("Can't initialise rendering backend"); } /* Get replies for EWMH atoms initialisation */ if(!atoms_init_finalise(ewmh_cookies)) /* No need to free ewmh_cookies in case of error as it's already handles by xcb-ewmh when getting the replies */ fatal("Cannot initialise atoms"); /* First check whether there is already a Compositing Manager (ICCCM) */ xcb_get_selection_owner_cookie_t wm_cm_owner_cookie = xcb_ewmh_get_wm_cm_owner(&globalconf.ewmh, globalconf.screen_nbr); /** * Second round-trip */ /* Initialise extensions based on the cache and perform initialisation of the rendering backend */ display_init_extensions(); if(!(*globalconf.rendering->init)()) return EXIT_FAILURE; /* Check ownership for WM_CM_Sn before actually claiming it (ICCCM) */ xcb_window_t wm_cm_owner_win; if(xcb_ewmh_get_wm_cm_owner_reply(&globalconf.ewmh, wm_cm_owner_cookie, &wm_cm_owner_win, NULL) && wm_cm_owner_win != XCB_NONE) fatal("A compositing manager is already active (window=%jx)", (uintmax_t) wm_cm_owner_win); /* Now send requests to register the CM */ display_register_cm(); /** * Third round-trip */ /* Check extensions version and finish initialisation of the rendering backend */ display_init_extensions_finalise(); if(!(*globalconf.rendering->init_finalise)()) return EXIT_FAILURE; /* All the plugins given in the configuration file */ plugin_load_all(); /* Validate errors and get PropertyNotify needed to acquire _NET_WM_CM_Sn ownership */ xcb_aux_sync(globalconf.connection); xcb_event_poll_for_event_loop(&globalconf.evenths); globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection); xcb_get_modifier_mapping_cookie_t key_mapping_cookie = xcb_get_modifier_mapping_unchecked(globalconf.connection); /* Finish CM X registration */ if(!display_register_cm_finalise()) fatal("Could not acquire _NET_WM_CM_Sn ownership"); /** * Last initialisation round-trip */ /* Grab the server before performing redirection and get the tree of windows to ensure there won't be anything else at the same time */ xcb_grab_server(globalconf.connection); /* Now redirect windows and add existing windows */ display_init_redirect(); /* Validate errors handlers during redirect */ xcb_aux_sync(globalconf.connection); xcb_event_poll_for_event_loop(&globalconf.evenths); /* Manage existing windows */ display_init_redirect_finalise(); xcb_ungrab_server(globalconf.connection); /* Check the plugin requirements which will disable plugins which don't meet the requirements */ plugin_check_requirements(); /* Get the lock masks reply of the request previously sent */ key_lock_mask_get_reply(key_mapping_cookie); /* Initialise normal errors and events handlers */ event_init_handlers(); xcb_generic_event_t *event; /* Flush existing requests before the loop as DamageNotify events may have been received in the meantime */ xcb_flush(globalconf.connection); globalconf.do_repaint = true; /* Main event and error loop */ do { /* Block until an event is received */ event = xcb_wait_for_event(globalconf.connection); /* Check X connection to avoid SIGSEGV */ if(xcb_connection_has_error(globalconf.connection)) fatal("X connection invalid"); xcb_event_handle(&globalconf.evenths, event); free(event); /* Then process all remaining events in the queue because before painting, all the DamageNotify have to be received */ xcb_event_poll_for_event_loop(&globalconf.evenths); /* Now paint the windows */ if(globalconf.do_repaint) { window_t *windows = NULL; for(plugin_t *plugin = globalconf.plugins; plugin; plugin = plugin->next) if(plugin->enable && plugin->vtable->render_windows && (windows = (*plugin->vtable->render_windows)())) break; if(!windows) windows = globalconf.windows; window_paint_all(windows); xcb_aux_sync(globalconf.connection); } globalconf.do_repaint = false; } while(true); return EXIT_SUCCESS; }