[sr-dev] git:master: cfg framework: safety checks added
Miklos Tirpak
miklos at iptel.org
Fri Jun 24 15:14:50 CEST 2011
Module: sip-router
Branch: master
Commit: 2ebc2cac489596f6b19bc1cebf25b57b1b69331c
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2ebc2cac489596f6b19bc1cebf25b57b1b69331c
Author: Miklos Tirpak <miklos at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date: Fri Jun 3 14:37:03 2011 +0200
cfg framework: safety checks added
Verify that the child process has a local configuration
in the functions that work with config group instances.
---
cfg/cfg_struct.c | 60 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/cfg/cfg_struct.c b/cfg/cfg_struct.c
index 6e93ca0..c10dd55 100644
--- a/cfg/cfg_struct.c
+++ b/cfg/cfg_struct.c
@@ -1100,26 +1100,28 @@ void cfg_move_handle(cfg_group_t *group, cfg_group_inst_t *src_ginst, cfg_group_
dst_ginst->vars
: CFG_GROUP_DATA(cfg_local, group);
- /* call the per child process callback of those variables
- that have different value in the two group instances */
- /* TODO: performance optimization: this entire loop can be
- skipped if the group does not have any variable with
- per-child process callback. Use some flag in the group
- structure for this purpose. */
- gname.s = group->name;
- gname.len = group->name_len;
- for (i = 0; i < CFG_MAX_VAR_NUM/(sizeof(int)*8); i++) {
- bitmap = ((src_ginst) ? src_ginst->set[i] : 0U)
- | ((dst_ginst) ? dst_ginst->set[i] : 0U);
- while (bitmap) {
- pos = bit_scan_forward32(bitmap);
- var = &group->mapping[pos + i*sizeof(int)*8];
- if (var->def->on_set_child_cb) {
- vname.s = var->def->name;
- vname.len = var->name_len;
- var->def->on_set_child_cb(&gname, &vname);
+ if (cfg_child_cb != CFG_NO_CHILD_CBS) {
+ /* call the per child process callback of those variables
+ that have different value in the two group instances */
+ /* TODO: performance optimization: this entire loop can be
+ skipped if the group does not have any variable with
+ per-child process callback. Use some flag in the group
+ structure for this purpose. */
+ gname.s = group->name;
+ gname.len = group->name_len;
+ for (i = 0; i < CFG_MAX_VAR_NUM/(sizeof(int)*8); i++) {
+ bitmap = ((src_ginst) ? src_ginst->set[i] : 0U)
+ | ((dst_ginst) ? dst_ginst->set[i] : 0U);
+ while (bitmap) {
+ pos = bit_scan_forward32(bitmap);
+ var = &group->mapping[pos + i*sizeof(int)*8];
+ if (var->def->on_set_child_cb) {
+ vname.s = var->def->name;
+ vname.len = var->name_len;
+ var->def->on_set_child_cb(&gname, &vname);
+ }
+ bitmap -= (1U << pos);
}
- bitmap -= (1U << pos);
}
}
/* keep track of how many group instences are set in the child process */
@@ -1140,6 +1142,11 @@ int cfg_select(cfg_group_t *group, unsigned int id)
{
cfg_group_inst_t *ginst;
+ if (!cfg_local) {
+ LOG(L_ERR, "ERROR: The child process has no local configuration\n");
+ return -1;
+ }
+
if (!(ginst = cfg_find_group(CFG_GROUP_META(cfg_local, group),
group->size,
id))
@@ -1161,6 +1168,11 @@ int cfg_select(cfg_group_t *group, unsigned int id)
/* Reset the group handle to the default, local configuration */
int cfg_reset(cfg_group_t *group)
{
+ if (!cfg_local) {
+ LOG(L_ERR, "ERROR: The child process has no local configuration\n");
+ return -1;
+ }
+
cfg_move_handle(group,
CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
NULL);
@@ -1183,6 +1195,11 @@ int cfg_select_first(cfg_group_t *group)
cfg_group_meta_t *meta;
cfg_group_inst_t *ginst;
+ if (!cfg_local) {
+ LOG(L_ERR, "ERROR: The child process has no local configuration\n");
+ return -1;
+ }
+
meta = CFG_GROUP_META(cfg_local, group);
if (!meta || (meta->num == 0))
return -1;
@@ -1212,6 +1229,11 @@ int cfg_select_next(cfg_group_t *group)
cfg_group_inst_t *old_ginst, *new_ginst;
int size;
+ if (!cfg_local) {
+ LOG(L_ERR, "ERROR: The child process has no local configuration\n");
+ return -1;
+ }
+
if (!(meta = CFG_GROUP_META(cfg_local, group)))
return -1;
More information about the sr-dev
mailing list