void Reconfig() { contact_schedd_interval = param_integer ("C_GAHP_CONTACT_SCHEDD_DELAY", 5); useXMLClassads = param_boolean( "GAHP_USE_XML_CLASSADS", false ); // When GSI authentication is used, we're willing to trust schedds // which have the same credential as the job if ( proxySubjectName ) { char *daemon_subjects = param( "GSI_DAEMON_NAME" ); if ( daemon_subjects ) { std::string buff; formatstr( buff, "%s,%s", daemon_subjects, proxySubjectName ); dprintf( D_ALWAYS, "Setting %s=%s\n", "GSI_DAEMON_NAME", buff.c_str() ); // We must use our daemon subsystem prefix in case the // admin used it in the config file. config_insert( "C_GAHP_WORKER_THREAD.GSI_DAEMON_NAME", buff.c_str() ); free( daemon_subjects ); } } }
void config_setstring(struct config *config, const char *str, const char *fmt, ...) { struct KeyValuePair *e; char key[1024]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof key, fmt, ap); va_end(ap); e = config_get(config, key); if (e) { ASSERT(e->type == CONFIG_KV_STRING || e->type == CONFIG_KV_UNKNOWN); free(e->u.str); e->u.str = NULL; } else { e = safe_malloc(sizeof *e); e->key = safe_strdup(key); e->type = CONFIG_KV_STRING; config_insert(config, e); } e->save = 1; e->u.str = str ? safe_strdup(str) : NULL; }
void config_setbool(struct config *config, bool s, const char *fmt, ...) { struct KeyValuePair *e; char key[1024]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof key, fmt, ap); va_end(ap); e = config_get(config, key); if (e) { if (e->type == CONFIG_KV_UNKNOWN) { free(e->u.str); e->u.str = NULL; } else { ASSERT(e->type == CONFIG_KV_BOOL); } } else { e = safe_malloc(sizeof *e); e->key = safe_strdup(key); e->type = CONFIG_KV_BOOL; config_insert(config, e); } e->save = 1; e->u.trueOrFalse = s; }
static void config_setunknownkv(struct config *config, const char *key, const char *val) { struct KeyValuePair *e; e = safe_malloc(sizeof *e); e->key = safe_strdup(key); e->u.str = safe_strdup(val); e->type = CONFIG_KV_UNKNOWN; e->save = 1; config_insert(config, e); }
int config_read(server *srv, const char *fn) { config_t context; data_config *dc; data_integer *dpid; data_string *dcwd; int ret; char *pos; data_array *modules; context_init(srv, &context); context.all_configs = srv->config_context; #ifdef __WIN32 pos = strrchr(fn, '\\'); #else pos = strrchr(fn, '/'); #endif if (pos) { buffer_copy_string_len(context.basedir, fn, pos - fn + 1); fn = pos + 1; } dc = data_config_init(); buffer_copy_string_len(dc->key, CONST_STR_LEN("global")); assert(context.all_configs->used == 0); dc->context_ndx = context.all_configs->used; array_insert_unique(context.all_configs, (data_unset *)dc); context.current = dc; /* default context */ srv->config = dc->value; dpid = data_integer_init(); dpid->value = getpid(); buffer_copy_string_len(dpid->key, CONST_STR_LEN("var.PID")); array_insert_unique(srv->config, (data_unset *)dpid); dcwd = data_string_init(); buffer_prepare_copy(dcwd->value, 1024); if (NULL != getcwd(dcwd->value->ptr, dcwd->value->size - 1)) { dcwd->value->used = strlen(dcwd->value->ptr) + 1; buffer_copy_string_len(dcwd->key, CONST_STR_LEN("var.CWD")); array_insert_unique(srv->config, (data_unset *)dcwd); } ret = config_parse_file(srv, &context, fn); /* remains nothing if parser is ok */ assert(!(0 == ret && context.ok && 0 != context.configs_stack->used)); context_free(&context); if (0 != ret) { return ret; } if (NULL != (dc = (data_config *)array_get_element(srv->config_context, "global"))) { srv->config = dc->value; } else { return -1; } if (NULL != (modules = (data_array *)array_get_element(srv->config, "server.modules"))) { data_string *ds; data_array *prepends; if (modules->type != TYPE_ARRAY) { fprintf(stderr, "server.modules must be an array"); return -1; } prepends = data_array_init(); /* prepend default modules */ if (NULL == array_get_element(modules->value, "mod_indexfile")) { ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile")); array_insert_unique(prepends->value, (data_unset *)ds); } prepends = (data_array *)configparser_merge_data((data_unset *)prepends, (data_unset *)modules); buffer_copy_string_buffer(prepends->key, modules->key); array_replace(srv->config, (data_unset *)prepends); modules->free((data_unset *)modules); modules = prepends; /* append default modules */ if (NULL == array_get_element(modules->value, "mod_dirlisting")) { ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting")); array_insert_unique(modules->value, (data_unset *)ds); } if (NULL == array_get_element(modules->value, "mod_staticfile")) { ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile")); array_insert_unique(modules->value, (data_unset *)ds); } } else { data_string *ds; modules = data_array_init(); /* server.modules is not set */ ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile")); array_insert_unique(modules->value, (data_unset *)ds); ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting")); array_insert_unique(modules->value, (data_unset *)ds); ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile")); array_insert_unique(modules->value, (data_unset *)ds); buffer_copy_string_len(modules->key, CONST_STR_LEN("server.modules")); array_insert_unique(srv->config, (data_unset *)modules); } if (0 != config_insert(srv)) { return -1; } return 0; }