int kadnode_set(const char opt[], const char val[]) { if (gconf && !gconf->is_running) { return conf_set(opt, val); } else { return 1; } }
void conf_load(Conf* conf, const char* load_file) { //clear conf_node_destroy(conf); FILE* fp = fopen(load_file, "r"); ASSERT(fp != NULL, "Open the %s is failed ! error msg : %s", load_file, strerror(errno)); char line_buf[CONF_STRING_MAX_LEN] = { 0 }; char result_buf[CONF_STRING_MAX_LEN] = { 0 }; while (!feof(fp)) { bzero(line_buf, CONF_STRING_MAX_LEN); bzero(result_buf, CONF_STRING_MAX_LEN); fgets(line_buf, CONF_STRING_MAX_LEN, fp); simple_string_trim(line_buf, CONF_SPACE_SYMBOL, result_buf); simple_string_trim(line_buf, CONF_NEWLINE_SYMBOL, result_buf); if (simple_string_start_with(result_buf, "#") || strlen(result_buf) <= 0) { continue; } int index = 0; ASSERT((index = simple_string_index_of(result_buf, "=")) >= 0, "Input line format error :'%s'.", result_buf); char tmp_key[CONF_STRING_MAX_LEN] = { 0 }; char key[CONF_STRING_MAX_LEN] = { 0 }; char tmp_value[CONF_STRING_MAX_LEN] = { 0 }; char value[CONF_STRING_MAX_LEN] = { 0 }; simple_string_substr(result_buf, 0, index, tmp_key); simple_string_substr(result_buf, index + 1, strlen(result_buf), tmp_value); simple_string_trim(tmp_key, CONF_SPACE_SYMBOL, key); simple_string_trim(tmp_value, CONF_SPACE_SYMBOL, value); simple_string_trim(key, CONF_NEWLINE_SYMBOL, tmp_key); simple_string_trim(value, CONF_NEWLINE_SYMBOL, tmp_value); conf_set(conf, tmp_key, tmp_value); } fclose(fp); }
void conf_merge(conf_t *to, conf_t *from) { GError *error = NULL; gsize length; gchar **keys; gchar *key; int i = 0; keys = g_key_file_get_keys(from,"enter",&length,&error); if (keys) { while (i<length) { key = keys[i++]; gchar *value = conf_get(from,key); conf_set(to,key,value); } g_strfreev(keys); } if (error) { g_error_free(error); } }
void menu_request_settings(void) { gint result; GtkDialog * dialog; GtkToggleButton * autostart_studio_button; GtkToggleButton * send_notifications_button; GtkEntry * shell_entry; GtkEntry * terminal_entry; GtkSpinButton * js_delay_spin; GtkEntry * jack_conf_tool_entry; bool autostart; bool notify; const char * shell; const char * terminal; unsigned int js_delay; const char * jack_conf_tool; autostart_studio_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("settings_studio_autostart_checkbutton")); send_notifications_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("settings_send_notifications_checkbutton")); shell_entry = GTK_ENTRY(get_gtk_builder_widget("settings_shell_entry")); terminal_entry = GTK_ENTRY(get_gtk_builder_widget("settings_terminal_entry")); js_delay_spin = GTK_SPIN_BUTTON(get_gtk_builder_widget("settings_js_delay_spin")); jack_conf_tool_entry = GTK_ENTRY(get_gtk_builder_widget("settings_jack_conf_tool_entry")); dialog = GTK_DIALOG(get_gtk_builder_widget("settings_dialog")); if (!conf_get_bool(LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART, &autostart)) { autostart = LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART_DEFAULT; } if (!conf_get_bool(LADISH_CONF_KEY_DAEMON_NOTIFY, ¬ify)) { notify = LADISH_CONF_KEY_DAEMON_NOTIFY_DEFAULT; } if (!conf_get(LADISH_CONF_KEY_DAEMON_SHELL, &shell)) { shell = LADISH_CONF_KEY_DAEMON_SHELL_DEFAULT; } if (!conf_get(LADISH_CONF_KEY_DAEMON_TERMINAL, &terminal)) { terminal = LADISH_CONF_KEY_DAEMON_TERMINAL_DEFAULT; } if (!conf_get_uint(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, &js_delay)) { js_delay = LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY_DEFAULT; } if (!conf_get(LADISH_CONF_KEY_JACK_CONF_TOOL, &jack_conf_tool)) { jack_conf_tool = LADISH_CONF_KEY_JACK_CONF_TOOL_DEFAULT; } gtk_toggle_button_set_active(autostart_studio_button, autostart); gtk_toggle_button_set_active(send_notifications_button, notify); gtk_entry_set_text(shell_entry, shell); gtk_entry_set_text(terminal_entry, terminal); gtk_entry_set_text(jack_conf_tool_entry, jack_conf_tool); gtk_spin_button_set_range(js_delay_spin, 0, 1000); gtk_spin_button_set_increments(js_delay_spin, 1, 2); gtk_spin_button_set_value(js_delay_spin, js_delay); gtk_widget_show(GTK_WIDGET(dialog)); result = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(GTK_WIDGET(dialog)); if (result != GTK_RESPONSE_OK) { return; } autostart = gtk_toggle_button_get_active(autostart_studio_button); notify = gtk_toggle_button_get_active(send_notifications_button); shell = gtk_entry_get_text(shell_entry); terminal = gtk_entry_get_text(terminal_entry); js_delay = gtk_spin_button_get_value(js_delay_spin); jack_conf_tool = gtk_entry_get_text(jack_conf_tool_entry); if (!conf_set_bool(LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART, autostart) || !conf_set_bool(LADISH_CONF_KEY_DAEMON_NOTIFY, notify) || !conf_set(LADISH_CONF_KEY_DAEMON_SHELL, shell) || !conf_set(LADISH_CONF_KEY_DAEMON_TERMINAL, terminal) || !conf_set_uint(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, js_delay) || !conf_set(LADISH_CONF_KEY_JACK_CONF_TOOL, jack_conf_tool)) { error_message_box(_("Storing settings")); } }
/************************************************************************************************** LOAD_CONFIG Load the configuration file. **************************************************************************************************/ void load_config(void) { int n; struct passwd *pwd = NULL; struct group *grp = NULL; /* Load config */ conf_load(&Conf, opt_conf); /* Set defaults */ for (n = 0; defConfig[n].name; n++) { if (defConfig[n].name[0] == '-' || !defConfig[n].value) continue; if (!conf_get(&Conf, defConfig[n].name, NULL)) conf_set(&Conf, defConfig[n].name, defConfig[n].value, 1); } /* Support "mysql-user" etc. for backwards compatibility */ if (conf_get(&Conf, "mysql-host", NULL)) conf_set(&Conf, "db-host", conf_get(&Conf, "mysql-host", NULL), 0); if (conf_get(&Conf, "mysql-user", NULL)) conf_set(&Conf, "db-user", conf_get(&Conf, "mysql-user", NULL), 0); if (conf_get(&Conf, "mysql-pass", NULL)) conf_set(&Conf, "db-password", conf_get(&Conf, "mysql-pass", NULL), 0); if (conf_get(&Conf, "mysql-password", NULL)) conf_set(&Conf, "db-password", conf_get(&Conf, "mysql-password", NULL), 0); #if HAVE_GETPWUID /* Set default for database username to real username if none was provided */ if (!conf_get(&Conf, "db-user", NULL)) { struct passwd *pwd2; if ((pwd2 = getpwuid(getuid())) && pwd2->pw_name) { conf_set(&Conf, "db-user", pwd2->pw_name, 0); memset(pwd2, 0, sizeof(struct passwd)); } } #endif /* Load user/group perms */ if (!(pwd = getpwnam(conf_get(&Conf, "user", NULL)))) Err(_("error loading uid for user `%s'"), conf_get(&Conf, "user", NULL)); perms_uid = pwd->pw_uid; perms_gid = pwd->pw_gid; memset(pwd, 0, sizeof(struct passwd)); if (!(grp = getgrnam(conf_get(&Conf, "group", NULL))) && !(grp = getgrnam("nobody"))) { Warnx(_("error loading gid for group `%s'"), conf_get(&Conf, "group", NULL)); Warnx(_("using gid %lu from user `%s'"), (unsigned long)perms_gid, conf_get(&Conf, "user", NULL)); } else { perms_gid = grp->gr_gid; memset(grp, 0, sizeof(struct group)); } /* We call conf_set_logging() again after moving into background, but it's called here to report on errors. */ conf_set_logging(); /* Set global options */ task_timeout = atou(conf_get(&Conf, "timeout", NULL)); axfr_enabled = GETBOOL(conf_get(&Conf, "allow-axfr", NULL)); Verbose(_("AXFR is %senabled"), (axfr_enabled)?"":_("not ")); tcp_enabled = GETBOOL(conf_get(&Conf, "allow-tcp", NULL)); Verbose(_("TCP ports are %senabled"), (tcp_enabled)?"":_("not ")); dns_update_enabled = GETBOOL(conf_get(&Conf, "allow-update", NULL)); Verbose(_("DNS UPDATE is %senabled"), (dns_update_enabled)?"":_("not ")); mydns_soa_use_active = GETBOOL(conf_get(&Conf, "use-soa-active", NULL)); mydns_rr_use_active = GETBOOL(conf_get(&Conf, "use-rr-active", NULL)); dns_notify_enabled = dns_update_enabled && GETBOOL(conf_get(&Conf, "notify-enabled", NULL)); Verbose(_("DNS NOTIFY is %senabled"), (dns_notify_enabled)?"":_("not ")); notify_timeout = atou(conf_get(&Conf, "notify-timeout", NULL)); notify_retries = atou(conf_get(&Conf, "notify-retries", NULL)); notify_algorithm = conf_get(&Conf, "notify-algorithm", NULL); dns_ixfr_enabled = GETBOOL(conf_get(&Conf, "ixfr-enabled", NULL)); Verbose(_("DNS IXFR is %senabled"), (dns_ixfr_enabled)?"":_("not ")); ixfr_gc_enabled = GETBOOL(conf_get(&Conf, "ixfr-gc-enabled", NULL)); ixfr_gc_interval = atou(conf_get(&Conf, "ixfr-gc-interval", NULL)); ixfr_gc_delay = atou(conf_get(&Conf, "ixfr-gc-delay", NULL)); mydns_rr_extended_data = GETBOOL(conf_get(&Conf, "extended-data-support", NULL)); mydns_dbengine = conf_get(&Conf, "dbengine", NULL); wildcard_recursion = atoi(conf_get(&Conf, "wildcard-recursion", NULL)); ignore_minimum = GETBOOL(conf_get(&Conf, "ignore-minimum", NULL)); /* Set table names if provided */ mydns_set_soa_table_name(conf_get(&Conf, "soa-table", NULL)); mydns_set_rr_table_name(conf_get(&Conf, "rr-table", NULL)); /* Set additional where clauses if provided */ mydns_set_soa_where_clause(conf_get(&Conf, "soa-where", NULL)); mydns_set_rr_where_clause(conf_get(&Conf, "rr-where", NULL)); /* Set recursive server if specified */ conf_set_recursive(); #ifdef DN_COLUMN_NAMES dn_default_ns = conf_get(&Conf, "default-ns", NULL); #endif }
static int app_rbd_open() { int ret; /* poolname imagename username password monitor */ fprintf(stdout, "open rados as following setting:\n" "poolname: %s\n" "imagename: %s\n" "username: %s\n" "password: %s\n" "monitor: %s\n", poolname, imagename, username, password, monitor); /** * 创建一个 rados_t 句柄, 该句柄暴扣了rados 客户端的数据结构, 用来和 * rados 通信, 第二个参数是连接 rados 的客户端 ID, 这里我们使用 admin */ ret = rados_create(&cluster, username); if (ret < 0) { fprintf(stderr, "cannot create a cluster handle: %s\n", strerror(-ret)); goto failed_create; } /* 载入配置文件 */ ret = rados_conf_read_file(cluster, "/etc/ceph/ceph.conf"); if (ret < 0) { fprintf(stderr, "cannot read config file: %s\n", strerror(-ret)); goto failed_shutdown; } /** * 调用 rados_conf_set() 设置 rados 参数, 包括认证信息, monitor 地址等, * 如果设置了 cephx 认证, 那么之前创建 rados 句柄的时候, 必须设置客户端 * ID, 并且必须设置 key 的密码. */ if (conf_set("key", password) < 0) { goto failed_shutdown; } if (conf_set("auth_supported", "cephx") < 0) { goto failed_shutdown; } if (conf_set("mon_host", monitor) < 0) { goto failed_shutdown; } /* 完成了上面的设置之后, 就可以用我们的 rados 句柄连接 rados 服务器了 */ ret = rados_connect(cluster); if (ret < 0) { fprintf(stderr, "cannot connect to cluster: %s\n", strerror(-ret)); goto failed_shutdown; } /** * 成功连接上 rados 服务器之后, 就可以用 rados_ioctx_create() 打开 rados * 上的 pool 了, 该函数需要传递一个 rados_ioctx_t, 用来对打开的 pool 进行 * 操作. */ ret = rados_ioctx_create(cluster, poolname, &io_ctx); if (ret < 0) { fprintf(stderr, "cannot open rados pool %s: %s\n", poolname, strerror(-ret)); goto failed_shutdown; } /** * 上面说过, 我们已经能够有一个 rados_ioctx_t 的指针了, 该指针用来对关联的 * pool 进行 I/O 操作, 比如打开池中的 image 等, 这里我们直接对 rbd 操作. */ ret = rbd_open(io_ctx, imagename, &image, NULL); if (ret < 0) { fprintf(stderr, "error reading header from image %s\n", imagename); goto failed_open; } return 0; failed_open: rados_ioctx_destroy(io_ctx); failed_shutdown: rados_shutdown(cluster); failed_create: return ret; }
/* * Call the configuration API. * XXX Error handling! How to do multi-line transactions? */ static void ui_config(char *cmd) { struct conf_list *vlist; struct conf_list_node *vnode; char subcmd[201], section[201], tag[201], value[201], tmp[201]; char *v, *nv; int trans = 0, items, skip = 0, ret; FILE *fp; if (sscanf(cmd, "C %200s", subcmd) != 1) goto fail; if (strcasecmp(subcmd, "get") == 0) { if (sscanf(cmd, "C %*s [%200[^]]]:%200s", section, tag) != 2) goto fail; v = conf_get_str(section, tag); fp = ui_open_result(); if (fp) { if (v) fprintf(fp, "%s\n", v); fclose(fp); } LOG_DBG((LOG_UI, 30, "ui_config: \"%s\"", cmd)); return; } trans = conf_begin(); if (strcasecmp(subcmd, "set") == 0) { items = sscanf(cmd, "C %*s [%200[^]]]:%200[^=]=%200s %200s", section, tag, value, tmp); if (!(items == 3 || items == 4)) goto fail; conf_set(trans, section, tag, value, items == 4 ? 1 : 0, 0); if (strcasecmp(section, "Phase 2") == 0 && (strcasecmp(tag, "Connections") == 0 || strcasecmp(tag, "Passive-connections") == 0)) ui_conn_reinit(); } else if (strcasecmp(subcmd, "add") == 0) { items = sscanf(cmd, "C %*s [%200[^]]]:%200[^=]=%200s %200s", section, tag, value, tmp); if (!(items == 3 || items == 4)) goto fail; v = conf_get_str(section, tag); if (!v) conf_set(trans, section, tag, value, 1, 0); else { vlist = conf_get_list(section, tag); if (vlist) { for (vnode = TAILQ_FIRST(&vlist->fields); vnode; vnode = TAILQ_NEXT(vnode, link)) { if (strcmp(vnode->field, value) == 0) { skip = 1; break; } } conf_free_list(vlist); } /* Add the new value to the end of the 'v' list. */ if (skip == 0) { if (asprintf(&nv, v[strlen(v) - 1] == ',' ? "%s%s" : "%s,%s", v, value) == -1) { log_error("ui_config: malloc() failed"); if (trans) conf_end(trans, 0); return; } conf_set(trans, section, tag, nv, 1, 0); free(nv); } } if (strcasecmp(section, "Phase 2") == 0 && (strcasecmp(tag, "Connections") == 0 || strcasecmp(tag, "Passive-connections") == 0)) ui_conn_reinit(); } else if (strcasecmp(subcmd, "rmv") == 0) { items = sscanf(cmd, "C %*s [%200[^]]]:%200[^=]=%200s %200s", section, tag, value, tmp); if (!(items == 3 || items == 4)) goto fail; vlist = conf_get_list(section, tag); if (vlist) { nv = v = NULL; for (vnode = TAILQ_FIRST(&vlist->fields); vnode; vnode = TAILQ_NEXT(vnode, link)) { if (strcmp(vnode->field, value) == 0) continue; ret = v ? asprintf(&nv, "%s,%s", v, vnode->field) : asprintf(&nv, "%s", vnode->field); free(v); if (ret == -1) { log_error("ui_config: malloc() failed"); if (trans) conf_end(trans, 0); return; } v = nv; } conf_free_list(vlist); if (nv) { conf_set(trans, section, tag, nv, 1, 0); free(nv); } else { conf_remove(trans, section, tag); } } if (strcasecmp(section, "Phase 2") == 0 && (strcasecmp(tag, "Connections") == 0 || strcasecmp(tag, "Passive-connections") == 0)) ui_conn_reinit(); } else if (strcasecmp(subcmd, "rm") == 0) { if (sscanf(cmd, "C %*s [%200[^]]]:%200s", section, tag) != 2) goto fail; conf_remove(trans, section, tag); } else if (strcasecmp(subcmd, "rms") == 0) { if (sscanf(cmd, "C %*s [%200[^]]]", section) != 1) goto fail; conf_remove_section(trans, section); } else goto fail; LOG_DBG((LOG_UI, 30, "ui_config: \"%s\"", cmd)); conf_end(trans, 1); return; fail: if (trans) conf_end(trans, 0); log_print("ui_config: command \"%s\" malformed", cmd); }
int conf_loadfile() { FILE* conf; char buf[512], *action, param[128]; int line = 0, success; if (!(conf = fopen(set_get_string("config_file"), "r"))) { log(LOG_ERROR, "Unable to open config file \"%s\" for reading", set_get_string("config_file")); return -1; } while (fgets(buf, sizeof(buf), conf) > 0 && ++line) { if (!*buf || *buf=='#') continue; action = strtok(buf, " \t\r\n"); if (action != NULL) { if (strcasecmp(action, "set") == 0) { sprintf(param, "%s", strtok(NULL, " =\r\n")); success = conf_set(param, strtok(NULL, "\r\n")); } else if (strcasecmp(action, "add") == 0) { sprintf(param, "%s", strtok(NULL, " \r\n")); success = conf_add(param, strtok(NULL, "\r\n")); } else if (strcasecmp(action, "echo") == 0) { success = conf_echo(strtok(NULL, "\r\n"), NULL); } else if (strcasecmp(action, "load") == 0) { sprintf(param, "%s", strtok(NULL, " =\r\n")); success = conf_load(param, strtok(NULL, "\r\n")); } else { log(LOG_ERROR, "configuration file: Unknown command \"%s\"", action); success = -1; } if (success == -1) { log(LOG_WARNING, "Loading of configuration file failed " "(error in %s, line %i)", set_get_string("config_file"), line); fclose(conf); return -1; } } } fclose(conf); return 0; }