void main_init() { /* one-time initialization */ #ifdef USE_SYSTEMD int i; systemd_fds=sd_listen_fds(1); if(systemd_fds<0) fatal("systemd initialization failed"); listen_fds_start=SD_LISTEN_FDS_START; /* set non-blocking mode on systemd file descriptors */ for(i=0; i<systemd_fds; ++i) set_nonblock(listen_fds_start+i, 1); #else systemd_fds=0; /* no descriptors received */ listen_fds_start=3; /* the value is not really important */ #endif /* basic initialization contains essential functions required for logging * subsystem to function properly, thus all errors here are fatal */ if(ssl_init()) /* initialize SSL library */ fatal("SSL initialization failed"); if(sthreads_init()) /* initialize critical sections & SSL callbacks */ fatal("Threads initialization failed"); if(cron_init()) /* initialize periodic events */ fatal("Cron initialization failed"); options_defaults(); options_apply(); #ifndef USE_FORK get_limits(); /* required by setup_fd() */ #endif fds=s_poll_alloc(); if(signal_pipe_init()) fatal("Signal pipe initialization failed: " "check your personal firewall"); stunnel_info(LOG_NOTICE); }
void n230_init(void) { //TODO: We may need to remove the debug UART before we release. //Initialize the debug UART first. wb_uart_init(WB_DBG_UART_BASE, CPU_CLOCK_FREQ/DBG_UART_BAUD); init_printf(NULL, putc); //Now we can init the rest with prints UHD_FW_TRACE_FSTR(INFO, "[ZPU Init Begin -- CPU CLOCK is %d MHz]", (CPU_CLOCK_FREQ/1000000)); //Initialize cron and the per millisecond cron job UHD_FW_TRACE(INFO, "Initializing cron..."); cron_init(get_counter_val, CPU_CLOCK_FREQ); cron_job_init(PER_MILLISEC_CRON_JOBID, 1); cron_job_init(PER_SECOND_CRON_JOBID, 1000); //Initialize rate for I2C cores UHD_FW_TRACE(INFO, "Initializing I2C..."); for (uint32_t i = 0; i < N230_NUM_ETH_PORTS; i++) { wb_i2c_init((i==1)?WB_ETH1_I2C_BASE:WB_ETH0_I2C_BASE, CPU_CLOCK_FREQ); } //Initialize eeprom read_n230_eeprom(); UHD_FW_TRACE(INFO, "Initializing network stack..."); init_network_stack(); }
int main(int argc, char **argv) { int exit_code = EXIT_FAILURE; int i; bool help = false; bool version = false; bool check_config = false; bool daemon = false; const char *debug_filter = NULL; int pid_fd = -1; for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0) { help = true; } else if (strcmp(argv[i], "--version") == 0) { version = true; } else if (strcmp(argv[i], "--check-config") == 0) { check_config = true; } else if (strcmp(argv[i], "--daemon") == 0) { daemon = true; } else if (strcmp(argv[i], "--debug") == 0) { if (i + 1 < argc && strncmp(argv[i + 1], "--", 2) != 0) { debug_filter = argv[++i]; } else { debug_filter = ""; } } else { fprintf(stderr, "Unknown option '%s'\n\n", argv[i]); print_usage(); return EXIT_FAILURE; } } if (help) { print_usage(); return EXIT_SUCCESS; } if (version) { printf("%s\n", VERSION_STRING); return EXIT_SUCCESS; } read_image_version(); _x11_enabled = access("/etc/tf_x11_enabled", F_OK) == 0; if (prepare_paths() < 0) { return EXIT_FAILURE; } if (check_config) { return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } config_init(_config_filename); if (config_has_error()) { fprintf(stderr, "Error(s) occurred while reading config file '%s'", _config_filename); goto error_config; } log_init(); if (daemon) { pid_fd = daemon_start(_log_filename, _pid_filename, 1); } else { pid_fd = pid_file_acquire(_pid_filename, getpid()); if (pid_fd == PID_FILE_ALREADY_ACQUIRED) { fprintf(stderr, "Already running according to '%s'\n", _pid_filename); } } if (pid_fd < 0) { goto error_pid_file; } if (daemon && _x11_enabled) { log_info("RED Brick API Daemon %s started (daemonized, X11 enabled) on %s image", VERSION_STRING, _image_version); } else if (daemon) { log_info("RED Brick API Daemon %s started (daemonized) on %s image", VERSION_STRING, _image_version); } else if (_x11_enabled) { log_info("RED Brick API Daemon %s started (X11 enabled) on %s image", VERSION_STRING, _image_version); } else { log_info("RED Brick API Daemon %s started on %s image", VERSION_STRING, _image_version); } if (debug_filter != NULL) { log_enable_debug_override(debug_filter); } if (config_has_warning()) { log_warn("Warning(s) in config file '%s', run with --check-config option for details", _config_filename); } if (event_init() < 0) { goto error_event; } if (signal_init(handle_sighup, NULL) < 0) { goto error_signal; } if (process_monitor_init() < 0) { goto error_process_monitor; } if (cron_init() < 0) { goto error_cron; } if (inventory_init() < 0) { goto error_inventory; } if (api_init() < 0) { goto error_api; } if (network_init(_brickd_socket_filename, _cron_socket_filename) < 0) { goto error_network; } if (inventory_load_programs() < 0) { goto error_load_programs; } if (event_run(network_cleanup_brickd_and_socats) < 0) { goto error_run; } exit_code = EXIT_SUCCESS; error_run: inventory_unload_programs(); error_load_programs: network_exit(); error_network: api_exit(); error_api: inventory_exit(); error_inventory: cron_exit(); error_cron: process_monitor_exit(); error_process_monitor: signal_exit(); error_signal: event_exit(); error_event: log_info("RED Brick API Daemon %s stopped", VERSION_STRING); error_pid_file: if (pid_fd >= 0) { pid_file_release(_pid_filename, pid_fd); } log_exit(); error_config: config_exit(); return exit_code; }