static void
cf_init_context(struct cf_context *cc)
{
- cc->need_journal = 1;
+ cc->enable_journal = 1;
clist_init(&cc->conf_entries);
}
void
cf_free_context(struct cf_context *cc)
{
- // FIXME: Roll back all transactions
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);
}
static void
cf_remember_entry(struct cf_context *cc, uns type, const char *arg)
{
- if (!cc->need_journal)
+ if (!cc->enable_journal)
return;
struct conf_entry *ce = cf_malloc(sizeof(*ce));
ce->type = type;
cf_reload(const char *file)
{
struct cf_context *cc = cf_get_context();
+ ASSERT(cc->enable_journal);
cf_journal_swap();
struct cf_journal_item *oldj = cf_journal_new_transaction(1);
uns ec = cc->everything_committed;
cf_journal_rollback_transaction(0, oldj);
return err;
}
+
+void
+cf_revert(void)
+{
+ cf_journal_swap();
+ cf_journal_delete();
+}
uns other_options; // used internally by cf_getopt()
clist conf_entries; // files/strings to reload
struct cf_journal_item *journal; // journalling
- int need_journal;
+ int enable_journal;
struct old_pools *pools;
struct item_stack stack[MAX_STACK_SIZE]; // interpreter stack
uns stack_level;
{
struct cf_context *cc = cf_get_context();
ASSERT(!cc->journal);
- cc->need_journal = enable;
+ cc->enable_journal = enable;
}
void
cf_journal_block(void *ptr, uns len)
{
struct cf_context *cc = cf_get_context();
- if (!cc->need_journal)
+ if (!cc->enable_journal)
return;
struct cf_journal_item *ji = cf_malloc(sizeof(struct cf_journal_item) + len);
ji->prev = cc->journal;
cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj)
{
struct cf_context *cc = cf_get_context();
- if (!cc->need_journal)
- die("Cannot rollback the configuration, because the journal is disabled.");
+ if (!cc->enable_journal)
+ return;
cf_journal_swap();
cc->journal = oldj;
if (new_pool)
mp_delete(p->pool);
}
}
-
-/* TODO: more space efficient journal */
* Insane tester of reading configuration files
*
* (c) 2006 Robert Spalek <robert@ucw.cz>
+ * (c) 2012 Martin Mares <mj@ucw.cz>
*/
#include <ucw/lib.h>
#include <time.h>
static int verbose;
-static int new_context;
static int reload;
struct sub_sect_1 {
};
static char *help = "\
-Usage: conf-test [ctxt] <options>\n\
+Usage: conf-test [ctxt] [nojournal] <options>\n\
\n\
Options:\n" CF_USAGE "\
-r, --reload\t\tReload configuration\n\
main(int argc, char *argv[])
{
log_init(argv[0]);
-
struct cf_context *cc = NULL, *prev = NULL;
- if (argc > 1 && !strcmp(argv[1], "ctxt")) {
- cc = cf_new_context();
- prev = cf_switch_context(cc);
- argc--, argv++;
+
+ // Special arguments which have to be parsed before cf_getopt()
+ while (argc > 1) {
+ if (!strcmp(argv[1], "ctxt")) {
+ cc = cf_new_context();
+ prev = cf_switch_context(cc);
+ argc--, argv++;
+ } else if (!strcmp(argv[1], "nojournal")) {
+ cf_set_journalling(0);
+ argc--, argv++;
+ } else
+ break;
}
cf_declare_section("top", &cf_top, 0);
int opt;
while ((opt = cf_getopt(argc, argv, short_opts, long_opts, NULL)) >= 0)
switch (opt) {
- case 'n': new_context++; break;
case 'r': reload++; break;
case 'v': verbose++; break;
default: usage("unknown option %c\n", opt);
bclose(out);
}
- if (new_context) {
+ if (cc) {
cf_switch_context(prev);
cf_free_context(cc);
}
+ printf("%08x\n", ip);
+
return 0;
}
* configuration specified in the file are undone.
**/
int cf_load(const char *file);
+
/**
* Reload configuration from @file, replace the old one.
* If @file is NULL, reload all loaded configuration files and re-apply
* settings are rolled back to the state before calling this function.
**/
int cf_reload(const char *file);
+
/**
* Parse some part of configuration passed in @string.
* The syntax is the same as in the <<config:,configuration file>>.
**/
int cf_close_group(void);
+/**
+ * Return all configuration items to their initial state before loading the
+ * configuration file. If journalling is disabled, it does nothing.
+ **/
+void cf_revert(void);
+
/*** === Data types [[conf_types]] ***/
enum cf_class { /** Class of the configuration item. **/