@@ -4588,193 +4588,8 @@ static int accel_finish_startup(void)
4588
4588
}
4589
4589
4590
4590
if (ZCG (accel_directives ).preload && * ZCG (accel_directives ).preload ) {
4591
- #ifdef ZEND_WIN32
4592
- zend_accel_error_noreturn (ACCEL_LOG_ERROR , "Preloading is not supported on Windows" );
4591
+ zend_accel_error_noreturn (ACCEL_LOG_ERROR , "Preloading is not supported" );
4593
4592
return FAILURE ;
4594
- #else
4595
- bool in_child = false;
4596
- int ret = SUCCESS ;
4597
- int rc ;
4598
- int orig_error_reporting ;
4599
-
4600
- int (* orig_activate )(void ) = sapi_module .activate ;
4601
- int (* orig_deactivate )(void ) = sapi_module .deactivate ;
4602
- void (* orig_register_server_variables )(zval * track_vars_array ) = sapi_module .register_server_variables ;
4603
- int (* orig_header_handler )(sapi_header_struct * sapi_header , sapi_header_op_enum op , sapi_headers_struct * sapi_headers ) = sapi_module .header_handler ;
4604
- int (* orig_send_headers )(sapi_headers_struct * sapi_headers ) = sapi_module .send_headers ;
4605
- void (* orig_send_header )(sapi_header_struct * sapi_header , void * server_context )= sapi_module .send_header ;
4606
- char * (* orig_getenv )(const char * name , size_t name_len ) = sapi_module .getenv ;
4607
- size_t (* orig_ub_write )(const char * str , size_t str_length ) = sapi_module .ub_write ;
4608
- void (* orig_flush )(void * server_context ) = sapi_module .flush ;
4609
- #ifdef ZEND_SIGNALS
4610
- bool old_reset_signals = SIGG (reset );
4611
- #endif
4612
-
4613
- if (UNEXPECTED (file_cache_only )) {
4614
- zend_accel_error (ACCEL_LOG_WARNING , "Preloading doesn't work in \"file_cache_only\" mode" );
4615
- return SUCCESS ;
4616
- }
4617
-
4618
- /* exclusive lock */
4619
- zend_shared_alloc_lock ();
4620
-
4621
- if (ZCSG (preload_script )) {
4622
- /* Preloading was done in another process */
4623
- preload_load ();
4624
- zend_shared_alloc_unlock ();
4625
- return SUCCESS ;
4626
- }
4627
-
4628
- if (geteuid () == 0 ) {
4629
- pid_t pid ;
4630
- struct passwd * pw ;
4631
-
4632
- if (!ZCG (accel_directives ).preload_user
4633
- || !* ZCG (accel_directives ).preload_user ) {
4634
- zend_shared_alloc_unlock ();
4635
- zend_accel_error_noreturn (ACCEL_LOG_FATAL , "\"opcache.preload_user\" has not been defined" );
4636
- return FAILURE ;
4637
- }
4638
-
4639
- pw = getpwnam (ZCG (accel_directives ).preload_user );
4640
- if (pw == NULL ) {
4641
- zend_shared_alloc_unlock ();
4642
- zend_accel_error_noreturn (ACCEL_LOG_FATAL , "Preloading failed to getpwnam(\"%s\")" , ZCG (accel_directives ).preload_user );
4643
- return FAILURE ;
4644
- }
4645
-
4646
- pid = fork ();
4647
- if (pid == -1 ) {
4648
- zend_shared_alloc_unlock ();
4649
- zend_accel_error_noreturn (ACCEL_LOG_FATAL , "Preloading failed to fork()" );
4650
- return FAILURE ;
4651
- } else if (pid == 0 ) { /* children */
4652
- if (setgid (pw -> pw_gid ) < 0 ) {
4653
- zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to setgid(%d)" , pw -> pw_gid );
4654
- exit (1 );
4655
- }
4656
- if (initgroups (pw -> pw_name , pw -> pw_gid ) < 0 ) {
4657
- zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to initgroups(\"%s\", %d)" , pw -> pw_name , pw -> pw_uid );
4658
- exit (1 );
4659
- }
4660
- if (setuid (pw -> pw_uid ) < 0 ) {
4661
- zend_accel_error (ACCEL_LOG_WARNING , "Preloading failed to setuid(%d)" , pw -> pw_uid );
4662
- exit (1 );
4663
- }
4664
- in_child = true;
4665
- } else { /* parent */
4666
- int status ;
4667
-
4668
- if (waitpid (pid , & status , 0 ) < 0 ) {
4669
- zend_shared_alloc_unlock ();
4670
- zend_accel_error_noreturn (ACCEL_LOG_FATAL , "Preloading failed to waitpid(%d)" , pid );
4671
- return FAILURE ;
4672
- }
4673
-
4674
- if (ZCSG (preload_script )) {
4675
- preload_load ();
4676
- }
4677
-
4678
- zend_shared_alloc_unlock ();
4679
- if (WIFEXITED (status ) && WEXITSTATUS (status ) == 0 ) {
4680
- return SUCCESS ;
4681
- } else {
4682
- return FAILURE ;
4683
- }
4684
- }
4685
- } else {
4686
- if (ZCG (accel_directives ).preload_user
4687
- && * ZCG (accel_directives ).preload_user ) {
4688
- zend_accel_error (ACCEL_LOG_WARNING , "\"opcache.preload_user\" is ignored" );
4689
- }
4690
- }
4691
-
4692
- sapi_module .activate = NULL ;
4693
- sapi_module .deactivate = NULL ;
4694
- sapi_module .register_server_variables = NULL ;
4695
- sapi_module .header_handler = preload_header_handler ;
4696
- sapi_module .send_headers = preload_send_headers ;
4697
- sapi_module .send_header = preload_send_header ;
4698
- sapi_module .getenv = NULL ;
4699
- sapi_module .ub_write = preload_ub_write ;
4700
- sapi_module .flush = preload_flush ;
4701
-
4702
- zend_interned_strings_switch_storage (1 );
4703
-
4704
- #ifdef ZEND_SIGNALS
4705
- SIGG (reset ) = false;
4706
- #endif
4707
-
4708
- orig_error_reporting = EG (error_reporting );
4709
- EG (error_reporting ) = 0 ;
4710
-
4711
- rc = php_request_startup ();
4712
-
4713
- EG (error_reporting ) = orig_error_reporting ;
4714
-
4715
- if (rc == SUCCESS ) {
4716
- bool orig_report_memleaks ;
4717
-
4718
- /* don't send headers */
4719
- SG (headers_sent ) = true;
4720
- SG (request_info ).no_headers = true;
4721
- php_output_set_status (0 );
4722
-
4723
- ZCG (auto_globals_mask ) = 0 ;
4724
- ZCG (request_time ) = (time_t )sapi_get_request_time ();
4725
- ZCG (cache_opline ) = NULL ;
4726
- ZCG (cache_persistent_script ) = NULL ;
4727
- ZCG (include_path_key_len ) = 0 ;
4728
- ZCG (include_path_check ) = true;
4729
-
4730
- ZCG (cwd ) = NULL ;
4731
- ZCG (cwd_key_len ) = 0 ;
4732
- ZCG (cwd_check ) = true;
4733
-
4734
- if (accel_preload (ZCG (accel_directives ).preload , in_child ) != SUCCESS ) {
4735
- ret = FAILURE ;
4736
- }
4737
- preload_flush (NULL );
4738
-
4739
- orig_report_memleaks = PG (report_memleaks );
4740
- PG (report_memleaks ) = false;
4741
- #ifdef ZEND_SIGNALS
4742
- /* We may not have registered signal handlers due to SIGG(reset)=0, so
4743
- * also disable the check that they are registered. */
4744
- SIGG (check ) = false;
4745
- #endif
4746
- php_request_shutdown (NULL ); /* calls zend_shared_alloc_unlock(); */
4747
- PG (report_memleaks ) = orig_report_memleaks ;
4748
- } else {
4749
- zend_shared_alloc_unlock ();
4750
- ret = FAILURE ;
4751
- }
4752
- #ifdef ZEND_SIGNALS
4753
- SIGG (reset ) = old_reset_signals ;
4754
- #endif
4755
-
4756
- sapi_module .activate = orig_activate ;
4757
- sapi_module .deactivate = orig_deactivate ;
4758
- sapi_module .register_server_variables = orig_register_server_variables ;
4759
- sapi_module .header_handler = orig_header_handler ;
4760
- sapi_module .send_headers = orig_send_headers ;
4761
- sapi_module .send_header = orig_send_header ;
4762
- sapi_module .getenv = orig_getenv ;
4763
- sapi_module .ub_write = orig_ub_write ;
4764
- sapi_module .flush = orig_flush ;
4765
-
4766
- sapi_activate ();
4767
-
4768
- if (in_child ) {
4769
- if (ret == SUCCESS ) {
4770
- exit (0 );
4771
- } else {
4772
- exit (2 );
4773
- }
4774
- }
4775
-
4776
- return ret ;
4777
- #endif
4778
4593
}
4779
4594
4780
4595
return SUCCESS ;
0 commit comments