X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fconf-context.c;h=050e43baaf47fc218e83f74aaf20479d83d14eeb;hb=f17e4350dcf0c033891e52b30b0c32a4a4fed5e0;hp=dc74b66a9509d724bb6f2d3df75b174983906bec;hpb=0ca8c151f5afe1680e98f3bfbe9d5c752d8a2924;p=libucw.git diff --git a/ucw/conf-context.c b/ucw/conf-context.c index dc74b66a..050e43ba 100644 --- a/ucw/conf-context.c +++ b/ucw/conf-context.c @@ -12,27 +12,31 @@ #include #include -#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); } @@ -53,31 +57,16 @@ cf_switch_context(struct cf_context *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(); }