#include <ucw/conf-internal.h>
#include <ucw/threads.h>
-#ifndef CONFIG_UCW_DEFAULT_CONFIG
-#define CONFIG_UCW_DEFAULT_CONFIG NULL
-#endif
+static struct cf_context cf_default_context;
-#ifndef CONFIG_UCW_ENV_VAR_CONFIG
-#define CONFIG_UCW_ENV_VAR_CONFIG NULL
-#endif
+static void
+cf_init_context(struct cf_context *cc)
+{
+ cc->enable_journal = 1;
+ clist_init(&cc->conf_entries);
+}
struct cf_context *
cf_new_context(void)
{
struct cf_context *cc = xmalloc_zero(sizeof(*cc));
- cc->need_journal = 1;
- clist_init(&cc->conf_entries);
+ cf_init_context(cc);
return cc;
}
void
-cf_free_context(struct cf_context *cc)
+cf_delete_context(struct cf_context *cc)
{
ASSERT(!cc->is_active);
+ ASSERT(cc != &cf_default_context);
+ struct cf_context *prev = cf_switch_context(cc);
+ cf_revert();
+ cf_switch_context(prev);
xfree(cc->parser);
xfree(cc);
}
return prev;
}
-struct cf_context *
-cf_obtain_context(void)
+static void CONSTRUCTOR_WITH_PRIORITY(10100)
+cf_init_default_context(void)
{
- struct ucwlib_context *uc = ucwlib_thread_context();
- if (unlikely(!uc->cf_context))
- {
- struct cf_context *cc = cf_new_context();
- uc->cf_context = cc;
- cc->def_file = CONFIG_UCW_DEFAULT_CONFIG;
- cc->env_file = CONFIG_UCW_ENV_VAR_CONFIG;
- cc->is_active = 1;
- }
- return uc->cf_context;
-}
-
-void
-cf_set_default_file(char *name)
-{
- struct cf_context *cc = cf_obtain_context();
- cc->def_file = name;
+ cf_init_context(&cf_default_context);
+ ucwlib_thread_context()->cf_context = &cf_default_context;
+ cf_default_context.is_active = 1;
}
-void
-cf_set_env_override(char *name)
+struct cf_context *
+cf_obtain_context(void)
{
- struct cf_context *cc = cf_obtain_context();
- cc->env_file = name;
+ return cf_get_context();
}