Browse code

app_python3: Python >= 3.7 call PyOS_AfterFork_Parent in main context after all forks

Anthony Alba authored on 22/11/2021 03:46:25
Showing 1 changed files
... ...
@@ -104,7 +104,13 @@ static int mod_init(void)
104 104
 	char *dname_src, *bname_src;
105 105
 	int i;
106 106
 
107
-	if(apy_sr_init_mod()<0) {
107
+	/*
108
+	 * register the need to be called post-fork of all children
109
+	 * with the special rank PROC_POSTCHILDINIT
110
+	 */
111
+	ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT);
112
+
113
+	if (apy_sr_init_mod()<0) {
108 114
 		LM_ERR("failed to init the sr mod\n");
109 115
 		return -1;
110 116
 	}
... ...
@@ -185,6 +191,16 @@ static int child_init(int rank)
185 191
 		 */
186 192
 #if PY_VERSION_HEX >= 0x03070000
187 193
 		PyOS_BeforeFork() ;
194
+#endif
195
+		return 0;
196
+	}
197
+	if(rank==PROC_POSTCHILDINIT) {
198
+		/*
199
+		 * this is called after forking of all child
200
+		 * processes
201
+		 */
202
+#if PY_VERSION_HEX >= 0x03070000
203
+		PyOS_AfterFork_Parent() ;
188 204
 #endif
189 205
 		return 0;
190 206
 	}