/* Check and parse config file */ int get_bootinfo(struct cfgdata_t *cfgdata) { struct stat sinfo; /* Clean cfgdata structure */ init_cfgdata(cfgdata); /* Parse config file */ if (0 == parse_cfgfile(BOOTCFG_PATH, cfgdata)) { /* Found and parsed */ log_msg(lg, "+ config file found"); /* Check kernel presence * FIXME: we should stat every kernel or shouldn't stat at all if (0 == stat(cfgdata->kernelpath, &sinfo)) return 0; log_msg(lg, "+ config file points to non-existent kernel"); return -1; */ return 0; } else { /* No config file found. Check kernels. */ #ifdef USE_MACHINE_KERNEL /* Check machine kernel if set */ if (NULL != machine_kernel) { if (0 == stat(machine_kernel, &sinfo)) { cfgdata_add_kernel(cfgdata, machine_kernel); log_msg(lg, "+ found machine kernel '%s'", machine_kernel); return 0; } } #endif /* Check default kernels */ char **kp; for (kp = default_kernels; NULL != *kp; kp++) { if (0 == stat(*kp, &sinfo)) { cfgdata_add_kernel(cfgdata, *kp); log_msg(lg, "+ found default kernel '%s'", *kp); return 0; } } } /* We have no kernels */ log_msg(lg, "+ no config file nor any kernels found"); return -1; }
int main(int argc, char **argv) { int rc = 0; struct cfgdata_t cfg; struct params_t params; kx_inputs inputs; lg = log_open(16); log_msg(lg, "%s starting", PACKAGE_STRING); initmode = do_init(); /* Get cmdline parameters */ params.cfg = &cfg; init_cfgdata(&cfg); cfg.angle = 0; /* No rotation by default */ parse_cmdline(&cfg); kxb_ttydev = cfg.ttydev; setup_terminal(kxb_ttydev, &kxb_echo_state, 1); /* Setup function that will restore terminal when exit() will called */ atexit(atexit_restore_terminal); log_msg(lg, "FB angle is %d, tty is %s", cfg.angle, cfg.ttydev); #ifdef USE_MACHINE_KERNEL machine_kernel = get_machine_kernelpath(); /* FIXME should be passed as arg to get_bootinfo() */ #endif #ifdef USE_DELAY /* extra delay for initializing slow SD/CF */ sleep(USE_DELAY); #endif int no_ui = 1; /* UI presence flag */ #ifdef USE_FBMENU params.gui = NULL; if (no_ui) { params.gui = gui_init(cfg.angle); if (NULL == params.gui) { log_msg(lg, "Can't initialize GUI"); } else no_ui = 0; } #endif #ifdef USE_TEXTUI FILE *ttyfp; params.tui = NULL; if (no_ui) { if (cfg.ttydev) ttyfp = fopen(cfg.ttydev, "w"); else ttyfp = stdout; params.tui = tui_init(ttyfp); if (NULL == params.tui) { log_msg(lg, "Can't initialize TUI"); if (ttyfp != stdout) fclose(ttyfp); } else no_ui = 0; } #endif if (no_ui) exit(-1); /* Exit if no one UI was initialized */ params.menu = build_menu(¶ms); params.bootcfg = NULL; scan_devices(¶ms); if (-1 == fill_menu(¶ms)) { exit(-1); } /* Collect input devices */ inputs_init(&inputs, 8); inputs_open(&inputs); inputs_preprocess(&inputs); /* Run main event loop * Return values: <0 - error, >=0 - selected item id */ rc = do_main_loop(¶ms, &inputs); #ifdef USE_FBMENU if (params.gui) { if (rc < 0) gui_clear(params.gui); gui_destroy(params.gui); } #endif #ifdef USE_TEXTUI if (params.tui) { tui_destroy(params.tui); if (ttyfp != stdout) fclose(ttyfp); } #endif inputs_close(&inputs); inputs_clean(&inputs); log_close(lg); lg = NULL; /* rc < 0 indicate error */ if (rc < 0) exit(rc); menu_destroy(params.menu, 0); if (rc >= A_DEVICES) { start_kernel(¶ms, rc - A_DEVICES); } /* When we reach this point then some error has occured */ DPRINTF("We should not reach this point!"); exit(-1); }