static int module_init(void) { struct contacts *contacts = baresip_contacts(); char path[256] = "", file[256] = ""; int err; err = conf_path_get(path, sizeof(path)); if (err) return err; if (re_snprintf(file, sizeof(file), "%s/contacts", path) < 0) return ENOMEM; if (!conf_fileexist(file)) { (void)fs_mkdir(path, 0700); err = write_template(file); if (err) return err; } err = conf_parse(file, confline_handler, contacts); if (err) return err; err = cmd_register(baresip_commands(), cmdv, ARRAY_SIZE(cmdv)); if (err) return err; info("Populated %u contacts\n", list_count(contact_list(contacts))); return err; }
int conf_load(const char * path, struct conf_entry * root) { uint8_t * buf; FILE * f; int size; /* open the file for reading */ if (!(f = fopen(path, "r"))) { DBG(DBG_ERROR, "fopen(\"%s\", \"r\") fail!", path); return -1; } /* get the file's size */ fseek(f, 0, SEEK_END); size = ftell(f); rewind(f); /* alloc memory for reading */ buf = (uint8_t *)calloc(1, size + 1); /* read the file */ if ((fread(buf, size, 1, f)) < 1) { DBG(DBG_ERROR, "fread() fail!"); return -1; } /* close the file */ fclose(f); /* null terminate the string */ buf[size] = '\0'; return conf_parse(buf, root); }
int main(int ac, char **av) { char *mode; int res; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); conf_parse(av[1]); conf_read(NULL); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); reset_dialog(); init_dialog(NULL); set_config_filename(conf_get_configname()); do { conf(&rootmenu); dialog_clear(); if (conf_get_changed()) res = dialog_yesno(NULL, _("Do you wish to save your " "new configuration?\n" "<ESC><ESC> to continue."), 6, 60); else res = -1; } while (res == KEY_ESC); end_dialog(); switch (res) { case 0: if (conf_write(filename)) { fprintf(stderr, _("\n\n" "Error during writing of the configuration.\n" "Your configuration changes were NOT saved." "\n\n")); return 1; } case -1: printf(_("\n\n" "*** End of configuration.\n" "\n\n")); break; default: fprintf(stderr, _("\n\n" "Your configuration changes were NOT saved." "\n\n")); } return 0; }
int main(int ac, char **av) { struct symbol *sym; char *mode; int res; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("KERNELVERSION", 0); sym_calc_value(sym); sprintf(menu_backtitle, _("Linux Kernel v%s Configuration"), sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); reset_dialog(); init_dialog(menu_backtitle); do { conf(&rootmenu); dialog_clear(); res = dialog_yesno(NULL, _("Do you wish to save your " "new kernel configuration?\n" "<ESC><ESC> to continue."), 6, 60); } while (res == KEY_ESC); end_dialog(); if (res == 0) { if (conf_write(NULL)) { fprintf(stderr, _("\n\n" "Error during writing of the kernel configuration.\n" "Your kernel configuration changes were NOT saved." "\n\n")); return 1; } printf(_("\n\n" "*** End of Linux kernel configuration.\n" "*** Execute 'make' to build the kernel or try 'make help'." "\n\n")); } else { fprintf(stderr, _("\n\n" "Your kernel configuration changes were NOT saved." "\n\n")); } return 0; }
int main(int ac, char **av) { conf_parse(av[1]); menu_build_message_list(menu_get_root_menu(NULL)); menu__xgettext(); return 0; }
int main(int ac, char **av) { struct symbol *sym; char *mode; int stat; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("KERNELVERSION", 0); sym_calc_value(sym); sprintf(menu_backtitle, _("swupdate %s Configuration"), sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); conf(&rootmenu); do { cprint_init(); cprint("--yesno"); cprint(_("Do you wish to save your new configuration?")); cprint("5"); cprint("60"); stat = exec_conf(); } while (stat < 0); if (stat == 0) { if (conf_write(NULL)) { fprintf(stderr, _("\n\n" "Error during writing of the configuration.\n" "Your configuration changes were NOT saved." "\n\n")); return 1; } printf(_("\n\n" "*** End of configuration.\n" "*** Execute 'make' to build the project or try 'make help'." "\n\n")); } else { fprintf(stderr, _("\n\n" "Your configuration changes were NOT saved." "\n\n")); } return 0; }
/** * Helper function. * * Reads symbols from a kconfig file and returns zero on success. * Otherwise, a python exception is created and a non-zero value is returned. * * @param kconfig_file path to the top-level Kconfig file * * @return 0 => success, non-zero => failure * * */ static int lkconfig__conf_parse ( const char* const kconfig_file ) { /* * FIXME: * conf_parse() from zconf.tab.c calls exit(1) on errors; * could modify it to return non-zero int on error * */ conf_parse ( kconfig_file ); return 0; }
void load_conf(struct opts *opts) { FILE *f; struct conf_entry *conf, *e; char *conf_file = opts->conf_file; if (!opts->conf_file) conf_file = DEFAULT_CONF_FILE; f = fopen (conf_file, "r"); if (!f) { if (opts->conf_file) { pfatal ("can't open conf file '%s'", opts->conf_file); } else { pinfo ("can't open conf file '%s'", conf_file); return; } } conf = conf_parse (f); if (!conf) pfatal ("can't parse config file"); for (e = conf; e; e = e->next) { if (!strcmp (e->key, "max-tries") && e->value) { opts->max_tries = atoi (e->value); } else if (!strcmp (e->key, "min-steady-state-interval") && e->value) { opts->min_steady_state_interval = atoi (e->value); } else if (!strcmp (e->key, "wait-between-tries") && e->value) { opts->wait_between_tries = atoi (e->value); } else if (!strcmp (e->key, "subprocess-tries") && e->value) { opts->subprocess_tries = atoi (e->value); } else if (!strcmp (e->key, "subprocess-wait-between-tries") && e->value) { opts->subprocess_wait_between_tries = atoi (e->value); } else if (!strcmp (e->key, "steady-state-interval") && e->value) { opts->steady_state_interval = atoi (e->value); } else if (!strcmp (e->key, "base-path") && e->value) { opts->base_path = strdup (e->value); if (!opts->base_path) fatal ("out of memory for base path"); } else if (!strcmp (e->key, "should-sync-hwclock")) { opts->should_sync_hwclock = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "should-load-disk")) { opts->should_load_disk = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "should-save-disk")) { opts->should_save_disk = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "should-netlink")) { opts->should_netlink = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "dry-run")) { opts->dry_run = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "jitter") && e->value) { opts->jitter = atoi (e->value); } else if (!strcmp (e->key, "verbose")) { verbose = e->value ? !strcmp(e->value, "yes") : 1; } else if (!strcmp (e->key, "source")) { e = parse_source(opts, e); } } }
int main(int ac, char **av) { FILE *base; if (ac < 1) { if ((base = fopen ("arch/x86/Kconfig", "r")) == NULL) { //Kernel < 2.6.24 with old arch conf_parse("arch/i386/Kconfig"); } else { conf_parse("arch/i386/Kconfig"); fclose(base); } } else conf_parse(av[1]); print_menu(&rootmenu); return 0; }
int main(int ac, char **av) { struct symbol *sym; char *mode; int stat; conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("KERNELRELEASE", 0); sym_calc_value(sym); sprintf(menu_backtitle, "Linux Kernel v%s Configuration", sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); conf(&rootmenu); do { cprint_init(); cprint("--yesno"); cprint("Do you wish to save your new kernel configuration?"); cprint("5"); cprint("60"); stat = exec_conf(); } while (stat < 0); if (stat == 0) { if (conf_write(NULL)) { fprintf(stderr, "\n\n" "Error during writing of the kernel configuration.\n" "Your kernel configuration changes were NOT saved." "\n\n"); return 1; } printf("\n\n" "*** End of Linux kernel configuration.\n" "*** Execute 'make' to build the kernel or try 'make help'." "\n\n"); } else { fprintf(stderr, "\n\n" "Your kernel configuration changes were NOT saved." "\n\n"); } return 0; }
int main(int ac, char **av) { int stat; char *mode; struct symbol *sym; conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("VERSION", 0); sym_calc_value(sym); snprintf(menu_backtitle, 128, "Core v%s Configuration", sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); init_dialog(); signal(SIGWINCH, winch_handler); conf(&rootmenu); end_dialog(); /* Restart dialog to act more like when lxdialog was still separate */ init_dialog(); do { stat = dialog_yesno(NULL, "Do you wish to save your new Core configuration?", 5, 60); } while (stat < 0); end_dialog(); if (stat == 0) { conf_write(NULL); printf("\n\n" "*** End of Core configuration.\n" "*** Check the top-level Makefile for additional configuration options.\n\n"); } else printf("\n\nYour Core configuration changes were NOT saved.\n\n"); return 0; }
int main(int ac, char **av) { struct symbol *sym; char *mode; int stat; conf_parse(av[1]); conf_read(NULL); sym = sym_lookup("VERSION", 0); sym_calc_value(sym); snprintf(menu_backtitle, 128, "BusyBox v%s Configuration", sym_get_string_value(sym)); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } tcgetattr(1, &ios_org); atexit(conf_cleanup); init_wsize(); init_dialog(); signal(SIGWINCH, winch_handler); conf(&rootmenu); end_dialog(); /* Restart dialog to act more like when lxdialog was still separate */ init_dialog(); do { stat = dialog_yesno(NULL, "Do you wish to save your new diagnostic program configuration?", 6, 60); } while (stat < 0); end_dialog(); if (stat == 0) { conf_write(NULL); printf("\n\n" "*** End of SQ diagnostic program configuration.\n"); printf("*** Execute 'make' to build the diagnostic program or try 'make help'.\n\n"); } else printf("\n\nYour diagnostic program configuration changes were NOT saved.\n\n"); return 0; }
//解析配置信息,并进行有效性判断 struct conf * conf_create(char *filename) { rstatus_t status; struct conf *cf; //打开配置文件,创建conf结构,并初始化 cf = conf_open(filename); if (cf == NULL) { return NULL; } /* validate configuration file before parsing */ status = conf_pre_validate(cf); //检查配置格式是否符合yml标准 if (status != NC_OK) { goto error; } /* parse the configuration file */ status = conf_parse(cf); //配置解析 if (status != NC_OK) { goto error; } /* validate parsed configuration */ status = conf_post_validate(cf); //重复性判断 if (status != NC_OK) { goto error; } conf_dump(cf); fclose(cf->fh); cf->fh = NULL; return cf; error: log_stderr("nutcracker: configuration file '%s' syntax is invalid", filename); fclose(cf->fh); cf->fh = NULL; conf_destroy(cf); return NULL; }
rmt_conf * conf_create(char *filename) { int ret; rmt_conf *cf; cf = conf_open(filename); if (cf == NULL) { return NULL; } /* validate configuration file before parsing */ ret = conf_pre_validate(cf); if (ret != RMT_OK) { goto error; } conf_organizations_dump(cf); /* parse the configuration file */ ret = conf_parse(cf); if (ret != RMT_OK) { goto error; } /* validate parsed configuration */ ret = conf_post_validate(cf); if (ret != RMT_OK) { goto error; } conf_dump(cf); fclose(cf->fh); cf->fh = NULL; return cf; error: fclose(cf->fh); cf->fh = NULL; conf_destroy(cf); return NULL; }
/* global functions */ int main(int argc, char **argv){ size_t i; /* check args */ if(argc < 4){ printf("usage: %s <Kconfig> <conf-header path> <config.h name>\n", argv[0]); return 1; } i = strlen(argv[2]); if(argv[2][i - 1] == '/') argv[2][i - 1] = 0; /* read Kconfig file */ conf_parse(argv[1]); /* read config file */ if(conf_read(NULL)){ fprintf(stderr, "error parsing config\n"); return 1; } /* create config headers */ if(conf_write_confheader(argv[2])){ fprintf(stderr, "error creating config headers\n"); return 1; } /* create configuration header dependency file */ if(conf_write_autoconfig_dep(argv[2], argv[3])){ fprintf(stderr, "error creating config header dependency file\n"); return 1; } /* create configuration header */ if(conf_write_autoconf(argv[3])){ fprintf(stderr, "error writing config header\n"); return 1; } return 0; }
config_t * conf_new (char *fname) { config_t * conf = (config_t*)xmalloc(sizeof(struct config_s)); if (!conf) { config_debug(("config_new: No memory\n")); return NULL; } memset(conf, 0, sizeof(struct config_s)); conf->items = xrtp_list_new(); conf->file = fopen(fname, "rw"); conf_parse(conf, conf->file); return conf; }
struct conf * conf_create(char *filename) { rstatus_t status; struct conf *cf; cf = conf_open(filename); if (cf == NULL) { return NULL; } /* validate configuration file before parsing */ status = conf_pre_validate(cf); if (status != NC_OK) { goto error; } /* parse the configuration file */ status = conf_parse(cf); if (status != NC_OK) { goto error; } /* validate parsed configuration */ status = conf_post_validate(cf); if (status != NC_OK) { goto error; } conf_dump(cf); fclose(cf->fh); cf->fh = NULL; return cf; error: fclose(cf->fh); cf->fh = NULL; conf_destroy(cf); return NULL; }
/* Before calling this function first time, please * initialize the `conf_t' structure with zero. * such as 'conf_t conf = {};' */ int conf_init(conf_t *conf, const char *filename) { FILE *fp; char resolved_path[PATH_MAX]; if (!realpath(filename, resolved_path)) { fprintf(stderr, "%s\n", strerror(errno)); return -1; } if (!(fp = fopen(filename, "r"))) { perror("fopen failed"); return -1; } if (conf_parse(conf, resolved_path, fp, 0) != 0) { fclose(fp); return -1; } fclose(fp); return 0; }
static struct dechunkiser_ctx *rtp_open_out(const char *fname, const char *config) { struct dechunkiser_ctx *res; res = malloc(sizeof(struct dechunkiser_ctx)); if (res == NULL) { return NULL; } if (conf_parse(res, config) != 0) { free(res); return NULL; } res->outfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (res->outfd < 0) { printf_log(res, 0, "Could not open output socket"); free(res); return NULL; } return res; }
void ng_init(void) { char path[PATH_MAX]; /* Initialize the config subsystem and register our context parsers */ conf_init_subsystem(); conf_register_context("player_group", parse_player_group); conf_register_context("dest_group", parse_dest_group); /* Load the config file containing the player groups and the choice groups */ strcpy(path, NONULL(getenv("HOME"))); strcat(path, ":" PKGDATADIR); conf_parse("notgame.cfg", path); /* Create the pre-game window */ pregame_init(); for (; gtk_events_pending(); ) { gtk_main_iteration(); } }
/** * Read the SIP accounts from the ~/.baresip/accounts file * * @return 0 if success, otherwise errorcode */ static int account_read_file(void) { char path[256] = "", file[256] = ""; uint32_t n; int err; err = conf_path_get(path, sizeof(path)); if (err) { warning("account: conf_path_get (%m)\n", err); return err; } if (re_snprintf(file, sizeof(file), "%s/accounts", path) < 0) return ENOMEM; if (!conf_fileexist(file)) { (void)fs_mkdir(path, 0700); err = account_write_template(file); if (err) return err; } err = conf_parse(file, line_handler, NULL); if (err) return err; n = list_count(uag_list()); info("Populated %u account%s\n", n, 1==n ? "" : "s"); if (list_isempty(uag_list())) { info("account: No SIP accounts found\n" " -- check your config " "or add an account using 'R' command\n"); } return 0; }
int main(int ac, char **av) { char *mode; int res; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); signal(SIGINT, sig_handler); conf_parse(av[1]); conf_read(NULL); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } initscr(); getyx(stdscr, saved_y, saved_x); if (init_dialog(NULL)) { fprintf(stderr, N_("Your display is too small to run Menuconfig!\n")); fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n")); return 1; } set_config_filename(conf_get_configname()); do { conf(&rootmenu); res = handle_exit(); } while (res == KEY_ESC); return res; }
int atheme_main(int argc, char *argv[]) { int daemonize_pipe[2]; bool have_conf = false; bool have_log = false; bool have_datadir = false; char buf[32]; int pid, r; FILE *pid_file; const char *pidfilename = RUNDIR "/atheme.pid"; char *log_p = NULL; mowgli_getopt_option_t long_opts[] = { { NULL, 0, NULL, 0, 0 }, }; atheme_bootstrap(); /* do command-line options */ while ((r = mowgli_getopt_long(argc, argv, "c:dhrl:np:D:v", long_opts, NULL)) != -1) { switch (r) { case 'c': config_file = sstrdup(mowgli_optarg); have_conf = true; break; case 'd': log_force = true; break; case 'h': print_help(); exit(EXIT_SUCCESS); break; case 'r': readonly = true; break; case 'l': log_p = sstrdup(mowgli_optarg); have_log = true; break; case 'n': runflags |= RF_LIVE; break; case 'p': pidfilename = mowgli_optarg; break; case 'D': datadir = mowgli_optarg; have_datadir = true; break; case 'v': print_version(); exit(EXIT_SUCCESS); break; default: printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n"); exit(EXIT_FAILURE); break; } } if (!have_conf) config_file = sstrdup(SYSCONFDIR "/atheme.conf"); if (!have_log) log_p = sstrdup(LOGDIR "/atheme.log"); if (!have_datadir) datadir = sstrdup(DATADIR); cold_start = true; runflags |= RF_STARTING; atheme_init(argv[0], log_p); slog(LG_INFO, "%s is starting up...", PACKAGE_STRING); /* check for pid file */ #ifndef MOWGLI_OS_WIN if ((pid_file = fopen(pidfilename, "r"))) { if (fgets(buf, 32, pid_file)) { pid = atoi(buf); if (!kill(pid, 0)) { fprintf(stderr, "atheme: daemon is already running\n"); exit(EXIT_FAILURE); } } fclose(pid_file); } #endif if (!(runflags & RF_LIVE)) daemonize(daemonize_pipe); atheme_setup(); conf_init(); if (!conf_parse(config_file)) { slog(LG_ERROR, "Error loading config file %s, aborting", config_file); exit(EXIT_FAILURE); } if (config_options.languagefile) { slog(LG_DEBUG, "Using language: %s", config_options.languagefile); if (!conf_parse(config_options.languagefile)) slog(LG_INFO, "Error loading language file %s, continuing", config_options.languagefile); } if (!backend_loaded && authservice_loaded) { slog(LG_ERROR, "atheme: no backend modules loaded, see your configuration file."); exit(EXIT_FAILURE); } /* we've done the critical startup steps now */ cold_start = false; /* load our db */ if (db_load) db_load(NULL); else if (backend_loaded) { slog(LG_ERROR, "atheme: backend module does not provide db_load()!"); exit(EXIT_FAILURE); } db_check(); #ifdef HAVE_GETPID /* write pid */ if ((pid_file = fopen(pidfilename, "w"))) { fprintf(pid_file, "%d\n", getpid()); fclose(pid_file); } else { fprintf(stderr, "atheme: unable to write pid file\n"); exit(EXIT_FAILURE); } #endif /* detach from terminal */ if ((runflags & RF_LIVE) || !detach_console(daemonize_pipe)) { #ifdef HAVE_GETPID slog(LG_INFO, "pid %d", getpid()); #endif slog(LG_INFO, "running in foreground mode from %s", PREFIX); } /* no longer starting */ runflags &= ~RF_STARTING; /* we probably have a few open already... */ me.maxfd = 3; /* DB commit interval is configurable */ if (db_save && !readonly) mowgli_timer_add(base_eventloop, "db_save", db_save, NULL, config_options.commit_interval); /* check expires every hour */ mowgli_timer_add(base_eventloop, "expire_check", expire_check, NULL, 3600); /* check k/x/q line expires every minute */ mowgli_timer_add(base_eventloop, "kline_expire", kline_expire, NULL, 60); mowgli_timer_add(base_eventloop, "xline_expire", xline_expire, NULL, 60); mowgli_timer_add(base_eventloop, "qline_expire", qline_expire, NULL, 60); /* check authcookie expires every ten minutes */ mowgli_timer_add(base_eventloop, "authcookie_expire", authcookie_expire, NULL, 600); /* reseed rng a little every five minutes */ mowgli_timer_add(base_eventloop, "rng_reseed", rng_reseed, NULL, 293); me.connected = false; uplink_connect(); /* main loop */ io_loop(); /* we're shutting down */ hook_call_shutdown(); if (db_save && !readonly) db_save(NULL); remove(pidfilename); errno = 0; if (curr_uplink != NULL && curr_uplink->conn != NULL) sendq_flush(curr_uplink->conn); connection_close_all(); me.connected = false; /* should we restart? */ if (runflags & RF_RESTART) { slog(LG_INFO, "main(): restarting"); #ifdef HAVE_EXECVE execv(BINDIR "/atheme-services", argv); #endif } slog(LG_INFO, "main(): shutting down"); mowgli_eventloop_destroy(base_eventloop); log_shutdown(); return 0; }
int main(int ac, char **av) { const char *progname = av[0]; int opt; const char *name, *defconfig_file = NULL /* gcc uninit */; struct stat tmpstat; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) { input_mode = (enum input_mode)opt; switch (opt) { case silentoldconfig: sync_kconfig = 1; break; case defconfig: case savedefconfig: defconfig_file = optarg; break; case randconfig: { struct timeval now; unsigned int seed; /* * Use microseconds derived seed, * compensate for systems where it may be zero */ gettimeofday(&now, NULL); seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); srand(seed); break; } case oldaskconfig: case oldconfig: case allnoconfig: case allyesconfig: case allmodconfig: case alldefconfig: case listnewconfig: case oldnoconfig: break; case '?': conf_usage(progname); exit(1); break; } } if (ac == optind) { printf(_("%s: Kconfig file missing\n"), av[0]); conf_usage(progname); exit(1); } name = av[optind]; conf_parse(name); //zconfdump(stdout); if (sync_kconfig) { name = conf_get_configname(); if (stat(name, &tmpstat)) { fprintf(stderr, _("***\n" "*** Configuration file \"%s\" not found!\n" "***\n" "*** Please run some configurator (e.g. \"make oldconfig\" or\n" "*** \"make menuconfig\" or \"make xconfig\").\n" "***\n"), name); exit(1); } } switch (input_mode) { case defconfig: if (!defconfig_file) defconfig_file = conf_get_default_confname(); if (conf_read(defconfig_file)) { printf(_("***\n" "*** Can't find default configuration \"%s\"!\n" "***\n"), defconfig_file); exit(1); } name = getenv("KCONFIG_SELINUX"); printf("KCONFIG_SELINUX(%s)\n", name); if (name) { if (conf_read_simple(name, S_DEF_USER, false)) { printf(_("***\n" "*** Can't find selinux configuration \"%s\"!\n" "***\n"), name); exit(1); } } name = getenv("KCONFIG_LOG_SELINUX"); printf("KCONFIG_LOG_SELINUX(%s)\n", name); if (name) { if (conf_read_simple(name, S_DEF_USER, false)) { printf(_("***\n" "*** Can't find selinux log configuration \"%s\"!\n" "***\n"), name); exit(1); } } name = getenv("KCONFIG_TIMA"); printf("KCONFIG_TIMA(%s)\n", name); if (name) { if (conf_read_simple(name, S_DEF_USER, false)) { printf(_("***\n" "*** Can't find tima log configuration \"%s\"!\n" "***\n"), name); exit(1); } } name = getenv("KCONFIG_VARIANT"); printf("KCONFIG_VARIANT(%s)\n", name); if (name) { if (conf_read_simple(name, S_DEF_USER, false)) { printf(_("***\n" "*** Can't find variant configuration \"%s\"!\n" "***\n"), name); exit(1); } } name = getenv("KCONFIG_DEBUG"); printf("KCONFIG_DEBUG(%s)\n", name); if (name) { if (conf_read_simple(name, S_DEF_USER, false)) { printf(_("***\n" "*** Can't find debug configuration \"%s\"!\n" "***\n"), name); exit(1); } } break; case savedefconfig: case silentoldconfig: case oldaskconfig: case oldconfig: case listnewconfig: case oldnoconfig: conf_read(NULL); break; case allnoconfig: case allyesconfig: case allmodconfig: case alldefconfig: case randconfig: name = getenv("KCONFIG_ALLCONFIG"); if (name && !stat(name, &tmpstat)) { conf_read_simple(name, S_DEF_USER, true); break; } switch (input_mode) { case allnoconfig: name = "allno.config"; break; case allyesconfig: name = "allyes.config"; break; case allmodconfig: name = "allmod.config"; break; case alldefconfig: name = "alldef.config"; break; case randconfig: name = "allrandom.config"; break; default: break; } if (!stat(name, &tmpstat)) conf_read_simple(name, S_DEF_USER, true); else if (!stat("all.config", &tmpstat)) conf_read_simple("all.config", S_DEF_USER, true); break; default: break; } if (sync_kconfig) { if (conf_get_changed()) { name = getenv("KCONFIG_NOSILENTUPDATE"); if (name && *name) { fprintf(stderr, _("\n*** The configuration requires explicit update.\n\n")); return 1; } } valid_stdin = isatty(0) && isatty(1) && isatty(2); } switch (input_mode) { case allnoconfig: conf_set_all_new_symbols(def_no); break; case allyesconfig: conf_set_all_new_symbols(def_yes); break; case allmodconfig: conf_set_all_new_symbols(def_mod); break; case alldefconfig: conf_set_all_new_symbols(def_default); break; case randconfig: conf_set_all_new_symbols(def_random); break; case defconfig: conf_set_all_new_symbols(def_default); break; case savedefconfig: break; case oldaskconfig: rootEntry = &rootmenu; conf(&rootmenu); input_mode = silentoldconfig; /* fall through */ case oldconfig: case listnewconfig: case oldnoconfig: case silentoldconfig: /* Update until a loop caused no more changes */ do { conf_cnt = 0; check_conf(&rootmenu); } while (conf_cnt && (input_mode != listnewconfig && input_mode != oldnoconfig)); break; } if (sync_kconfig) { /* silentoldconfig is used during the build so we shall update autoconf. * All other commands are only used to generate a config. */ if (conf_get_changed() && conf_write(NULL)) { fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); exit(1); } if (conf_write_autoconf()) { fprintf(stderr, _("\n*** Error during update of the configuration.\n\n")); return 1; } } else if (input_mode == savedefconfig) { if (conf_write_defconfig(defconfig_file)) { fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"), defconfig_file); return 1; } } else if (input_mode != listnewconfig) { if (conf_write(NULL)) { fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); exit(1); } } return 0; }
int main(int ac, char **av) { int i = 1; const char *name; struct stat tmpstat; if (ac > i && av[i][0] == '-') { switch (av[i++][1]) { case 'o': input_mode = ask_new; break; case 's': input_mode = ask_silent; valid_stdin = isatty(0) && isatty(1) && isatty(2); break; case 'd': input_mode = set_default; break; case 'D': input_mode = set_default; defconfig_file = av[i++]; if (!defconfig_file) { printf(_("%s: No default config file specified\n"), av[0]); exit(1); } break; case 'n': input_mode = set_no; break; case 'm': input_mode = set_mod; break; case 'y': input_mode = set_yes; break; case 'r': input_mode = set_random; srandom(time(NULL)); break; case 'h': case '?': fprintf(stderr, "See README for usage info\n"); exit(0); } } name = av[i]; if (!name) { printf(_("%s: Kconfig file missing\n"), av[0]); exit(1); } conf_parse(name); //zconfdump(stdout); switch (input_mode) { case set_default: if (!defconfig_file) defconfig_file = conf_get_default_confname(); if (conf_read(defconfig_file)) { printf("***\n" "*** Can't find default configuration \"%s\"!\n" "***\n", defconfig_file); exit(1); } break; case ask_silent: if (stat(".config", &tmpstat)) { printf(_("***\n" "*** You have not yet configured your "PROJECT_NAME"!\n" "***\n" "*** Please run some configurator (e.g. \"make oldconfig\" or\n" "*** \"make menuconfig\" or \"make xconfig\").\n" "***\n")); exit(1); } case ask_all: case ask_new: conf_read(NULL); break; case set_no: case set_mod: case set_yes: case set_random: name = getenv("KCONFIG_ALLCONFIG"); if (name && !stat(name, &tmpstat)) { conf_read_simple(name, S_DEF_USER); break; } switch (input_mode) { case set_no: name = "allno.config"; break; case set_mod: name = "allmod.config"; break; case set_yes: name = "allyes.config"; break; case set_random: name = "allrandom.config"; break; default: break; } if (!stat(name, &tmpstat)) conf_read_simple(name, S_DEF_USER); else if (!stat("all.config", &tmpstat)) conf_read_simple("all.config", S_DEF_USER); break; default: break; } if (input_mode != ask_silent) { rootEntry = &rootmenu; conf(&rootmenu); if (input_mode == ask_all) { input_mode = ask_silent; valid_stdin = 1; } } else if (sym_change_count) { name = getenv("KCONFIG_NOSILENTUPDATE"); if (name && *name) { fprintf(stderr, _("\n*** "PROJECT_NAME" configuration requires explicit update.\n\n")); return 1; } } else goto skip_check; do { conf_cnt = 0; check_conf(&rootmenu); } while (conf_cnt); if (!conf_write(NULL)) { skip_check: if (!(input_mode == ask_silent && conf_write_autoconf())) return 0; } fprintf(stderr, _("\n*** Error writing "PROJECT_NAME" configuration.\n\n")); return 1; }
int main(int ac, char **av) { int i = 1; const char *name; struct stat tmpstat; if (ac > i && av[i][0] == '-') { switch (av[i++][1]) { case 'o': input_mode = ask_new; break; case 's': input_mode = ask_silent; valid_stdin = isatty(0) && isatty(1) && isatty(2); break; case 'd': input_mode = set_default; break; case 'D': input_mode = set_default; defconfig_file = av[i++]; if (!defconfig_file) { printf("%s: No default config file specified\n", av[0]); exit(1); } break; case 'n': input_mode = set_no; break; case 'm': input_mode = set_mod; break; case 'y': input_mode = set_yes; break; case 'r': input_mode = set_random; srandom(time(NULL)); break; case 'h': case '?': printf("%s [-o|-s] config\n", av[0]); exit(0); } } name = av[i]; if (!name) { printf("%s: configuration file missing\n", av[0]); } conf_parse(name); //zconfdump(stdout); switch (input_mode) { case set_default: if (!defconfig_file) defconfig_file = conf_get_default_confname(); if (conf_read(defconfig_file)) { printf("***\n" "*** Can't find default configuration \"%s\"!\n" "***\n", defconfig_file); exit(1); } break; case ask_silent: if (stat(".config", &tmpstat)) { printf("***\n" "*** You have not yet configured axTLS!\n" "***\n" "*** Please run some configurator (e.g. \"make oldconfig\" or\n" "*** \"make menuconfig\" or \"make config\").\n" "***\n"); exit(1); } case ask_all: case ask_new: conf_read(NULL); break; default: break; } if (input_mode != ask_silent) { rootEntry = &rootmenu; conf(&rootmenu); if (input_mode == ask_all) { input_mode = ask_silent; valid_stdin = 1; } } do { conf_cnt = 0; check_conf(&rootmenu); } while (conf_cnt); if (conf_write(NULL)) { fprintf(stderr, "\n*** Error during writing of the axTLS configuration.\n\n"); return 1; } return 0; }
int main(int ac, char **av) { int saved_x, saved_y; char *mode; int res; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); conf_parse(av[1]); conf_read(NULL); mode = getenv("MENUCONFIG_MODE"); if (mode) { if (!strcasecmp(mode, "single_menu")) single_menu_mode = 1; } getyx(stdscr, saved_y, saved_x); if (init_dialog(NULL)) { fprintf(stderr, N_("Your display is too small to run Menuconfig!\n")); fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n")); return 1; } set_config_filename(conf_get_configname()); do { conf(&rootmenu); dialog_clear(); if (conf_get_changed()) res = dialog_yesno(NULL, _("Do you wish to save your " "new configuration?\n" "<ESC><ESC> to continue."), 6, 60); else res = -1; } while (res == KEY_ESC); end_dialog(saved_x, saved_y); switch (res) { case 0: if (conf_write(filename)) { fprintf(stderr, _("\n\n" "Error during writing of the configuration.\n" "Your configuration changes were NOT saved." "\n\n")); return 1; } case -1: printf(_("\n\n" "*** End of configuration.\n" "*** Execute 'make' to build or try 'make help'." "\n\n")); break; default: fprintf(stderr, _("\n\n" "Your configuration changes were NOT saved." "\n\n")); } return conf_write_autoconf(); }
int main(int ac, char **av) { const char *progname = av[0]; int opt; const char *name, *defconfig_file = NULL /* gcc uninit */; struct stat tmpstat; tty_stdio = isatty(0) && isatty(1); while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) { if (opt == 's') { conf_set_message_callback(NULL); continue; } input_mode = (enum input_mode)opt; switch (opt) { case syncconfig: sync_kconfig = 1; break; case defconfig: case savedefconfig: defconfig_file = optarg; break; case randconfig: { struct timeval now; unsigned int seed; char *seed_env; /* * Use microseconds derived seed, * compensate for systems where it may be zero */ gettimeofday(&now, NULL); seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); seed_env = getenv("KCONFIG_SEED"); if( seed_env && *seed_env ) { char *endp; int tmp = (int)strtol(seed_env, &endp, 0); if (*endp == '\0') { seed = tmp; } } fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed ); srand(seed); break; } case oldaskconfig: case oldconfig: case allnoconfig: case allyesconfig: case allmodconfig: case alldefconfig: case listnewconfig: case olddefconfig: break; case '?': conf_usage(progname); exit(1); break; } } if (ac == optind) { fprintf(stderr, "%s: Kconfig file missing\n", av[0]); conf_usage(progname); exit(1); } name = av[optind]; conf_parse(name); //zconfdump(stdout); if (sync_kconfig) { name = conf_get_configname(); if (stat(name, &tmpstat)) { fprintf(stderr, "***\n" "*** Configuration file \"%s\" not found!\n" "***\n" "*** Please run some configurator (e.g. \"make oldconfig\" or\n" "*** \"make menuconfig\" or \"make xconfig\").\n" "***\n", name); exit(1); } } switch (input_mode) { case defconfig: if (!defconfig_file) defconfig_file = conf_get_default_confname(); if (conf_read(defconfig_file)) { fprintf(stderr, "***\n" "*** Can't find default configuration \"%s\"!\n" "***\n", defconfig_file); exit(1); } break; case savedefconfig: case syncconfig: case oldaskconfig: case oldconfig: case listnewconfig: case olddefconfig: conf_read(NULL); break; case allnoconfig: case allyesconfig: case allmodconfig: case alldefconfig: case randconfig: name = getenv("KCONFIG_ALLCONFIG"); if (!name) break; if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) { if (conf_read_simple(name, S_DEF_USER)) { fprintf(stderr, "*** Can't read seed configuration \"%s\"!\n", name); exit(1); } break; } switch (input_mode) { case allnoconfig: name = "allno.config"; break; case allyesconfig: name = "allyes.config"; break; case allmodconfig: name = "allmod.config"; break; case alldefconfig: name = "alldef.config"; break; case randconfig: name = "allrandom.config"; break; default: break; } if (conf_read_simple(name, S_DEF_USER) && conf_read_simple("all.config", S_DEF_USER)) { fprintf(stderr, "*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n", name); exit(1); } break; default: break; } if (sync_kconfig) { if (conf_get_changed()) { name = getenv("KCONFIG_NOSILENTUPDATE"); if (name && *name) { fprintf(stderr, "\n*** The configuration requires explicit update.\n\n"); return 1; } } } switch (input_mode) { case allnoconfig: conf_set_all_new_symbols(def_no); break; case allyesconfig: conf_set_all_new_symbols(def_yes); break; case allmodconfig: conf_set_all_new_symbols(def_mod); break; case alldefconfig: conf_set_all_new_symbols(def_default); break; case randconfig: /* Really nothing to do in this loop */ while (conf_set_all_new_symbols(def_random)) ; break; case defconfig: conf_set_all_new_symbols(def_default); break; case savedefconfig: break; case oldaskconfig: rootEntry = &rootmenu; conf(&rootmenu); input_mode = oldconfig; /* fall through */ case oldconfig: case listnewconfig: case syncconfig: /* Update until a loop caused no more changes */ do { conf_cnt = 0; check_conf(&rootmenu); } while (conf_cnt); break; case olddefconfig: default: break; } if (sync_kconfig) { /* syncconfig is used during the build so we shall update autoconf. * All other commands are only used to generate a config. */ if (conf_get_changed() && conf_write(NULL)) { fprintf(stderr, "\n*** Error during writing of the configuration.\n\n"); exit(1); } if (conf_write_autoconf()) { fprintf(stderr, "\n*** Error during update of the configuration.\n\n"); return 1; } } else if (input_mode == savedefconfig) { if (conf_write_defconfig(defconfig_file)) { fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n", defconfig_file); return 1; } } else if (input_mode != listnewconfig) { if (conf_write(NULL)) { fprintf(stderr, "\n*** Error during writing of the configuration.\n\n"); exit(1); } } return 0; }
int main(int argc, char *argv[]) { int c, tout, flags, flush, restore; const char *spath, **blsock; size_t nblsock, maxblsock; setprogname(argv[0]); spath = NULL; blsock = NULL; maxblsock = nblsock = 0; flush = 0; restore = 0; tout = 0; flags = O_RDWR|O_EXCL|O_CLOEXEC; while ((c = getopt(argc, argv, "C:c:D:dfP:rR:s:t:v")) != -1) { switch (c) { case 'C': controlprog = optarg; break; case 'c': configfile = optarg; break; case 'D': dbfile = optarg; break; case 'd': debug++; break; case 'f': flush++; break; case 'P': spath = optarg; break; case 'R': rulename = optarg; break; case 'r': restore++; break; case 's': if (nblsock >= maxblsock) { maxblsock += 10; void *p = realloc(blsock, sizeof(*blsock) * maxblsock); if (p == NULL) err(EXIT_FAILURE, "Can't allocate memory for %zu sockets", maxblsock); blsock = p; } blsock[nblsock++] = optarg; break; case 't': tout = atoi(optarg) * 1000; break; case 'v': vflag++; break; default: usage(c); } } argc -= optind; if (argc) usage(0); signal(SIGHUP, sighup); signal(SIGINT, sigdone); signal(SIGQUIT, sigdone); signal(SIGTERM, sigdone); signal(SIGUSR1, sigusr1); signal(SIGUSR2, sigusr2); openlog(getprogname(), LOG_PID, LOG_DAEMON); if (debug) { lfun = dlog; if (tout == 0) tout = 5000; } else { if (tout == 0) tout = 15000; } update_interfaces(); conf_parse(configfile); if (flush) { rules_flush(); flags |= O_TRUNC; } struct pollfd *pfd = NULL; bl_t *bl = NULL; size_t nfd = 0; size_t maxfd = 0; for (size_t i = 0; i < nblsock; i++) addfd(&pfd, &bl, &nfd, &maxfd, blsock[i]); free(blsock); if (spath) { FILE *fp = fopen(spath, "r"); char *line; if (fp == NULL) err(EXIT_FAILURE, "Can't open `%s'", spath); for (; (line = fparseln(fp, NULL, NULL, NULL, 0)) != NULL; free(line)) addfd(&pfd, &bl, &nfd, &maxfd, line); fclose(fp); } if (nfd == 0) addfd(&pfd, &bl, &nfd, &maxfd, _PATH_BLSOCK); state = state_open(dbfile, flags, 0600); if (state == NULL) state = state_open(dbfile, flags | O_CREAT, 0600); if (state == NULL) return EXIT_FAILURE; if (restore) rules_restore(); if (!debug) { if (daemon(0, 0) == -1) err(EXIT_FAILURE, "daemon failed"); if (pidfile(NULL) == -1) err(EXIT_FAILURE, "Can't create pidfile"); } for (size_t t = 0; !done; t++) { if (readconf) { readconf = 0; conf_parse(configfile); } switch (poll(pfd, (nfds_t)nfd, tout)) { case -1: if (errno == EINTR) continue; (*lfun)(LOG_ERR, "poll (%m)"); return EXIT_FAILURE; case 0: state_sync(state); break; default: for (size_t i = 0; i < nfd; i++) if (pfd[i].revents & POLLIN) process(bl[i]); } if (t % 100 == 0) state_sync(state); if (t % 10000 == 0) update_interfaces(); update(); } state_close(state); return 0; }
int main(int ac, char **av) { int opt; const char *name; struct stat tmpstat; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) { switch (opt) { case 'o': input_mode = ask_silent; break; case 's': input_mode = ask_silent; sync_kconfig = 1; break; case 'b': input_mode = dont_ask; break; case 'B': input_mode = dont_ask_dont_tell; break; case 'd': input_mode = set_default; break; case 'D': input_mode = set_default; defconfig_file = optarg; break; case 'n': input_mode = set_no; break; case 'm': input_mode = set_mod; break; case 'y': input_mode = set_yes; break; case 'r': { struct timeval now; unsigned int seed; /* * Use microseconds derived seed, * compensate for systems where it may be zero */ gettimeofday(&now, NULL); seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); srand(seed); input_mode = set_random; break; } case 'h': printf(_("See README for usage info\n")); exit(0); break; default: fprintf(stderr, _("See README for usage info\n")); exit(1); } } if (ac == optind) { printf(_("%s: Kconfig file missing\n"), av[0]); exit(1); } name = av[optind]; conf_parse(name); //zconfdump(stdout); if (sync_kconfig) { name = conf_get_configname(); if (stat(name, &tmpstat)) { fprintf(stderr, _("***\n" "*** You have not yet configured your kernel!\n" "*** (missing kernel config file \"%s\")\n" "***\n" "*** Please run some configurator (e.g. \"make oldconfig\" or\n" "*** \"make menuconfig\" or \"make xconfig\").\n" "***\n"), name); exit(1); } } switch (input_mode) { case set_default: if (!defconfig_file) defconfig_file = conf_get_default_confname(); if (conf_read(defconfig_file)) { printf(_("***\n" "*** Can't find default configuration \"%s\"!\n" "***\n"), defconfig_file); exit(1); } break; case ask_silent: case ask_all: case ask_new: case dont_ask: case dont_ask_dont_tell: conf_read(NULL); break; case set_no: case set_mod: case set_yes: case set_random: name = getenv("KCONFIG_ALLCONFIG"); if (name && !stat(name, &tmpstat)) { conf_read_simple(name, S_DEF_USER); break; } switch (input_mode) { case set_no: name = "allno.config"; break; case set_mod: name = "allmod.config"; break; case set_yes: name = "allyes.config"; break; case set_random: name = "allrandom.config"; break; default: break; } if (!stat(name, &tmpstat)) conf_read_simple(name, S_DEF_USER); else if (!stat("all.config", &tmpstat)) conf_read_simple("all.config", S_DEF_USER); break; default: break; } if (sync_kconfig) { if (conf_get_changed()) { name = getenv("KCONFIG_NOSILENTUPDATE"); if (name && *name) { fprintf(stderr, _("\n*** Kernel configuration requires explicit update.\n\n")); return 1; } } valid_stdin = isatty(0) && isatty(1) && isatty(2); } switch (input_mode) { case set_no: conf_set_all_new_symbols(def_no); break; case set_yes: conf_set_all_new_symbols(def_yes); break; case set_mod: conf_set_all_new_symbols(def_mod); break; case set_random: conf_set_all_new_symbols(def_random); break; case set_default: conf_set_all_new_symbols(def_default); break; case ask_new: case ask_all: rootEntry = &rootmenu; conf(&rootmenu); input_mode = ask_silent; /* fall through */ case dont_ask: case dont_ask_dont_tell: case ask_silent: /* Update until a loop caused no more changes */ do { conf_cnt = 0; check_conf(&rootmenu); } while (conf_cnt && (input_mode != dont_ask && input_mode != dont_ask_dont_tell)); break; } if (sync_kconfig) { /* silentoldconfig is used during the build so we shall update autoconf. * All other commands are only used to generate a config. */ if (conf_get_changed() && conf_write(NULL)) { fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); exit(1); } if (conf_write_autoconf()) { fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n")); return 1; } } else { if (conf_write(NULL)) { fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); exit(1); } } return return_value; }