Skip to content

Commit

Permalink
Fix GH-10385: FPM successful config test early exit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nielsdos authored and bukka committed Feb 5, 2023
1 parent 4199b72 commit 5b13e83
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions sapi/fpm/fpm/fpm.c
Expand Up @@ -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;
Expand All @@ -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;
}
/* }}} */

Expand Down
8 changes: 7 additions & 1 deletion sapi/fpm/fpm/fpm.h
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions sapi/fpm/fpm/fpm_main.c
Expand Up @@ -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
Expand Down Expand Up @@ -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]) {
Expand Down

0 comments on commit 5b13e83

Please sign in to comment.