Browse code

cfg framework: fix shutdown crash for non registered modules

Added cfg_update_no_cbs() which partially updates (no per-child
callbacks are called) the local config.
It's needed for config update on exit (SIGTERM) for modules that
do not register as cfg users and when the code is compiled with
SIG_DEBUG.

Andrei Pelinescu-Onciul authored on 06/10/2009 10:47:14
Showing 2 changed files
... ...
@@ -219,8 +219,10 @@ static inline void cfg_block_free(cfg_block_t *block)
219 219
 /* updates all the module handles and calls the
220 220
  * per-child process callbacks -- not intended to be used
221 221
  * directly, use cfg_update() instead!
222
+ * params:
223
+ *   no_cbs - if 1, do not call per child callbacks
222 224
  */
223
-static inline void cfg_update_local(void)
225
+static inline void cfg_update_local(int no_cbs)
224 226
 {
225 227
 	cfg_group_t	*group;
226 228
 	cfg_child_cb_t	*last_cb;
... ...
@@ -247,7 +249,7 @@ static inline void cfg_update_local(void)
247 247
 	)
248 248
 		*(group->handle) = cfg_local->vars + group->offset;
249 249
 
250
-	if (unlikely(cfg_child_cb==CFG_NO_CHILD_CBS))
250
+	if (unlikely(cfg_child_cb==CFG_NO_CHILD_CBS || no_cbs))
251 251
 		return;
252 252
 	/* call the per-process callbacks */
253 253
 	while (cfg_child_cb != last_cb) {
... ...
@@ -287,7 +289,17 @@ static inline void cfg_update_local(void)
287 287
 #define cfg_update() \
288 288
 	do { \
289 289
 		if (unlikely(cfg_local != *cfg_global)) \
290
-			cfg_update_local(); \
290
+			cfg_update_local(0); \
291
+	} while(0)
292
+
293
+/* like cfg_update(), but does not execute callbacks
294
+ * (it should be used sparingly only in special cases, since it
295
+ *  breaks an important cfg framework feature)
296
+ */
297
+#define cfg_update_no_cbs() \
298
+	do { \
299
+		if (unlikely(cfg_local != *cfg_global)) \
300
+			cfg_update_local(1); \
291 301
 	} while(0)
292 302
 
293 303
 /* searches a group by name */
... ...
@@ -779,7 +779,11 @@ void sig_usr(int signo)
779 779
 					LOG(L_INFO, "INFO: signal %d received\n", signo);
780 780
 					/* print memory stats for non-main too */
781 781
 					#ifdef PKG_MALLOC
782
-					cfg_update(); /* make sure we have current values */
782
+					/* make sure we have current cfg values, but update only
783
+					  the safe part (values not requiring callbacks), to
784
+					  account for processes that might not have registered
785
+					  config support */
786
+					cfg_update_no_cbs();
783 787
 					memlog=cfg_get(core, core_cfg, memlog);
784 788
 					if (memlog <= cfg_get(core, core_cfg, debug)){
785 789
 						if (cfg_get(core, core_cfg, mem_summary) & 1) {