void WiredTigerEngineFactory::ParseConfig(const Properties& props, WiredTigerConfig& cfg) { cfg.path = "."; conf_get_string(props, "data-dir", cfg.path); conf_get_int64(props, "wiredtiger.batch_commit_watermark", cfg.batch_commit_watermark); conf_get_string(props, "wiredtiger.init_options", cfg.init_options); conf_get_string(props, "wiredtiger.init_table_options", cfg.init_table_options); //conf_get_bool(props, "leveldb.logenable", cfg.logenable); }
void LevelDBEngineFactory::ParseConfig(const Properties& props, LevelDBConfig& cfg) { cfg.path = "."; conf_get_string(props, "data-dir", cfg.path); conf_get_int64(props, "leveldb.block_cache_size", cfg.block_cache_size); conf_get_int64(props, "leveldb.write_buffer_size", cfg.write_buffer_size); conf_get_int64(props, "leveldb.max_open_files", cfg.max_open_files); conf_get_int64(props, "leveldb.block_size", cfg.block_size); conf_get_int64(props, "leveldb.block_restart_interval", cfg.block_restart_interval); conf_get_int64(props, "leveldb.bloom_bits", cfg.bloom_bits); conf_get_int64(props, "leveldb.batch_commit_watermark", cfg.batch_commit_watermark); conf_get_string(props, "leveldb.compression", cfg.compression); }
/*{{{ create / destroy */ CacheMng *cache_mng_create (Application *app) { CacheMng *cmng; cmng = g_new0 (CacheMng, 1); cmng->app = app; cmng->h_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, cache_entry_destroy); cmng->q_lru = g_queue_new (); cmng->size = 0; cmng->check_time = time (NULL); cmng->max_size = conf_get_uint (application_get_conf (cmng->app), "filesystem.cache_dir_max_size"); cmng->cache_dir = g_strdup_printf ("%s/%s", conf_get_string (application_get_conf (cmng->app), "filesystem.cache_dir"), CACHE_MNGR_DIR); cmng->cache_hits = 0; cmng->cache_miss = 0; cache_mng_rm_cache_dir (cmng); if (g_mkdir_with_parents (cmng->cache_dir, 0700) != 0) { LOG_err (CMNG_LOG, "Failed to remove directory: %s", cmng->cache_dir); cache_mng_destroy (cmng); return NULL; } return cmng; }
static void zipper_init_command_server(zipper_t *zipper, const char *config_path) { config_t *command_server_conf = NULL; int ret = conf_get_sub_config(zipper->config_, "command_server_config", &command_server_conf); ASSERT(ret == 0, "get configure for command server failed\n"); char ip[MAX_IP_STR_LEN]; int port; conf_get_string(command_server_conf, "ip", ip); conf_get_integer(command_server_conf, "port", &port); char command_spec_file_path[PATH_MAX]; if (0 != conf_get_path(command_server_conf, "command_spec_file", command_spec_file_path)) ASSERT(0, "command specific file doesn't found\n"); zipper->command_server_ = command_server_create(zipper->base_event_, ip, port, command_spec_file_path, config_path); conf_destroy(command_server_conf); command_server_init_command_runner(zipper->command_server_, zipper->rule_store_, zipper->ip_store_); }
// got HttpConnection object static void fileio_write_on_multipart_init_con_cb (gpointer client, gpointer ctx) { HttpConnection *con = (HttpConnection *) client; FileWriteData *wdata = (FileWriteData *) ctx; gboolean res; gchar *path; http_connection_acquire (con); path = g_strdup_printf ("%s?uploads", wdata->fop->fname); // send storage class with the init request http_connection_add_output_header (con, "x-amz-storage-class", conf_get_string (application_get_conf (con->app), "s3.storage_type")); res = http_connection_make_request (con, path, "POST", NULL, TRUE, NULL, fileio_write_on_multipart_init_cb, wdata ); g_free (path); if (!res) { LOG_err (FIO_LOG, INO_CON_H"Failed to create HTTP request !", INO_T (wdata->ino), con); http_connection_release (con); wdata->on_buffer_written_cb (wdata->fop, wdata->ctx, FALSE, 0); g_free (wdata); return; } }
static void fileio_simple_download_on_con_cb (gpointer client, gpointer ctx) { HttpConnection *con = (HttpConnection *) client; FileIOSimpleDownload *fsim = (FileIOSimpleDownload *) ctx; gboolean res; LOG_debug (FIO_LOG, CON_H"Downloading data.", con); http_connection_acquire (con); http_connection_add_output_header (con, "x-amz-storage-class", conf_get_string (application_get_conf (con->app), "s3.storage_type")); res = http_connection_make_request (con, fsim->fname, "GET", NULL, TRUE, NULL, fileio_simple_download_on_sent_cb, fsim ); if (!res) { LOG_err (FIO_LOG, CON_H"Failed to create HTTP request !", con); http_connection_release (con); fsim->on_download_cb (fsim->ctx, FALSE, NULL, 0); fileio_simple_download_destroy (fsim); return; } }
// got HttpConnection object static void fileio_release_on_update_headers_con_cb (gpointer client, gpointer ctx) { HttpConnection *con = (HttpConnection *) client; FileIO *fop = (FileIO *) ctx; gchar *path; gchar *cpy_path; gboolean res; unsigned char digest[16]; gchar *md5str; size_t i; LOG_debug (FIO_LOG, INO_CON_H"Updating object's headers..", INO_T (fop->ino), con); http_connection_acquire (con); if (fop->content_type) http_connection_add_output_header (con, "Content-Type", fop->content_type); http_connection_add_output_header (con, "x-amz-metadata-directive", "REPLACE"); http_connection_add_output_header (con, "x-amz-storage-class", conf_get_string (application_get_conf (con->app), "s3.storage_type")); MD5_Final (digest, &fop->md5); md5str = g_malloc (33); for (i = 0; i < 16; ++i) sprintf(&md5str[i*2], "%02x", (unsigned int)digest[i]); http_connection_add_output_header (con, "x-amz-meta-md5", md5str); g_free (md5str); cpy_path = g_strdup_printf ("%s%s", conf_get_string (application_get_conf (fop->app), "s3.bucket_name"), fop->fname); http_connection_add_output_header (con, "x-amz-copy-source", cpy_path); g_free (cpy_path); path = g_strdup_printf ("%s", fop->fname); res = http_connection_make_request (con, path, "PUT", NULL, TRUE, NULL, fileio_release_on_update_header_cb, fop ); g_free (path); if (!res) { LOG_err (FIO_LOG, INO_CON_H"Failed to create HTTP request !", INO_T (fop->ino), con); http_connection_release (con); fileio_destroy (fop); return; } }
void LMDBEngineFactory::ParseConfig(const Properties& props, LMDBConfig& cfg) { cfg.path = "."; conf_get_string(props, "data-dir", cfg.path); conf_get_int64(props, "lmdb.database_max_size", cfg.max_db_size); conf_get_int64(props, "lmdb.batch_commit_watermark", cfg.batch_commit_watermark); conf_get_bool(props, "lmdb.readahead", cfg.readahead); }
void load_font(){ char *font_name=conf_get_string("font",FONT); Font font=XLoadFont(dpy,font_name); XSetFont(dpy,gc,font); XGCValues v; XGetGCValues(dpy,gc,GCFont,&v); sfont=XQueryFont(dpy,v.font); }
void* main2(void* ptr) { int retval; (void)ptr; retval = join_cluster(conf_get_string(CONF_ADDRESS)); if (retval) { log_print(log_critical, "Unable to join cluster"); exit(1); } return NULL; }
StatSrv *stat_srv_create (Application *app) { StatSrv *stat_srv; stat_srv = g_new0 (StatSrv, 1); stat_srv->app = app; stat_srv->q_op_history = g_queue_new (); stat_srv->boot_time = time (NULL); // stats server is disabled if (!conf_get_boolean (application_get_conf (stat_srv->app), "statistics.enabled")) { return stat_srv; } stat_srv->http = evhttp_new (application_get_evbase (app)); if (!stat_srv->http) { LOG_err (STAT_LOG, "Failed to create statistics server !"); return NULL; } // bind if (evhttp_bind_socket (stat_srv->http, conf_get_string (application_get_conf (stat_srv->app), "statistics.host"), conf_get_int (application_get_conf (stat_srv->app), "statistics.port")) == -1) { LOG_err (STAT_LOG, "Failed to bind statistics server to %s:%d", conf_get_string (application_get_conf (stat_srv->app), "statistics.host"), conf_get_int (application_get_conf (stat_srv->app), "statistics.port") ); return NULL; } // install handlers evhttp_set_cb (stat_srv->http, conf_get_string (application_get_conf (stat_srv->app), "statistics.stats_path"), stat_srv_on_stats_cb, stat_srv); evhttp_set_gencb (stat_srv->http, stat_srv_on_gen_cb, stat_srv); return stat_srv; }
int main(void) { int width = 0; int height = 0; int fullscreen = 0; int image_count = 0; int i = 0; int ret = 0; char expr[64] = {0}; const char *image; ret = conf_init("config.lua"); printf("ret: %d\n", ret); ret = conf_get_int("settings.resolution.width", &width); printf("ret: %d, width: %d\n", ret, width); ret = conf_get_int("settings.resolution.height", &height); printf("ret: %d, height: %d\n", ret, height); ret = conf_get_bool("settings.resolution.fullscreen", &fullscreen); printf("ret: %d, fullscreen: %d\n", ret, fullscreen); ret = conf_get_int("#settings.images", &image_count); printf("ret: %d, image_count: %d\n", ret, image_count); for (i = 0; i < image_count; ++i) { memset(expr, 0, sizeof(expr)); snprintf(expr, sizeof(expr), "settings.images[%d]", i + 1); ret = conf_get_string(expr, &image); printf("ret: %d, settings.images[%d] = %s\n", ret, i + 1, image); } conf_free(); return 0; }
static void zipper_init_server(zipper_t *zipper) { config_t *zipper_server_config = NULL; int ret = conf_get_sub_config(zipper->config_, "server_config", &zipper_server_config); ASSERT(ret == 0, "get configure for server failed\n"); char ip[MAX_IP_STR_LEN]; int port; conf_get_string(zipper_server_config, "ip", ip); conf_get_integer(zipper_server_config, "port", &port); zipper->dns_server_ = dns_server_create(zipper->base_event_, UDP_SERVER, ip, port); conf_destroy(zipper_server_config); command_server_get_named_ip(zipper->command_server_, ip); port = command_server_get_named_port(zipper->command_server_); zipper->dns_client_ = dns_client_create(zipper->base_event_, UDP_CLIENT, ip, port); }
void actions_init( conf_t* c ) { char nm[MAX_FILE_READ_BUFFER]; n_actions = conf_get_int( c, "n_actions" ); assert( n_actions > 0 && n_actions <= MAX_ACTIONS ); action_ranges = (action_range_t *) malloc( n_actions * sizeof( action_range_t ) ); action_names = (char**) malloc( n_actions * sizeof(char*) ); int i; for( i = 0; i < n_actions; i++ ) { action_names[i] = strdup( conf_get_string( c, spf1( nm, "action[%d].name", i ) ) ); action_ranges[i].front = conf_get_int( c, spf1( nm, "action_range[%d].front", i ) ); action_ranges[i].behind = conf_get_int( c, spf1( nm, "action_range[%d].behind", i ) ); action_ranges[i].left = conf_get_int( c, spf1( nm, "action_range[%d].left", i ) ); action_ranges[i].right = conf_get_int( c, spf1( nm, "action_range[%d].right", i ) ); assert( action_ranges[i].front >=0 && action_ranges[i].behind >=0 && action_ranges[i].left >=0 && action_ranges[i].right >= 0 ); if( action_ranges[i].front > action_ranges[max_action_id].front ) max_action_id = i; } }
static void fileio_simple_upload_on_con_cb (gpointer client, gpointer ctx) { HttpConnection *con = (HttpConnection *) client; FileIOSimpleUpload *fsim = (FileIOSimpleUpload *) ctx; time_t t; gchar str[10]; char time_str[50]; gboolean res; LOG_debug (FIO_LOG, CON_H"Uploading data. Size: %zu", con, evbuffer_get_length (fsim->write_buf)); http_connection_acquire (con); snprintf (str, sizeof (str), "%d", fsim->mode); http_connection_add_output_header (con, "x-amz-storage-class", conf_get_string (application_get_conf (con->app), "s3.storage_type")); http_connection_add_output_header (con, "x-amz-meta-mode", str); t = time (NULL); if (strftime (time_str, sizeof (time_str), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t))) { http_connection_add_output_header (con, "x-amz-meta-date", time_str); } res = http_connection_make_request (con, fsim->fname, "PUT", fsim->write_buf, TRUE, NULL, fileio_simple_upload_on_sent_cb, fsim ); if (!res) { LOG_err (FIO_LOG, CON_H"Failed to create HTTP request !", con); http_connection_release (con); fsim->on_upload_cb (fsim->ctx, FALSE); fileio_simple_upload_destroy (fsim); return; } }
void hamlib_init(void) { rig_model_t model; struct timespec sleep; freq_t freq; rmode_t mode; pbwidth_t width; gboolean enable; gchar *port, *conf, *spd; gint ret, speed; if (rig != NULL) return; enable = conf_get_bool("hamlib/enable"); model = conf_get_int("hamlib/rig"); port = conf_get_filename("hamlib/port"); speed = conf_get_int("hamlib/speed"); conf = conf_get_string("hamlib/conf"); if (!enable || !model || port[0] == 0) return; rig_set_debug(RIG_DEBUG_ERR); rig = rig_init(model); if (rig == NULL) { errmsg(_("Hamlib init: rig_init failed (model=%d)"), model); return; } g_strstrip(conf); if (conf[0]) { gchar **v, **p, *q; v = g_strsplit(conf, ",", 0); for (p = v; *p; p++) { if ((q = strchr(*p, '=')) == NULL) { errmsg(_("Hamlib init: Bad param=value pair: '%s'"), *p); break; } *q++ = 0; g_strstrip(*p); g_strstrip(q); if (hamlib_set_param(*p, q) == FALSE) break; } g_strfreev(v); } g_free(conf); hamlib_set_param("rig_pathname", port); g_free(port); spd = g_strdup_printf("%d", speed); hamlib_set_param("serial_speed", spd); g_free(spd); ret = rig_open(rig); if (ret != RIG_OK) { errmsg(_("Hamlib init: rig_open failed: %s"), rigerror(ret)); rig_cleanup(rig); rig = NULL; return; } /* Polling the rig sometimes fails right after opening it */ sleep.tv_sec = 0; sleep.tv_nsec = 100000000L; /* 100ms */ nanosleep(&sleep, NULL); if (need_freq == TRUE && \ (ret = rig_get_freq(rig, RIG_VFO_CURR, &freq)) != RIG_OK) { errmsg(_("Hamlib init: rig_get_freq failed: %s"), rigerror(ret)); hamlib_waterfall = FALSE; hamlib_qsodata = FALSE; need_freq = FALSE; need_mode = FALSE; } if (need_mode == TRUE && (ret = rig_get_mode(rig, RIG_VFO_CURR, &mode, &width)) != RIG_OK) { errmsg(_("Hamlib init: rig_get_mode failed: %s.\nAssuming USB mode."), rigerror(ret)); need_mode = FALSE; } if (hamlib_ptt == TRUE && (ret = rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_OFF)) != RIG_OK) { errmsg(_("Hamlib init: rig_set_ptt failed: %s.\nHamlib PTT disabled"), rigerror(ret)); hamlib_ptt = FALSE; } /* Don't create the thread if frequency data is not needed */ if (need_freq == FALSE) { // g_warning("Freq data not needed, thread not started."); /* If PTT isn't needed either then close everything */ if (hamlib_ptt == FALSE) { // g_warning("PTT not needed, closing rig."); rig_close(rig); rig_cleanup(rig); rig = NULL; } return; } if (pthread_create(&hamlib_thread, NULL, hamlib_loop, NULL) < 0) { errmsg(_("Hamlib init: pthread_create: %m")); rig_close(rig); rig_cleanup(rig); rig = NULL; } }
// got HttpConnection object static void fileio_release_on_part_con_cb (gpointer client, gpointer ctx) { HttpConnection *con = (HttpConnection *) client; FileIO *fop = (FileIO *) ctx; gchar *path; gboolean res; FileIOPart *part; size_t buf_len; const gchar *buf; LOG_debug (FIO_LOG, INO_CON_H"Releasing fop. Size: %zu", INO_T (fop->ino), con, evbuffer_get_length (fop->write_buf)); // add part information to the list part = g_new0 (FileIOPart, 1); part->part_number = fop->part_number; buf_len = evbuffer_get_length (fop->write_buf); buf = (const gchar *)evbuffer_pullup (fop->write_buf, buf_len); // XXX: move to separate thread // 1. calculate MD5 of a part. get_md5_sum (buf, buf_len, &part->md5str, &part->md5b); // 2. calculate MD5 of multiple message blocks MD5_Update (&fop->md5, buf, buf_len); fop->l_parts = g_list_append (fop->l_parts, part); // if this is a multipart if (fop->multipart_initiated) { if (!fop->uploadid) { LOG_err (FIO_LOG, INO_CON_H"UploadID is not set, aborting operation !", INO_T (fop->ino), con); fileio_destroy (fop); return; } path = g_strdup_printf ("%s?partNumber=%u&uploadId=%s", fop->fname, fop->part_number, fop->uploadid); fop->part_number++; } else { path = g_strdup (fop->fname); } #ifdef MAGIC_ENABLED // guess MIME type gchar *mime_type = magic_buffer (application_get_magic_ctx (fop->app), buf, buf_len); if (mime_type) { LOG_debug (FIO_LOG, "Guessed MIME type of %s as %s", path, mime_type); fop->content_type = g_strdup (mime_type); } else { LOG_err (FIO_LOG, "Failed to guess MIME type of %s !", path); } #endif http_connection_acquire (con); // add output headers http_connection_add_output_header (con, "Content-MD5", part->md5b); if (fop->content_type) http_connection_add_output_header (con, "Content-Type", fop->content_type); // if this is the full file if (!fop->multipart_initiated) { time_t t; gchar time_str[50]; // Add current time t = time (NULL); if (strftime (time_str, sizeof (time_str), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t))) { http_connection_add_output_header (con, "x-amz-meta-date", time_str); } http_connection_add_output_header (con, "x-amz-storage-class", conf_get_string (application_get_conf (con->app), "s3.storage_type")); } res = http_connection_make_request (con, path, "PUT", fop->write_buf, TRUE, NULL, fileio_release_on_part_sent_cb, fop ); g_free (path); if (!res) { LOG_err (FIO_LOG, INO_CON_H"Failed to create HTTP request !", INO_T (fop->ino), con); http_connection_release (con); fileio_destroy (fop); return; } }
int PerconaFTEngine::Init(const std::string& dir, const std::string& options) { Properties props; parse_conf_content(options, props); //parse config conf_get_int64(props, "cache_size", g_perconaft_config.cache_size); conf_get_uint32(props, "checkpoint_pool_threads", g_perconaft_config.checkpoint_pool_threads); conf_get_uint32(props, "checkpoint_period", g_perconaft_config.checkpoint_period); conf_get_uint32(props, "cleaner_period", g_perconaft_config.cleaner_period); conf_get_uint32(props, "cleaner_iterations", g_perconaft_config.cleaner_iterations); conf_get_bool(props, "evictor_enable_partial_eviction", g_perconaft_config.evictor_enable_partial_eviction); std::string compression; conf_get_string(props, "compression", compression); if (compression == "none") { g_perconaft_config.compression = TOKU_NO_COMPRESSION; } else if (compression == "snappy" || compression.empty()) { g_perconaft_config.compression = TOKU_SNAPPY_METHOD; } else if (compression == "zlib") { g_perconaft_config.compression = TOKU_ZLIB_METHOD; } else { ERROR_LOG("Invalid compression config:%s for PercanoFT.", compression.c_str()); return -1; } uint32 env_open_flags = DB_CREATE | DB_PRIVATE | DB_THREAD | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_RECOVER; int env_open_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; db_env_create(&m_env, 0); m_env->set_default_bt_compare(m_env, ardb_perconaft_compare); m_env->set_errcall(m_env, _err_callback); /* * set env config */ uint32 cache_gsize = g_perconaft_config.cache_size >> 30; uint32 cache_bytes = g_perconaft_config.cache_size % (1024 * 1024 * 1024); m_env->set_cachesize(m_env, cache_gsize, cache_bytes, 1); m_env->set_cachetable_pool_threads(m_env, g_perconaft_config.checkpoint_pool_threads); m_env->checkpointing_set_period(m_env, g_perconaft_config.checkpoint_period); m_env->cleaner_set_period(m_env, g_perconaft_config.cleaner_period); m_env->cleaner_set_iterations(m_env, g_perconaft_config.cleaner_iterations); m_env->evictor_set_enable_partial_eviction(m_env, g_perconaft_config.evictor_enable_partial_eviction); int r = m_env->open(m_env, dir.c_str(), env_open_flags, env_open_mode); CHECK_EXPR(r); DataArray nss; if (0 == r) { g_toku_env = m_env; DB* db = m_env->get_db_for_directory(m_env); if (NULL != db) { PerconaFTLocalContext& local_ctx = g_local_ctx.GetValue(); DB_TXN* txn = local_ctx.transc.Get(); DBC *c = NULL; CHECK_EXPR(r = db->cursor(db, txn, &c, 0)); if (0 == r) { r = c->c_getf_first(c, 0, nil_callback, NULL); } while (0 == r) { DBT raw_key; DBT raw_val; memset(&raw_key, 0, sizeof(raw_key)); memset(&raw_val, 0, sizeof(raw_key)); if (0 == c->c_get(c, &raw_key, &raw_val, DB_CURRENT)) { //std::string ns_str Data ns; ns.SetString((const char*) raw_key.data, false); INFO_LOG("TokuFT directory db %s:%s", (const char* ) raw_key.data, (const char* ) raw_val.data); nss.push_back(ns); } r = c->c_getf_next(c, 0, nil_callback, NULL); } if (NULL != c) { c->c_close(c); } local_ctx.transc.Release(true); r = 0; } } for (size_t i = 0; i < nss.size(); i++) { Context tmp; GetFTDB(tmp, nss[i], true); } return ENGINE_ERR(r); }
int imap_driver_config(struct module *module, config_setting_t *conf) { config_setting_t *setting, *value; struct imap_config *config; struct imap_driver *driver; int port; if (conf == NULL) return 1; config = malloc(sizeof(struct imap_config)); if (config == NULL) return 1; *config = config_default; setting = config_setting_get_member(conf, "listen"); if (setting) { /* in the future there are going to be more listen addresses but not * right now */ value = config_setting_get_elem(setting, 0); if (value == NULL) return 1; conf_get_string(config->listen, value); } /*TODO: prime for a rewrite */ setting = config_setting_get_member(conf, "defaults"); if (setting) { value = config_setting_get_elem(setting, 0); if (value == NULL) return 1; conf_get_string(config->default_host, value); value = config_setting_get_elem(setting, 1); if (value == NULL) return 1; port = config_setting_get_int(value); if ((port > 0) && (port <= 65535)) { config->default_port = port; } else { return 1; } } setting = config_setting_get_member(conf, "tls"); if (setting != NULL) { value = config_setting_get_elem(setting, 0); if (value == NULL) return 1; conf_get_string(config->cert, value); value = config_setting_get_elem(setting, 1); if (value == NULL) return 1; conf_get_string(config->pkey, value); } driver = calloc(1, sizeof(struct imap_driver)); if (driver == NULL) return 1; driver->config = config; module->priv = driver; return 0; }
END_TEST START_TEST (test_conf_default) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "agroup", head_group); fail_unless (ret == 0); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 1, "Got %d expected %d", i, 1); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 10); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'A'); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 5.5f) < 0.0001f, "Got %f expected %f", f, 5.5f); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "default") == 0); i = conf_get_int (conf, "agroup", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 1, "Got %d expected %d", i, 1); u = conf_get_uint (conf, "agroup", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 10); c = conf_get_char (conf, "agroup", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'A'); bf = conf_get_bool (conf, "agroup", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0); bt = conf_get_bool (conf, "agroup", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1); f = conf_get_float (conf, "agroup", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 5.5f) < 0.0001f, "Got %f expected %f", f, 5.5f); s = conf_get_string (conf, "agroup", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "default") == 0); conf_free (conf); }
END_TEST START_TEST (test_conf_file) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "agroup", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "c group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "b group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "e group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "d group", head_group); fail_unless (ret == 0); ret = conf_load (conf, CONFDIR "test.conf"); fail_unless (ret == 0, "ret = %d", ret); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 55, "Got %u expected %u", u, 55); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not Default") == 0, "Got %d expected 'Not Default", i); i = conf_get_int (conf, "agroup", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, "agroup", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 75, "Got %u expected %u", u, 75); c = conf_get_char (conf, "agroup", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, "agroup", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "agroup", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "agroup", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, "agroup", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not") == 0, "Got '%s' expected 'Not'", s); i = conf_get_int (conf, "b group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, "b group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 85, "Got %u expected %u", u, 85); c = conf_get_char (conf, "b group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, "b group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "b group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "b group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f + 25.5f) < 0.0001f, "Got %f expected %f", f, -25.5f); s = conf_get_string (conf, "b group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not Default") == 0, "Got %d expected 'Not Default", i); i = conf_get_int (conf, "c group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == -16, "Got %d expected %d", i, -16); u = conf_get_uint (conf, "c group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 16, "Got %u expected %u", u, 16); c = conf_get_char (conf, "c group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\0', "Got %c expected %c", c, '\0'); bf = conf_get_bool (conf, "c group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "c group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "c group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, "c group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, " Not Default") == 0, "Got %d expected 'Not Default", s); i = conf_get_int (conf, "d group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 100, "Got %d expected %d", i, 100); u = conf_get_uint (conf, "d group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 100, "Got %u expected %u", u, 100); c = conf_get_char (conf, "d group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\07', "Got %c expected %c", c, '\07'); bf = conf_get_bool (conf, "d group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "d group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "d group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 100.0f) < 0.0001f, "Got %f expected %f", f, +100.0f); s = conf_get_string (conf, "d group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "\b\v\t\n\r\f\a\\\?\'\"\x10\010") == 0, "Got %d expected 'Not Default", s); i = conf_get_int (conf, "e group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == -100, "Got %d expected %d", i, -100); u = conf_get_uint (conf, "e group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 0, "Got %u expected %u", u, 0); c = conf_get_char (conf, "e group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\t', "Got %c expected %c", c, '\t'); bf = conf_get_bool (conf, "e group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "e group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "e group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f + 100) < 0.0001f, "Got %f expected %f", f, -100.0f); s = conf_get_string (conf, "e group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strlen (s) == 0, "Got '%s' expected ''", s); conf_free (conf); }
bool ArdbConfig::Parse(const Properties& props) { conf_props = props; conf_get_string(props, "home", home); if (home.empty()) { home = "../ardb"; } make_dir(home); int err = real_path(home, home); if (0 != err) { ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } err = access(home.c_str(), R_OK | W_OK); if (0 != err) { err = errno; ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } setenv("ARDB_HOME", home.c_str(), 1); replace_env_var(const_cast<Properties&>(props)); conf_get_string(props, "pidfile", pidfile); conf_get_int64(props, "tcp-keepalive", tcp_keepalive); conf_get_int64(props, "timeout", timeout); conf_get_int64(props, "unixsocketperm", unixsocketperm); conf_get_int64(props, "slowlog-log-slower-than", slowlog_log_slower_than); conf_get_int64(props, "slowlog-max-len", slowlog_max_len); conf_get_int64(props, "maxclients", max_clients); Properties::const_iterator listen_it = props.find("listen"); if (listen_it != props.end()) { const ConfItemsArray& cs = listen_it->second; for (uint32 i = 0; i < cs.size(); i++) { if (cs[i].size() != 1) { WARN_LOG("Invalid config 'listen'"); } else { const std::string& str = cs[i][0]; listen_addresses.push_back(str); } } } if (listen_addresses.empty()) { listen_addresses.push_back("0.0.0.0:16379"); } Properties::const_iterator tp_it = props.find("thread-pool-size"); if (tp_it != props.end()) { const ConfItemsArray& cs = tp_it->second; for (uint32 i = 0; i < cs.size(); i++) { uint32 size = 0; if (cs[i].size() != 1 || !string_touint32(cs[i][0], size)) { WARN_LOG("Invalid config 'thread-pool-size'"); } else { thread_pool_sizes.push_back((int64) size); } } } Properties::const_iterator qp_it = props.find("qps-limit"); if (qp_it != props.end()) { const ConfItemsArray& cs = qp_it->second; for (uint32 i = 0; i < cs.size(); i++) { uint32 limit = 0; if (cs[i].size() != 1 || !string_touint32(cs[i][0], limit)) { WARN_LOG("Invalid config 'qps-limit'"); } else { qps_limits.push_back((int64) limit); } } } thread_pool_sizes.resize(listen_addresses.size()); qps_limits.resize(listen_addresses.size()); conf_get_string(props, "data-dir", data_base_path); conf_get_string(props, "backup-dir", backup_dir); conf_get_string(props, "repl-dir", repl_data_dir); make_dir(repl_data_dir); make_dir(backup_dir); err = real_path(repl_data_dir, repl_data_dir); if (0 != err) { ERROR_LOG("Invalid 'repl-dir' config:%s for reason:%s", repl_data_dir.c_str(), strerror(err)); return false; } std::string backup_file_format; conf_get_string(props, "backup-file-format", backup_file_format); if (!strcasecmp(backup_file_format.c_str(), "redis")) { backup_redis_format = true; } conf_get_string(props, "zookeeper-servers", zookeeper_servers); conf_get_string(props, "loglevel", loglevel); conf_get_string(props, "logfile", logfile); conf_get_bool(props, "daemonize", daemonize); conf_get_int64(props, "repl-backlog-size", repl_backlog_size); conf_get_int64(props, "repl-ping-slave-period", repl_ping_slave_period); conf_get_int64(props, "repl-timeout", repl_timeout); conf_get_int64(props, "repl-state-persist-period", repl_state_persist_period); conf_get_int64(props, "repl-backlog-ttl", repl_backlog_time_limit); conf_get_bool(props, "repl-disable-tcp-nodelay", repl_disable_tcp_nodelay); conf_get_int64(props, "lua-time-limit", lua_time_limit); conf_get_int64(props, "hash-max-ziplist-entries", hash_max_ziplist_entries); conf_get_int64(props, "hash_max-ziplist-value", hash_max_ziplist_value); conf_get_int64(props, "set-max-ziplist-entries", set_max_ziplist_entries); conf_get_int64(props, "set-max-ziplist-value", set_max_ziplist_value); conf_get_int64(props, "list-max-ziplist-entries", list_max_ziplist_entries); conf_get_int64(props, "list-max-ziplist-value", list_max_ziplist_value); conf_get_int64(props, "zset-max-ziplist-entries", zset_max_ziplist_entries); conf_get_int64(props, "zset_max_ziplist_value", zset_max_ziplist_value); conf_get_int64(props, "L1-zset-max-cache-size", L1_zset_max_cache_size); conf_get_int64(props, "L1-set-max-cache-size", L1_set_max_cache_size); conf_get_int64(props, "L1-hash-max-cache-size", L1_hash_max_cache_size); conf_get_int64(props, "L1-list-max-cache-size", L1_list_max_cache_size); conf_get_int64(props, "L1-string-max-cache-size", L1_string_max_cache_size); conf_get_bool(props, "L1-zset-read-fill-cache", L1_zset_read_fill_cache); conf_get_bool(props, "L1-zset-seek-load-cache", L1_zset_seek_load_cache); conf_get_bool(props, "L1-set-read-fill-cache", L1_set_read_fill_cache); conf_get_bool(props, "L1-set-seek-load-cache", L1_set_seek_load_cache); conf_get_bool(props, "L1-hash-read-fill-cache", L1_hash_read_fill_cache); conf_get_bool(props, "L1-hash-seek-load-cache", L1_hash_seek_load_cache); conf_get_bool(props, "L1-list-read-fill-cache", L1_list_read_fill_cache); conf_get_bool(props, "L1-list-seek-load-cache", L1_list_seek_load_cache); conf_get_bool(props, "L1-string-read-fill-cache", L1_string_read_fill_cache); conf_get_int64(props, "hll-sparse-max-bytes", hll_sparse_max_bytes); conf_get_bool(props, "slave-read-only", slave_readonly); conf_get_bool(props, "slave-serve-stale-data", slave_serve_stale_data); conf_get_int64(props, "slave-priority", slave_priority); conf_get_bool(props, "slave-ignore-expire", slave_ignore_expire); conf_get_bool(props, "slave-ignore-del", slave_ignore_del); std::string slaveof; if (conf_get_string(props, "slaveof", slaveof)) { std::vector<std::string> ss = split_string(slaveof, ":"); if (ss.size() == 2) { master_host = ss[0]; if (!string_touint32(ss[1], master_port)) { master_host = ""; WARN_LOG("Invalid 'slaveof' config."); } } else { WARN_LOG("Invalid 'slaveof' config."); } } std::string include_dbs, exclude_dbs; repl_includes.clear(); repl_excludes.clear(); conf_get_string(props, "replicate-include-db", include_dbs); conf_get_string(props, "replicate-exclude-db", exclude_dbs); if (0 != split_uint32_array(include_dbs, "|", repl_includes)) { ERROR_LOG("Invalid 'replicate-include-db' config."); repl_includes.clear(); } if (0 != split_uint32_array(exclude_dbs, "|", repl_excludes)) { ERROR_LOG("Invalid 'replicate-exclude-db' config."); repl_excludes.clear(); } if (data_base_path.empty()) { data_base_path = "."; } make_dir(data_base_path); err = real_path(data_base_path, data_base_path); if (0 != err) { ERROR_LOG("Invalid 'data-dir' config:%s for reason:%s", data_base_path.c_str(), strerror(err)); return false; } conf_get_string(props, "additional-misc-info", additional_misc_info); conf_get_string(props, "requirepass", requirepass); Properties::const_iterator fit = props.find("rename-command"); if (fit != props.end()) { rename_commands.clear(); StringSet newcmdset; const ConfItemsArray& cs = fit->second; ConfItemsArray::const_iterator cit = cs.begin(); while (cit != cs.end()) { if (cit->size() != 2 || newcmdset.count(cit->at(1)) > 0) { ERROR_LOG("Invalid 'rename-command' config."); } else { rename_commands[cit->at(0)] = cit->at(1); newcmdset.insert(cit->at(1)); } cit++; } } conf_get_int64(props, "compact-min-interval", compact_min_interval); conf_get_int64(props, "compact-max-interval", compact_max_interval); conf_get_int64(props, "compact-after-write", compact_trigger_write_count); conf_get_bool(props, "compact-enable", compact_enable); conf_get_int64(props, "reply-pool-size", reply_pool_size); conf_get_bool(props, "replace-all-for-multi-sadd", replace_for_multi_sadd); conf_get_bool(props, "replace-all-for-hmset", replace_for_hmset); conf_get_int64(props, "slave-client-output-buffer-limit", slave_client_output_buffer_limit); conf_get_int64(props, "pubsub-client-output-buffer-limit", pubsub_client_output_buffer_limit); conf_get_bool(props, "scan-redis-compatible", scan_redis_compatible); conf_get_int64(props, "scan-cursor-expire-after", scan_cursor_expire_after); conf_get_int64(props, "max-string-bitset-value", max_string_bitset_value); conf_get_int64(props, "databases", maxdb); conf_get_bool(props, "lua-exec-atomic", lua_exec_atomic); trusted_ip.clear(); Properties::const_iterator ip_it = props.find("trusted-ip"); if (ip_it != props.end()) { const ConfItemsArray& cs = ip_it->second; for (uint32 i = 0; i < cs.size(); i++) { trusted_ip.insert(cs[i][0]); } } if (!verify_config(*this)) { return false; } ArdbLogger::SetLogLevel(loglevel); return true; }
/*{{{ application_finish_initialization_and_run */ static gint application_finish_initialization_and_run (Application *app) { struct sigaction sigact; /*{{{ create Pools */ // create ClientPool for reading operations app->read_client_pool = client_pool_create (app, conf_get_int (app->conf, "pool.readers"), http_connection_create, http_connection_destroy, http_connection_set_on_released_cb, http_connection_check_rediness, http_connection_get_stats_info_caption, http_connection_get_stats_info_data ); if (!app->read_client_pool) { LOG_err (APP_LOG, "Failed to create ClientPool !"); application_exit (app); return -1; } // create ClientPool for writing operations app->write_client_pool = client_pool_create (app, conf_get_int (app->conf, "pool.writers"), http_connection_create, http_connection_destroy, http_connection_set_on_released_cb, http_connection_check_rediness, http_connection_get_stats_info_caption, http_connection_get_stats_info_data ); if (!app->write_client_pool) { LOG_err (APP_LOG, "Failed to create ClientPool !"); application_exit (app); return -1; } // create ClientPool for various operations app->ops_client_pool = client_pool_create (app, conf_get_int (app->conf, "pool.operations"), http_connection_create, http_connection_destroy, http_connection_set_on_released_cb, http_connection_check_rediness, http_connection_get_stats_info_caption, http_connection_get_stats_info_data ); if (!app->ops_client_pool) { LOG_err (APP_LOG, "Failed to create ClientPool !"); application_exit (app); return -1; } /*}}}*/ /*{{{ CacheMng */ app->cmng = cache_mng_create (app); if (!app->cmng) { LOG_err (APP_LOG, "Failed to create CacheMng !"); application_exit (app); return -1; } /*}}}*/ /*{{{ DirTree*/ app->dir_tree = dir_tree_create (app); if (!app->dir_tree) { LOG_err (APP_LOG, "Failed to create DirTree !"); application_exit (app); return -1; } /*}}}*/ /*{{{ FUSE*/ app->rfuse = rfuse_new (app, conf_get_string (app->conf, "app.mountpoint"), app->fuse_opts); if (!app->rfuse) { LOG_err (APP_LOG, "Failed to create FUSE fs ! Mount point: %s", conf_get_string (app->conf, "app.mountpoint")); application_exit (app); return -1; } /*}}}*/ // set global App variable _app = app; /*{{{ signal handlers*/ // SIGINT app->sigint_ev = evsignal_new (app->evbase, SIGINT, sigint_cb, app); event_add (app->sigint_ev, NULL); // SIGSEGV sigact.sa_sigaction = sigsegv_cb; sigact.sa_flags = (int)SA_RESETHAND | SA_SIGINFO; sigemptyset (&sigact.sa_mask); if (sigaction (SIGSEGV, &sigact, (struct sigaction *) NULL) != 0) { LOG_err (APP_LOG, "error setting signal handler for %d (%s)\n", SIGSEGV, strsignal(SIGSEGV)); application_exit (app); return 1; } // SIGTERM app->sigterm_ev = evsignal_new (app->evbase, SIGTERM, sigterm_cb, app); event_add (app->sigterm_ev, NULL); // SIGABRT sigact.sa_sigaction = sigsegv_cb; sigact.sa_flags = (int)SA_RESETHAND | SA_SIGINFO; sigemptyset (&sigact.sa_mask); if (sigaction (SIGABRT, &sigact, (struct sigaction *) NULL) != 0) { LOG_err (APP_LOG, "error setting signal handler for %d (%s)\n", SIGABRT, strsignal(SIGABRT)); application_exit (app); return 1; } // SIGPIPE app->sigpipe_ev = evsignal_new (app->evbase, SIGPIPE, sigpipe_cb, app); event_add (app->sigpipe_ev, NULL); // SIGUSR1 app->sigusr1_ev = evsignal_new (app->evbase, SIGUSR1, sigusr1_cb, app); event_add (app->sigusr1_ev, NULL); // SIGUSR2 app->sigusr2_ev = evsignal_new (app->evbase, SIGUSR2, sigusr2_cb, app); event_add (app->sigusr2_ev, NULL); /*}}}*/ if (!conf_get_boolean (app->conf, "app.foreground")) fuse_daemonize (0); return 0; }
END_TEST START_TEST (test_conf_errors) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; /* * Test Add group errors. */ conf = conf_create (); fail_unless (conf != 0); /* Add group to non conf. */ ret = conf_add_group (NULL, NULL, head_group); fail_unless (ret == -1); conf_free (conf); /* Add two groups with no group name under root. */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == -1); conf_free (conf); /* Add group with bad parameter type. */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, bad_1_group); fail_unless (ret < 0); conf_free (conf); /* * Test load errors. */ conf = conf_create (); fail_unless (conf != 0); /* Load with no groups. */ ret = conf_load (conf, CONFDIR "test.conf"); fail_unless (ret == -1); /* Test filename. */ ret = conf_add_group (conf, "a group", head_group); fail_unless (ret == 0); ret = conf_load (conf, NULL); fail_unless (ret == -1); ret = conf_load (conf, "/dev/null/something"); fail_unless (ret == -1); /* Test group names. */ ret = conf_load (conf, CONFDIR "test_bad1.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad2.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad3.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad4.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad5.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad6.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad7.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad8.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad9.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad10.conf"); fail_unless (ret != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_load (conf, CONFDIR "test_bad11.conf"); fail_unless (ret == -15, "%d", ret); ret = conf_load (conf, CONFDIR "test_bad12.conf"); fail_unless (ret == -13); ret = conf_load (conf, CONFDIR "test_bad13.conf"); fail_unless (ret != -14); ret = conf_load (conf, CONFDIR "test_bad14.conf"); fail_unless (ret == -17, "%d", ret); conf_free (conf); /* Test getting values */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, "a group", head_group); fail_unless (ret == 0); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 0); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 0); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 0); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 0); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 0); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 0); i = conf_get_int (conf, "a group", "X_int", &valid); fail_unless (valid == 0); u = conf_get_uint (conf, "a group", "X_uint", &valid); fail_unless (valid == 0); c = conf_get_char (conf, "a group", "X_char", &valid); fail_unless (valid == 0); bf = conf_get_bool (conf, "a group", "X_bool_false", &valid); fail_unless (valid == 0); bt = conf_get_bool (conf, "a group", "X_bool_true", &valid); fail_unless (valid == 0); f = conf_get_float (conf, "a group", "X_float", &valid); fail_unless (valid == 0); s = conf_get_string (conf, "a group", "X_string", &valid); fail_unless (valid == 0); conf_free (conf); }
/*{{{ main */ int main (int argc, char *argv[]) { Application *app; gboolean verbose = FALSE; gboolean version = FALSE; GError *error = NULL; GOptionContext *context; gchar **s_params = NULL; gchar **s_config = NULL; gboolean foreground = FALSE; gchar conf_str[1023]; struct stat st; gchar **cache_dir = NULL; gchar **s_fuse_opts = NULL; gchar **s_log_file = NULL; guint32 part_size = 0; gboolean disable_syslog = FALSE; gboolean disable_stats = FALSE; gboolean force_head_requests = FALSE; gint uid = -1; gint gid = -1; gint fmode = -1; gint dmode = -1; struct event_config *ev_config; srand (time (NULL)); app = g_new0 (Application, 1); app->conf_path = g_build_filename (SYSCONFDIR, "riofs.conf.xml", NULL); g_snprintf (conf_str, sizeof (conf_str), "Path to configuration file. Default: %s", app->conf_path); GOptionEntry entries[] = { { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &s_params, NULL, NULL }, { "config", 'c', 0, G_OPTION_ARG_FILENAME_ARRAY, &s_config, conf_str, NULL}, { "uid", 0, 0, G_OPTION_ARG_INT, &uid, "Set UID of filesystem owner.", NULL }, { "gid", 0, 0, G_OPTION_ARG_INT, &gid, "Set GID of filesystem owner.", NULL }, { "fmode", 0, 0, G_OPTION_ARG_INT, &fmode, "Set mode for all files.", NULL }, { "dmode", 0, 0, G_OPTION_ARG_INT, &dmode, "Set mode for all directories.", NULL }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Flag. Do not daemonize process.", NULL }, { "cache-dir", 0, 0, G_OPTION_ARG_STRING_ARRAY, &cache_dir, "Set cache directory.", NULL }, { "fuse-options", 'o', 0, G_OPTION_ARG_STRING_ARRAY, &s_fuse_opts, "Fuse options.", "\"opt[,opt...]\"" }, { "disable-syslog", 0, 0, G_OPTION_ARG_NONE, &disable_syslog, "Flag. Disable logging to syslog.", NULL }, { "disable-stats", 0, 0, G_OPTION_ARG_NONE, &disable_stats, "Flag. Disable Statistics HTTP interface.", NULL }, { "part-size", 0, 0, G_OPTION_ARG_INT, &part_size, "Set file part size (in bytes).", NULL }, { "log-file", 'l', 0, G_OPTION_ARG_STRING_ARRAY, &s_log_file, "File to write output.", NULL }, { "force-head-requests", 0, 0, G_OPTION_ARG_NONE, &force_head_requests, "Flag. Send HEAD request for each file.", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output.", NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &version, "Show application version and exit.", NULL }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; // init libraries CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free); ENGINE_load_builtin_engines (); ENGINE_register_all_complete (); ERR_load_crypto_strings (); OpenSSL_add_all_algorithms (); #ifdef SSL_ENABLED SSL_load_error_strings (); SSL_library_init (); #endif g_random_set_seed (time (NULL)); // init main app structure ev_config = event_config_new (); #if defined(__APPLE__) // method select is the preferred method on OS X. kqueue and poll are not supported. event_config_avoid_method (ev_config, "kqueue"); event_config_avoid_method (ev_config, "poll"); #endif app->evbase = event_base_new_with_config (ev_config); event_config_free (ev_config); if (!app->evbase) { LOG_err (APP_LOG, "Failed to create event base !"); application_destroy (app); return -1; } app->dns_base = evdns_base_new (app->evbase, 1); if (!app->dns_base) { LOG_err (APP_LOG, "Failed to create DNS base !"); application_destroy (app); return -1; } app->f_log = NULL; app->log_file_name = NULL; /*{{{ cmd line args */ // parse command line options context = g_option_context_new ("[bucketname] [mountpoint]"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_description (context, "Please set both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables!"); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_fprintf (stderr, "Failed to parse command line options: %s\n", error->message); application_destroy (app); g_option_context_free (context); return -1; } g_option_context_free (context); // check if --version is specified if (version) { g_fprintf (stdout, "RioFS File System v%s\n", VERSION); g_fprintf (stdout, "Copyright (C) 2012-2014 Paul Ionkin <*****@*****.**>\n"); g_fprintf (stdout, "Copyright (C) 2012-2014 Skoobe GmbH. All rights reserved.\n"); g_fprintf (stdout, "Libraries:\n"); g_fprintf (stdout, " GLib: %d.%d.%d libevent: %s fuse: %d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION, LIBEVENT_VERSION, FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION ); #if defined(__APPLE__) || defined(__FreeBSD__) || !defined(__GLIBC__) g_fprintf (stdout, "\n"); #else g_fprintf (stdout, " glibc: %s\n", gnu_get_libc_version ()); #endif g_fprintf (stdout, "Features:\n"); g_fprintf (stdout, " libevent backend method: %s\n", event_base_get_method(app->evbase)); #ifdef SSL_ENABLED g_fprintf (stdout, " SSL enabled\n"); #endif /* { int i; const char **methods = event_get_supported_methods (); g_fprintf (stdout, " Available libevent backend methods:\n"); for (i = 0; methods[i] != NULL; ++i) { g_fprintf (stdout, " %s\n", methods[i]); } } */ return 0; } if (!s_params || g_strv_length (s_params) != 2) { LOG_err (APP_LOG, "Wrong number of provided arguments!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } if (verbose) log_level = LOG_debug; else log_level = LOG_msg; /*}}}*/ /*{{{ parse config file */ // user provided alternative config path if (s_config && g_strv_length (s_config) > 0) { g_free (app->conf_path); app->conf_path = g_strdup (s_config[0]); g_strfreev (s_config); } app->conf = conf_create (); if (access (app->conf_path, R_OK) == 0) { LOG_debug (APP_LOG, "Using config file: %s", app->conf_path); if (!conf_parse_file (app->conf, app->conf_path)) { LOG_err (APP_LOG, "Failed to parse configuration file: %s", app->conf_path); application_destroy (app); return -1; } } else { LOG_err (APP_LOG, "Configuration file is not found !"); application_destroy (app); return -1; } if (!conf_check_keys (app->conf, conf_keys_str, conf_keys_len)) { LOG_err (APP_LOG, "Configuration file is missing keys, please re-check your configuration file: %s", app->conf_path); application_destroy (app); return -1; } if (disable_syslog) { conf_set_boolean (app->conf, "log.use_syslog", FALSE); } // update logging settings logger_set_syslog (conf_get_boolean (app->conf, "log.use_syslog")); logger_set_color (conf_get_boolean (app->conf, "log.use_color")); if (cache_dir && g_strv_length (cache_dir) > 0) { conf_set_string (app->conf, "filesystem.cache_dir", cache_dir[0]); g_strfreev (cache_dir); } if (!verbose) log_level = conf_get_int (app->conf, "log.level"); if (uid >= 0) conf_set_int (app->conf, "filesystem.uid", uid); if (gid >= 0) conf_set_int (app->conf, "filesystem.gid", gid); if (fmode >= 0) conf_set_int (app->conf, "filesystem.file_mode", fmode); if (dmode >= 0) conf_set_int (app->conf, "filesystem.dir_mode", dmode); /*}}}*/ // try to get access parameters from the environment if (getenv ("AWS_ACCESS_KEY_ID")) { conf_set_string (app->conf, "s3.access_key_id", getenv ("AWS_ACCESS_KEY_ID")); // else check if it's set it the config file } else { if (!conf_node_exists (app->conf, "s3.access_key_id")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } if (getenv ("AWS_SECRET_ACCESS_KEY")) { conf_set_string (app->conf, "s3.secret_access_key", getenv ("AWS_SECRET_ACCESS_KEY")); } else { if (!conf_node_exists (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } // check if both strings are set if (!conf_get_string (app->conf, "s3.access_key_id") || !conf_get_string (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } // foreground is set if (foreground) conf_set_boolean (app->conf, "app.foreground", foreground); if (part_size) conf_set_uint (app->conf, "s3.part_size", part_size); if (disable_stats) conf_set_boolean (app->conf, "statistics.enabled", FALSE); if (force_head_requests) conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", TRUE); else conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", FALSE); conf_set_string (app->conf, "s3.bucket_name", s_params[0]); if (!application_set_url (app, conf_get_string (app->conf, "s3.endpoint"))) { application_destroy (app); return -1; } if (s_fuse_opts && g_strv_length (s_fuse_opts) > 0) { app->fuse_opts = g_strdup (s_fuse_opts[0]); g_strfreev (s_fuse_opts); } if (s_log_file && g_strv_length (s_log_file) > 0) { app->log_file_name = g_strdup (s_log_file[0]); app->f_log = fopen (s_log_file[0], "a+"); if (!app->f_log) { LOG_err (APP_LOG, "Failed to open log file: %s Error: %s", s_log_file[0], strerror (errno)); application_destroy (app); return -1; } LOG_debug (APP_LOG, "Using %s for storing application logs.", s_log_file[0]); logger_set_file (app->f_log); g_strfreev (s_log_file); } conf_set_string (app->conf, "app.mountpoint", s_params[1]); // check if directory exists if (stat (conf_get_string (app->conf, "app.mountpoint"), &st) == -1) { LOG_err (APP_LOG, "Mountpoint %s does not exist! Please check directory permissions!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } // check if it's a directory if (!S_ISDIR (st.st_mode)) { LOG_err (APP_LOG, "Mountpoint %s is not a directory!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } g_strfreev (s_params); #ifdef SSL_ENABLED app->ssl_ctx = SSL_CTX_new (SSLv23_client_method ()); if (!app->ssl_ctx) { LOG_err (APP_LOG, "Failed to initialize SSL engine !"); application_exit (app); return -1; } SSL_CTX_set_options (app->ssl_ctx, SSL_OP_ALL); #endif #ifdef MAGIC_ENABLED app->magic_ctx = magic_open(MAGIC_MIME_TYPE); if (!app->magic_ctx) { LOG_err(APP_LOG, "Failed to initialize magic library\n"); return -1; } if (magic_load(app->magic_ctx, NULL)) { LOG_err(APP_LOG, "Failed to load magic database: %s\n", magic_error(app->magic_ctx)); magic_close(app->magic_ctx); return -1; } #endif app->stat_srv = stat_srv_create (app); if (!app->stat_srv) { application_exit (app); return -1; } // perform the initial request to get bucket ACL (handles redirect as well) app->service_con = http_connection_create (app); if (!app->service_con) { application_destroy (app); return -1; } bucket_client_get (app->service_con, "/?acl", application_on_bucket_acl_cb, app); // start the loop event_base_dispatch (app->evbase); application_destroy (app); return 0; }
bool ArdbConfig::Parse(const Properties& props) { conf_props = props; conf_get_string(props, "home", home); if (home.empty()) { home = "../ardb"; } make_dir(home); int err = real_path(home, home); if (0 != err) { ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } err = access(home.c_str(), R_OK | W_OK); if (0 != err) { err = errno; ERROR_LOG("Invalid 'home' config:%s for reason:%s", home.c_str(), strerror(err)); return false; } setenv("ARDB_HOME", home.c_str(), 1); replace_env_var(const_cast<Properties&>(props)); conf_get_string(props, "pidfile", pidfile); conf_get_int64(props, "thread-pool-size", thread_pool_size); if (thread_pool_size <= 0) { thread_pool_size = available_processors(); } conf_get_int64(props, "hz", hz); if (hz < CONFIG_MIN_HZ) hz = CONFIG_MIN_HZ; if (hz > CONFIG_MAX_HZ) hz = CONFIG_MAX_HZ; conf_get_int64(props, "tcp-keepalive", tcp_keepalive); conf_get_int64(props, "timeout", timeout); //conf_get_int64(props, "unixsocketperm", unixsocketperm); conf_get_int64(props, "slowlog-log-slower-than", slowlog_log_slower_than); conf_get_int64(props, "slowlog-max-len", slowlog_max_len); conf_get_int64(props, "maxclients", max_clients); if(max_clients <= 0) { max_clients = 10000; } for (int i = 0;; i++) { char config_key[256]; sprintf(config_key, "server[%d].listen", i); ListenPoint lp; std::string address; if (!conf_get_string(props, config_key, address)) { break; } if (address.find(":") == std::string::npos) { lp.host = address; } else { std::vector<std::string> ss = split_string(address, ":"); uint32 port; if (ss.size() < 2 || !string_touint32(ss[ss.size() - 1], port) || port > 65535) { ERROR_LOG("Invalid listen address %s", address.c_str()); return false; } lp.host = address.substr(0, address.size() - ss[ss.size() - 1].size() - 1); lp.port = port; } sprintf(config_key, "server[%d].qps-limit", i); conf_get_int64(props, config_key, lp.qps_limit); sprintf(config_key, "server[%d].unixsocketperm", i); conf_get_int64(props, config_key, lp.qps_limit); servers.push_back(lp); } if (servers.empty()) { ListenPoint lp; lp.host = "0.0.0.0"; lp.port = 16379; servers.push_back(lp); } if (strcasecmp(engine.c_str(), "rocksdb") == 0) { conf_get_string(props, "rocksdb.compaction", rocksdb_compaction); conf_get_bool(props, "rocksdb.disableWAL", rocksdb_disablewal); conf_get_bool(props, "rocksdb.scan-total-order", rocksdb_scan_total_order); } conf_get_string(props, "engine", engine); conf_get_string(props, "data-dir", data_base_path); conf_get_string(props, "backup-dir", backup_dir); conf_get_string(props, "repl-dir", repl_data_dir); make_dir(repl_data_dir); make_dir(backup_dir); err = real_path(repl_data_dir, repl_data_dir); if (0 != err) { ERROR_LOG("Invalid 'repl-dir' config:%s for reason:%s", repl_data_dir.c_str(), strerror(err)); return false; } std::string backup_file_format; conf_get_string(props, "backup-file-format", backup_file_format); if (!strcasecmp(backup_file_format.c_str(), "redis")) { backup_redis_format = true; } conf_get_string(props, "zookeeper-servers", zookeeper_servers); conf_get_string(props, "zk-clientid-file", zk_clientid_file); conf_get_string(props, "loglevel", loglevel); conf_get_string(props, "logfile", logfile); conf_get_bool(props, "daemonize", daemonize); conf_get_int64(props, "repl-backlog-size", repl_backlog_size); conf_get_int64(props, "repl-backlog-cache-size", repl_backlog_cache_size); conf_get_int64(props, "repl-ping-slave-period", repl_ping_slave_period); conf_get_int64(props, "repl-timeout", repl_timeout); conf_get_int64(props, "repl-backlog-sync-period", repl_backlog_sync_period); conf_get_int64(props, "repl-backlog-ttl", repl_backlog_time_limit); conf_get_int64(props, "min-slaves-to-write", repl_min_slaves_to_write); conf_get_int64(props, "min-slaves-max-lag", repl_min_slaves_max_lag); conf_get_bool(props, "slave-serve-stale-data", repl_serve_stale_data); conf_get_int64(props, "max-slave-worker-queue", max_slave_worker_queue); if(max_slave_worker_queue <= 0) { max_slave_worker_queue = 1024; } conf_get_bool(props, "repl-disable-tcp-nodelay", repl_disable_tcp_nodelay); conf_get_int64(props, "lua-time-limit", lua_time_limit); conf_get_int64(props, "snapshot-max-lag-offset", snapshot_max_lag_offset); conf_get_int64(props, "maxsnapshots", maxsnapshots); if(maxsnapshots == 0) { maxsnapshots = 1; } if (snapshot_max_lag_offset > repl_backlog_size / 2) { snapshot_max_lag_offset = repl_backlog_size / 2; } conf_get_int64(props, "hll-sparse-max-bytes", hll_sparse_max_bytes); conf_get_bool(props, "slave-read-only", slave_readonly); conf_get_bool(props, "slave-serve-stale-data", slave_serve_stale_data); conf_get_int64(props, "slave-priority", slave_priority); conf_get_bool(props, "slave-ignore-expire", slave_ignore_expire); conf_get_bool(props, "slave-ignore-del", slave_ignore_del); conf_get_bool(props, "slave-cleardb-before-fullresync", slave_cleardb_before_fullresync); conf_get_int64(props, "statistics-log-period", statistics_log_period); if (statistics_log_period <= 0) { statistics_log_period = DEFAULT_STAT_LOG_PERIOD_SECS; } std::string slaveof; if (conf_get_string(props, "slaveof", slaveof)) { std::vector<std::string> ss = split_string(slaveof, ":"); if (ss.size() == 2) { master_host = ss[0]; if (!string_touint32(ss[1], master_port)) { master_host = ""; WARN_LOG("Invalid 'slaveof' config."); } } else { WARN_LOG("Invalid 'slaveof' config."); } } conf_get_string(props, "masterauth", masterauth); if (data_base_path.empty()) { data_base_path = "."; } make_dir(data_base_path); err = real_path(data_base_path, data_base_path); if (0 != err) { ERROR_LOG("Invalid 'data-dir' config:%s for reason:%s", data_base_path.c_str(), strerror(err)); return false; } conf_get_string(props, "requirepass", requirepass); Properties::const_iterator fit = props.find("rename-command"); if (fit != props.end()) { rename_commands.clear(); const ConfItemsArray& cs = fit->second; ConfItemsArray::const_iterator cit = cs.begin(); while (cit != cs.end()) { if (cit->size() != 2) { ERROR_LOG("Invalid 'rename-command' config with %u args.", cit->size()); } else { rename_commands[cit->at(0)] = cit->at(1); } cit++; } } conf_get_int64(props, "reply-pool-size", reply_pool_size); conf_get_int64(props, "slave-client-output-buffer-limit", slave_client_output_buffer_limit); conf_get_int64(props, "pubsub-client-output-buffer-limit", pubsub_client_output_buffer_limit); conf_get_string(props, "redis-compatible-version", redis_compatible_version); conf_get_bool(props, "redis-compatible-mode", redis_compatible); conf_get_bool(props, "compact-after-snapshot-load", compact_after_snapshot_load); conf_get_int64(props, "qps-limit-per-host", qps_limit_per_host); conf_get_int64(props, "qps-limit-per-connection", qps_limit_per_connection); conf_get_int64(props, "range-delete-min-size", range_delete_min_size); conf_get_int64(props, "stream-lru-cache-size", stream_lru_cache_size); //trusted_ip.clear(); Properties::const_iterator ip_it = props.find("trusted-ip"); if (ip_it != props.end()) { const ConfItemsArray& cs = ip_it->second; for (uint32 i = 0; i < cs.size(); i++) { //trusted_ip.insert(cs[i][0]); } } if (!verify_config(*this)) { return false; } ArdbLogger::SetLogLevel(loglevel); return true; }
void LMDBEngineFactory::ParseConfig(const Properties& props, LMDBConfig& cfg) { cfg.path = "."; conf_get_string(props, "data-dir", cfg.path); }