X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fconf-section.c;h=bbd3416426ef5ddc643928cfb739cd07bf34102f;hb=a3da5079c1c4d0bd98f78b7dcc18634579837057;hp=4908ca6e4e77912358b30e5837a84ea29a0c7a29;hpb=4a1e23ef2fadbb534fda085be26da0bc34690641;p=libucw.git diff --git a/lib/conf-section.c b/lib/conf-section.c index 4908ca6e..bbd34164 100644 --- a/lib/conf-section.c +++ b/lib/conf-section.c @@ -91,7 +91,7 @@ inspect_section(struct cf_section *sec) } else if (ci->cls == CC_LIST) { inspect_section(ci->u.sec); sec->flags |= SEC_FLAG_DYNAMIC | SEC_FLAG_CANT_COPY; - } else if (ci->cls == CC_DYNAMIC) + } else if (ci->cls == CC_DYNAMIC || ci->cls == CC_BITMAP) sec->flags |= SEC_FLAG_DYNAMIC; else if (ci->cls == CC_PARSER) { sec->flags |= SEC_FLAG_CANT_COPY; @@ -138,11 +138,18 @@ cf_init_section(byte *name, struct cf_section *sec, void *ptr, uns do_bzero) ASSERT(sec->size); bzero(ptr, sec->size); } - for (uns i=0; sec->cfg[i].cls; i++) - if (sec->cfg[i].cls == CC_SECTION) - cf_init_section(sec->cfg[i].name, sec->cfg[i].u.sec, ptr + (addr_int_t) sec->cfg[i].ptr, 0); - else if (sec->cfg[i].cls == CC_LIST) - clist_init(ptr + (addr_int_t) sec->cfg[i].ptr); + for (struct cf_item *ci=sec->cfg; ci->cls; ci++) + if (ci->cls == CC_SECTION) + cf_init_section(ci->name, ci->u.sec, ptr + (uintptr_t) ci->ptr, 0); + else if (ci->cls == CC_LIST) + clist_init(ptr + (uintptr_t) ci->ptr); + else if (ci->cls == CC_DYNAMIC) { + void **dyn = ptr + (uintptr_t) ci->ptr; + if (!*dyn) { // replace NULL by an empty array + static uns zero = 0; + *dyn = (&zero) + 1; + } + } if (sec->init) { byte *msg = sec->init(ptr); if (msg) @@ -150,40 +157,24 @@ cf_init_section(byte *name, struct cf_section *sec, void *ptr, uns do_bzero) } } -static void -replace_null_dary(struct cf_item *item, void **ptr) -{ - static u64 zero = 0; - if (*ptr) - return; - uns size = cf_type_size(item->type, item->u.utype); - cf_journal_block(ptr, sizeof(void*)); - if (size <= sizeof(zero)) - *ptr = (&zero) + 1; - else - *ptr = cf_malloc_zero(size) + size; -} - static byte * commit_section(struct cf_section *sec, void *ptr, uns commit_all) { - struct cf_item *ci; byte *err; - for (ci=sec->cfg; ci->cls; ci++) + for (struct cf_item *ci=sec->cfg; ci->cls; ci++) if (ci->cls == CC_SECTION) { - if ((err = commit_section(ci->u.sec, ptr + (addr_int_t) ci->ptr, commit_all))) { + if ((err = commit_section(ci->u.sec, ptr + (uintptr_t) ci->ptr, commit_all))) { log(L_ERROR, "Cannot commit section %s: %s", ci->name, err); return "commit of a subsection failed"; } } else if (ci->cls == CC_LIST) { uns idx = 0; - CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (addr_int_t) ci->ptr)) + CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (uintptr_t) ci->ptr)) if (idx++, err = commit_section(ci->u.sec, n, commit_all)) { log(L_ERROR, "Cannot commit node #%d of list %s: %s", idx, ci->name, err); return "commit of a list failed"; } - } else if (ci->cls == CC_DYNAMIC) - replace_null_dary(ci, ptr + (addr_int_t) ci->ptr); + } if (sec->commit) { /* We have to process the whole tree of sections even if just a few changes * have been made, because there are dependencies between commit-hooks and