Forráskód Böngészése

- Updating the local configuration in the child processes that are
forked by modules.

- Per-child process config destroy function is introduced:
should be called when a child process exists, but SER continues
running, not needed to be called otherwise.

Miklos Tirpak 18 éve
szülő
commit
f20a809de3
2 módosított fájl, 45 hozzáadás és 0 törlés
  1. 35 0
      cfg/cfg_struct.c
  2. 10 0
      cfg/cfg_struct.h

+ 35 - 0
cfg/cfg_struct.c

@@ -302,6 +302,41 @@ int cfg_child_init(void)
 	return 0;
 }
 
+/* per-child process destroy function
+ * Should be called only when the child process exits,
+ * but SER continues running
+ *
+ * WARNING: this function call must be the very last action
+ * before the child process exits, because the local config
+ * is not available afterwards.
+ */
+void cfg_child_destroy(void)
+{
+	/* unref the local config */
+	if (cfg_local) {
+		CFG_UNREF(cfg_local);
+		cfg_local = NULL;
+	}
+
+	/* unref the per-process callback list */
+	if (atomic_dec_and_test(&cfg_child_cb->refcnt)) {
+		/* No more pocess refers to this callback.
+		Did this process block the deletion,
+		or is there any other process that has not
+		reached	prev_cb yet? */
+		CFG_LOCK();
+		if (*cfg_child_cb_first == cfg_child_cb) {
+			/* yes, this process was blocking the deletion */
+			*cfg_child_cb_first = cfg_child_cb->next;
+			CFG_UNLOCK();
+			shm_free(cfg_child_cb);
+		} else {
+			CFG_UNLOCK();
+		}
+	}
+	cfg_child_cb = NULL;
+}
+
 /* searches a variable definition by group and variable name */
 int cfg_lookup_var(str *gname, str *vname,
 			cfg_group_t **group, cfg_mapping_t **var)

+ 10 - 0
cfg/cfg_struct.h

@@ -123,6 +123,16 @@ void cfg_destroy(void);
 /* per-child process init function */
 int cfg_child_init(void);
 
+/* per-child process destroy function
+ * Should be called only when the child process exits,
+ * but SER continues running.
+ *
+ * WARNING: this function call must be the very last action
+ * before the child process exits, because the local config
+ * is not available afterwards.
+ */
+void cfg_child_destroy(void);
+
 /* creates a new cfg group, and adds it to the linked list */
 int cfg_new_group(char *name, int num, cfg_mapping_t *mapping,
 		char *vars, int size, void **handle);