Browse Source

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 17 years ago
parent
commit
b9c10056a6
3 changed files with 17 additions and 0 deletions
  1. 2 0
      cfg/cfg.h
  2. 12 0
      cfg/cfg_ctx.c
  3. 3 0
      doc/cfg.txt

+ 2 - 0
cfg/cfg.h

@@ -53,6 +53,8 @@
 
 /* atomic change is allowed */
 #define CFG_ATOMIC		(1U<<(2*CFG_INPUT_SHIFT))
+/* variable is read-only */
+#define CFG_READONLY		(1U<<(2*CFG_INPUT_SHIFT+1))
 
 typedef int (*cfg_on_change)(void *, str *, void **);
 typedef void (*cfg_on_set_child)(str *);

+ 12 - 0
cfg/cfg_ctx.c

@@ -274,6 +274,12 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, str *var_name,
 	/* look-up the group and the variable */
 	if (cfg_lookup_var(group_name, var_name, &group, &var))
 		return 1;
+		
+	/* check whether the variable is read-only */
+	if (var->def->type & CFG_READONLY) {
+		LOG(L_ERR, "ERROR: cfg_set_now(): variable is read-only\n");
+		goto error0;
+	}
 
 	/* check whether we have to convert the type */
 	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,
 	if (cfg_lookup_var(group_name, var_name, &group, &var))
 		return 1;
 
+	/* check whether the variable is read-only */
+	if (var->def->type & CFG_READONLY) {
+		LOG(L_ERR, "ERROR: cfg_set_delayed(): variable is read-only\n");
+		goto error0;
+	}
+
 	/* check whether we have to convert the type */
 	if (convert_val(val_type, val, CFG_INPUT_TYPE(var), &v))
 		goto error0;

+ 3 - 0
doc/cfg.txt

@@ -117,6 +117,9 @@ Each row consists of the following items:
 				It can be used only with CFG_VAR_INT type,
 				and per-child process callback is not allowed
 
+	- CFG_READONLY		The variable is read-only, its value cannot
+				be changed.
+
 - minimum value for integers (optional)
 - maximum value for integers (optional)
 - fixup function (optional) that is called when the variable is going to be