Browse Source

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.
Miklos Tirpak 15 years ago
parent
commit
99b680c32a
2 changed files with 21 additions and 5 deletions
  1. 10 3
      cfg/cfg_ctx.c
  2. 11 2
      cfg/cfg_ctx.h

+ 10 - 3
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);

+ 11 - 2
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,