Explorar o código

cfg framework: support for no per-child callbacks procs

Support for using the config framework from processes that
cannot or do not need to execute cfg per-child callbacks.
For example a process that only monitors some cfg values that do
not involve per-child callbacks, does not ever need to execute
one.

Signed-off-by: Miklos Tirpak <[email protected]>
Andrei Pelinescu-Onciul %!s(int64=16) %!d(string=hai) anos
pai
achega
4a9a969de8
Modificáronse 2 ficheiros con 33 adicións e 1 borrados
  1. 17 1
      cfg/cfg_struct.c
  2. 16 0
      cfg/cfg_struct.h

+ 17 - 1
cfg/cfg_struct.c

@@ -418,6 +418,22 @@ int cfg_late_child_init(void)
 	return 0;
 	return 0;
 }
 }
 
 
+
+/* per-child init function for non-cb executing processes.
+ * Mark this process as not wanting to execute any per-child config
+ * callback (it will have only limited config functionality, but is useful
+ * when a process needs only to watch some non-callback cfg. values,
+ * e.g. the main attendant process, debug and memlog).
+ * It needs to be called from the forked process.
+ * cfg_register_child must _not_ be called.
+ */
+int cfg_child_no_cb_init(void)
+{
+	/* set the callback list pointer to the beginning of the list */
+	cfg_child_cb = CFG_NO_CHILD_CBS;
+	return 0;
+}
+
 /* per-child process destroy function
 /* per-child process destroy function
  * Should be called only when the child process exits,
  * Should be called only when the child process exits,
  * but SER continues running
  * but SER continues running
@@ -436,7 +452,7 @@ void cfg_child_destroy(void)
 		cfg_local = NULL;
 		cfg_local = NULL;
 	}
 	}
 
 
-	if (!cfg_child_cb) return;
+	if (!cfg_child_cb || cfg_child_cb==CFG_NO_CHILD_CBS) return;
 
 
 	/* The lock must be held to make sure that the global config
 	/* The lock must be held to make sure that the global config
 	is not replaced meantime, and the other child processes do not
 	is not replaced meantime, and the other child processes do not

+ 16 - 0
cfg/cfg_struct.h

@@ -120,6 +120,10 @@ extern cfg_child_cb_t	**cfg_child_cb_first;
 extern cfg_child_cb_t	**cfg_child_cb_last;
 extern cfg_child_cb_t	**cfg_child_cb_last;
 extern cfg_child_cb_t	*cfg_child_cb;
 extern cfg_child_cb_t	*cfg_child_cb;
 
 
+/* magic value for cfg_child_cb for processes that do not want to
+   execute per-child callbacks */
+#define CFG_NO_CHILD_CBS ((void*)(long)(-1))
+
 /* macros for easier variable access */
 /* macros for easier variable access */
 #define CFG_VAR_TYPE(var)	CFG_VAR_MASK((var)->def->type)
 #define CFG_VAR_TYPE(var)	CFG_VAR_MASK((var)->def->type)
 #define CFG_INPUT_TYPE(var)	CFG_INPUT_MASK((var)->def->type)
 #define CFG_INPUT_TYPE(var)	CFG_INPUT_MASK((var)->def->type)
@@ -149,6 +153,16 @@ int cfg_child_init(void);
  */
  */
 int cfg_late_child_init(void);
 int cfg_late_child_init(void);
 
 
+/* per-child init function for non-cb executing processes.
+ * Mark this process as not wanting to execute any per-child config
+ * callback (it will have only limited config functionality, but is useful
+ * when a process needs only to watch some non-callback cfg. values,
+ * e.g. the main attendant process, debug and memlog).
+ * It needs to be called from the forked process.
+ * cfg_register_child must _not_ be called.
+ */
+int cfg_child_no_cb_init(void);
+
 /* per-child process destroy function
 /* per-child process destroy function
  * Should be called only when the child process exits,
  * Should be called only when the child process exits,
  * but SER continues running.
  * but SER continues running.
@@ -233,6 +247,8 @@ static inline void cfg_update_local(void)
 	)
 	)
 		*(group->handle) = cfg_local->vars + group->offset;
 		*(group->handle) = cfg_local->vars + group->offset;
 
 
+	if (unlikely(cfg_child_cb==CFG_NO_CHILD_CBS))
+		return;
 	/* call the per-process callbacks */
 	/* call the per-process callbacks */
 	while (cfg_child_cb != last_cb) {
 	while (cfg_child_cb != last_cb) {
 		prev_cb = cfg_child_cb;
 		prev_cb = cfg_child_cb;