Module: sip-router
Branch: tirpi/cfg_framework_multivalue
Commit: 99b680c32a92d5d528b7b4375ed8c2974221bc45
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=99b680c…
Author: Miklos Tirpak <miklos(a)iptel.org>
Committer: Miklos Tirpak <miklos(a)iptel.org>
Date: Tue Sep 14 15:49:25 2010 +0200
cfg framework: error messages added
When a group instance is deleted while there are pending changes
to this instance which are not yet committed, the commit failed
without any error. An error message is added, and cfg_diff_next returns
also error in this case to let the drivers farther propagate the error.
---
cfg/cfg_ctx.c | 13 ++++++++++---
cfg/cfg_ctx.h | 13 +++++++++++--
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/cfg/cfg_ctx.c b/cfg/cfg_ctx.c
index 9413d75..534cf49 100644
--- a/cfg/cfg_ctx.c
+++ b/cfg/cfg_ctx.c
@@ -1027,8 +1027,11 @@ int cfg_commit(cfg_ctx_t *ctx)
group = changed->group;
if (!(CFG_GROUP_META(block, group)->array =
cfg_clone_array(CFG_GROUP_META(*cfg_global, group), group))
- )
+ ) {
+ LOG(L_ERR, "ERROR: cfg_set_now(): group array cannot be cloned for
%.*s[%u]\n",
+ group->name_len, group->name, changed->group_id);
goto error;
+ }
replaced[replaced_num] = CFG_GROUP_META(*cfg_global, group)->array;
replaced_num++;
@@ -1318,6 +1321,10 @@ int cfg_diff_init(cfg_ctx_t *ctx,
/* return the pending changes that have not been
* committed yet
+ * return value:
+ * 1: valid value is found
+ * 0: no more changed value found
+ * -1: error occured
*/
int cfg_diff_next(void **h,
str *gname, unsigned int **gid, str *vname,
@@ -1348,7 +1355,7 @@ int cfg_diff_next(void **h,
} else {
if (!cfg_local) {
LOG(L_ERR, "ERROR: cfg_diff_next(): Local configuration is missing\n");
- return 0;
+ return -1;
}
group_inst = cfg_find_group(CFG_GROUP_META(cfg_local, changed->group),
changed->group->size,
@@ -1356,7 +1363,7 @@ int cfg_diff_next(void **h,
if (!group_inst) {
LOG(L_ERR, "ERROR: cfg_diff_next(): local group instance %.*s[%u] is not
found\n",
changed->group->name_len, changed->group->name, changed->group_id);
- return 0;
+ return -1;
}
pval = (union cfg_var_value*)
(group_inst->vars + changed->var->offset);
diff --git a/cfg/cfg_ctx.h b/cfg/cfg_ctx.h
index 1bfd348..8a0836e 100644
--- a/cfg/cfg_ctx.h
+++ b/cfg/cfg_ctx.h
@@ -157,19 +157,28 @@ int cfg_diff_init(cfg_ctx_t *ctx,
/*! \brief return the pending changes that have not been
* committed yet
+ * return value:
+ * 1: valid value is found
+ * 0: no more changed value found
+ * -1: error occured
+ *
*
* can be used as follows:
*
* void *handle;
* if (cfg_diff_init(ctx, &handle)) return -1
- * while (cfg_diff_next(&handle
+ * while ((err = cfg_diff_next(&handle
* &group_name, &group_id, &var_name,
* &old_val, &new_val
- * &val_type)
+ * &val_type)) > 0
* ) {
* ...
* }
* cfg_diff_release(ctx);
+ * if (err) {
+ * error occured, the changes cannot be retrieved
+ * ...
+ * }
*/
int cfg_diff_next(void **h,
str *gname, unsigned int **gid, str *vname,