Browse code

CFG_READONLY flag is introduced. Variables marked with this flag can be stored in the configuration framework even if they are read-only.

Miklos Tirpak authored on 13/10/2008 14:09:18
Showing 3 changed files
... ...
@@ -53,6 +53,8 @@
53 53
 
54 54
 /* atomic change is allowed */
55 55
 #define CFG_ATOMIC		(1U<<(2*CFG_INPUT_SHIFT))
56
+/* variable is read-only */
57
+#define CFG_READONLY		(1U<<(2*CFG_INPUT_SHIFT+1))
56 58
 
57 59
 typedef int (*cfg_on_change)(void *, str *, void **);
58 60
 typedef void (*cfg_on_set_child)(str *);
... ...
@@ -274,6 +274,12 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, str *var_name,
274 274
 	/* look-up the group and the variable */
275 275
 	if (cfg_lookup_var(group_name, var_name, &group, &var))
276 276
 		return 1;
277
+		
278
+	/* check whether the variable is read-only */
279
+	if (var->def->type & CFG_READONLY) {
280
+		LOG(L_ERR, "ERROR: cfg_set_now(): variable is read-only\n");
281
+		goto error0;
282
+	}
277 283
 
278 284
 	/* check whether we have to convert the type */
279 285
 	if (convert_val(val_type, val, CFG_INPUT_TYPE(var), &v))
... ...
@@ -513,6 +519,12 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
513 513
 	if (cfg_lookup_var(group_name, var_name, &group, &var))
514 514
 		return 1;
515 515
 
516
+	/* check whether the variable is read-only */
517
+	if (var->def->type & CFG_READONLY) {
518
+		LOG(L_ERR, "ERROR: cfg_set_delayed(): variable is read-only\n");
519
+		goto error0;
520
+	}
521
+
516 522
 	/* check whether we have to convert the type */
517 523
 	if (convert_val(val_type, val, CFG_INPUT_TYPE(var), &v))
518 524
 		goto error0;
... ...
@@ -117,6 +117,9 @@ Each row consists of the following items:
117 117
 				It can be used only with CFG_VAR_INT type,
118 118
 				and per-child process callback is not allowed
119 119
 
120
+	- CFG_READONLY		The variable is read-only, its value cannot
121
+				be changed.
122
+
120 123
 - minimum value for integers (optional)
121 124
 - maximum value for integers (optional)
122 125
 - fixup function (optional) that is called when the variable is going to be