Browse code

cfg framework: safety checks added

Verify that the child process has a local configuration
in the functions that work with config group instances.

Miklos Tirpak authored on 03/06/2011 12:37:03
Showing 1 changed files
... ...
@@ -1100,26 +1100,28 @@ void cfg_move_handle(cfg_group_t *group, cfg_group_inst_t *src_ginst, cfg_group_
1100 1100
 				dst_ginst->vars
1101 1101
 				: CFG_GROUP_DATA(cfg_local, group);
1102 1102
 
1103
-	/* call the per child process callback of those variables
1104
-	that have different value in the two group instances */
1105
-	/* TODO: performance optimization: this entire loop can be
1106
-	skipped if the group does not have any variable with
1107
-	per-child process callback. Use some flag in the group
1108
-	structure for this purpose. */
1109
-	gname.s = group->name;
1110
-	gname.len = group->name_len;
1111
-	for (i = 0; i < CFG_MAX_VAR_NUM/(sizeof(int)*8); i++) {
1112
-		bitmap = ((src_ginst) ? src_ginst->set[i] : 0U)
1113
-			| ((dst_ginst) ? dst_ginst->set[i] : 0U);
1114
-		while (bitmap) {
1115
-			pos = bit_scan_forward32(bitmap);
1116
-			var = &group->mapping[pos + i*sizeof(int)*8];
1117
-			if (var->def->on_set_child_cb) {
1118
-				vname.s = var->def->name;
1119
-				vname.len = var->name_len;
1120
-				var->def->on_set_child_cb(&gname, &vname);
1103
+	if (cfg_child_cb != CFG_NO_CHILD_CBS) {
1104
+		/* call the per child process callback of those variables
1105
+		that have different value in the two group instances */
1106
+		/* TODO: performance optimization: this entire loop can be
1107
+		skipped if the group does not have any variable with
1108
+		per-child process callback. Use some flag in the group
1109
+		structure for this purpose. */
1110
+		gname.s = group->name;
1111
+		gname.len = group->name_len;
1112
+		for (i = 0; i < CFG_MAX_VAR_NUM/(sizeof(int)*8); i++) {
1113
+			bitmap = ((src_ginst) ? src_ginst->set[i] : 0U)
1114
+				| ((dst_ginst) ? dst_ginst->set[i] : 0U);
1115
+			while (bitmap) {
1116
+				pos = bit_scan_forward32(bitmap);
1117
+				var = &group->mapping[pos + i*sizeof(int)*8];
1118
+				if (var->def->on_set_child_cb) {
1119
+					vname.s = var->def->name;
1120
+					vname.len = var->name_len;
1121
+					var->def->on_set_child_cb(&gname, &vname);
1122
+				}
1123
+				bitmap -= (1U << pos);
1121 1124
 			}
1122
-			bitmap -= (1U << pos);
1123 1125
 		}
1124 1126
 	}
1125 1127
 	/* 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)
1140 1142
 {
1141 1143
 	cfg_group_inst_t	*ginst;
1142 1144
 
1145
+	if (!cfg_local) {
1146
+		LOG(L_ERR, "ERROR: The child process has no local configuration\n");
1147
+		return -1;
1148
+	}
1149
+
1143 1150
 	if (!(ginst = cfg_find_group(CFG_GROUP_META(cfg_local, group),
1144 1151
 				group->size,
1145 1152
 				id))
... ...
@@ -1161,6 +1168,11 @@ int cfg_select(cfg_group_t *group, unsigned int id)
1161 1168
 /* Reset the group handle to the default, local configuration */
1162 1169
 int cfg_reset(cfg_group_t *group)
1163 1170
 {
1171
+	if (!cfg_local) {
1172
+		LOG(L_ERR, "ERROR: The child process has no local configuration\n");
1173
+		return -1;
1174
+	}
1175
+
1164 1176
 	cfg_move_handle(group,
1165 1177
 			CFG_HANDLE_TO_GINST(*(group->handle)), /* the active group instance */
1166 1178
 			NULL);
... ...
@@ -1183,6 +1195,11 @@ int cfg_select_first(cfg_group_t *group)
1183 1195
 	cfg_group_meta_t	*meta;
1184 1196
 	cfg_group_inst_t	*ginst;
1185 1197
 
1198
+	if (!cfg_local) {
1199
+		LOG(L_ERR, "ERROR: The child process has no local configuration\n");
1200
+		return -1;
1201
+	}
1202
+
1186 1203
 	meta = CFG_GROUP_META(cfg_local, group);
1187 1204
 	if (!meta || (meta->num == 0))
1188 1205
 		return -1;
... ...
@@ -1212,6 +1229,11 @@ int cfg_select_next(cfg_group_t *group)
1212 1229
 	cfg_group_inst_t	*old_ginst, *new_ginst;
1213 1230
 	int	size;
1214 1231
 
1232
+	if (!cfg_local) {
1233
+		LOG(L_ERR, "ERROR: The child process has no local configuration\n");
1234
+		return -1;
1235
+	}
1236
+
1215 1237
 	if (!(meta = CFG_GROUP_META(cfg_local, group)))
1216 1238
 		return -1;
1217 1239