Fix GH-10385: FPM successful config test early exit

This introduces an enum `fpm_init_return_status` to propagate the status
up to fpm_main. This also makes the code clearer by not using magic
integer return numbers.

Closes GH-10388
This commit is contained in:
Niels Dossche 2023-01-20 22:17:27 +01:00 committed by Jakub Zelenka
parent 4199b72c50
commit 5b13e83074
No known key found for this signature in database
GPG Key ID: 1C0779DC5C0A9DE4
4 changed files with 20 additions and 11 deletions

1
NEWS
View File

@ -19,6 +19,7 @@ PHP NEWS
- FPM:
. Fixed bug GH-10315 (FPM unknown child alert not valid). (Jakub Zelenka)
. Fixed bug GH-10385 (FPM successful config test early exit). (nielsdos)
- Opcache:
. Fix incorrect page_size check. (nielsdos)

View File

@ -41,7 +41,7 @@ struct fpm_globals_s fpm_globals = {
.send_config_pipe = {0, 0},
};
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr) /* {{{ */
enum fpm_init_return_status fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr) /* {{{ */
{
fpm_globals.argc = argc;
fpm_globals.argv = argv;
@ -67,22 +67,22 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
0 > fpm_event_init_main()) {
if (fpm_globals.test_successful) {
exit(FPM_EXIT_OK);
return FPM_INIT_EXIT_OK;
} else {
zlog(ZLOG_ERROR, "FPM initialization failed");
return -1;
return FPM_INIT_ERROR;
}
}
if (0 > fpm_conf_write_pid()) {
zlog(ZLOG_ERROR, "FPM initialization failed");
return -1;
return FPM_INIT_ERROR;
}
fpm_stdio_init_final();
zlog(ZLOG_NOTICE, "fpm is running, pid %d", (int) fpm_globals.parent_pid);
return 0;
return FPM_INIT_CONTINUE;
}
/* }}} */

View File

@ -34,8 +34,14 @@
#endif
enum fpm_init_return_status {
FPM_INIT_ERROR,
FPM_INIT_CONTINUE,
FPM_INIT_EXIT_OK,
};
int fpm_run(int *max_requests);
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr);
enum fpm_init_return_status fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr);
struct fpm_globals_s {
pid_t parent_pid;

View File

@ -1532,7 +1532,6 @@ int main(int argc, char *argv[])
int force_stderr = 0;
int php_information = 0;
int php_allow_to_run_as_root = 0;
int ret;
#if ZEND_RC_DEBUG
bool old_rc_debug;
#endif
@ -1800,21 +1799,24 @@ consult the installation file that came with this distribution, or visit \n\
zend_rc_debug = 0;
#endif
ret = fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root, force_daemon, force_stderr);
enum fpm_init_return_status ret = fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root, force_daemon, force_stderr);
#if ZEND_RC_DEBUG
zend_rc_debug = old_rc_debug;
#endif
if (ret < 0) {
if (ret == FPM_INIT_ERROR) {
if (fpm_globals.send_config_pipe[1]) {
int writeval = 0;
zlog(ZLOG_DEBUG, "Sending \"0\" (error) to parent via fd=%d", fpm_globals.send_config_pipe[1]);
zend_quiet_write(fpm_globals.send_config_pipe[1], &writeval, sizeof(writeval));
close(fpm_globals.send_config_pipe[1]);
}
return FPM_EXIT_CONFIG;
exit_status = FPM_EXIT_CONFIG;
goto out;
} else if (ret == FPM_INIT_EXIT_OK) {
exit_status = FPM_EXIT_OK;
goto out;
}
if (fpm_globals.send_config_pipe[1]) {