Browse code

Merge 69b5bb39c7c47bb1970335c7fb0da813a7747d73 into 5e617b5e2130ed96f624e027023329433f8814ee

aalba6675 authored on 19/11/2021 14:13:22 • GitHub committed on 19/11/2021 14:13:22
Showing 2 changed files
... ...
@@ -148,6 +148,7 @@ void ksr_module_set_flag(unsigned int flag);
148 148
 #define PROC_FIFO      PROC_RPC  /**< FIFO attendant process */
149 149
 #define PROC_TCP_MAIN -4  /**< TCP main process */
150 150
 #define PROC_UNIXSOCK -5  /**< Unix socket server */
151
+#define PROC_POST_FORK -6  /**< Main process after all children are forked */
151 152
 #define PROC_ATTENDANT -10  /**< main "attendant process */
152 153
 #define PROC_POSTCHILDINIT -126  /**< special rank - main kamailio process after
153 154
 									after all child_init() are executed */
... ...
@@ -1489,6 +1489,14 @@ int main_loop(void)
1489 1489
 			goto error;
1490 1490
 		}
1491 1491
 
1492
+
1493
+		/* call it also w/ PROC_POST_FORK to make sure modules that cleanup
1494
+		 * post-fork get a chance to run */
1495
+		if (init_child(PROC_POST_FORK) < 0) {
1496
+			LM_ERR("init_child(PROC_POST_FORK) -- exiting\n");
1497
+			goto error;
1498
+		}
1499
+
1492 1500
 		/* We will call child_init even if we
1493 1501
 		 * do not fork - and it will be called with rank 1 because
1494 1502
 		 * in fact we behave like a child, not like main process
... ...
@@ -1862,6 +1870,13 @@ int main_loop(void)
1862 1870
 		}
1863 1871
 #endif
1864 1872
 		/* main */
1873
+
1874
+		/* hook for modules(in main process only) to do post-fork cleanup */
1875
+		if (init_child(PROC_POST_FORK) < 0) {
1876
+			LM_ERR("init_child(PROC_POST_FORK) -- exiting\n");
1877
+			goto error;
1878
+		}
1879
+
1865 1880
 		strncpy(pt[0].desc, "main process - attendant", MAX_PT_DESC );
1866 1881
 #ifdef USE_TCP
1867 1882
 		close_extra_socks(PROC_ATTENDANT, get_proc_no());