@@ -290,6 +290,17 @@ extern "C" fn minit(_type: c_int, module_number: c_int) -> ZendResult {
290290 #[ cfg( feature = "exception_profiling" ) ]
291291 exception:: exception_profiling_minit ( ) ;
292292
293+ // There are a few things which need to do something on the first rinit of
294+ // each minit/mshutdown cycle. In Apache, when doing `apachectl graceful`,
295+ // there can be more than one of these cycles per process.
296+ // Re-initializing these on each minit allows us to do it once per cycle.
297+ // This is unsafe generally, but all SAPIs are supposed to only have one
298+ // thread alive during minit, so it should be safe here specifically.
299+ unsafe {
300+ ZAI_CONFIG_ONCE = Once :: new ( ) ;
301+ RINIT_ONCE = Once :: new ( ) ;
302+ }
303+
293304 ZendResult :: Success
294305}
295306
@@ -374,15 +385,20 @@ extern "C" fn activate() {
374385 unsafe { profiling:: activate_run_time_cache ( ) } ;
375386}
376387
388+ /// The mut here is *only* for resetting this back to uninitialized each minit.
389+ static mut ZAI_CONFIG_ONCE : Once = Once :: new ( ) ;
390+ /// The mut here is *only* for resetting this back to uninitialized each minit.
391+ static mut RINIT_ONCE : Once = Once :: new ( ) ;
392+
377393/* If Failure is returned the VM will do a C exit; try hard to avoid that,
378394 * using it for catastrophic errors only.
379395 */
380396extern "C" fn rinit ( _type : c_int , _module_number : c_int ) -> ZendResult {
381397 #[ cfg( debug_assertions) ]
382398 trace ! ( "RINIT({_type}, {_module_number})" ) ;
383399
384- static ONCE : Once = Once :: new ( ) ;
385- ONCE . call_once ( || unsafe {
400+ // SAFETY: not being mutated during rinit.
401+ unsafe { & ZAI_CONFIG_ONCE } . call_once ( || unsafe {
386402 bindings:: zai_config_first_time_rinit ( ) ;
387403 config:: first_rinit ( ) ;
388404 } ) ;
@@ -420,8 +436,7 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
420436 // SAFETY: still safe to access in rinit after first_rinit.
421437 let system_settings = unsafe { system_settings. as_ref ( ) } ;
422438
423- static ONCE2 : Once = Once :: new ( ) ;
424- ONCE2 . call_once ( || {
439+ unsafe { & RINIT_ONCE } . call_once ( || {
425440 if system_settings. profiling_enabled {
426441 /* Safety: sapi_module is initialized by rinit and shouldn't be
427442 * modified at this point (safe to read values).
0 commit comments