Skip to content

Commit 5b13e83

Browse files
nielsdosbukka
authored andcommitted
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
1 parent 4199b72 commit 5b13e83

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ PHP NEWS
1919

2020
- FPM:
2121
. Fixed bug GH-10315 (FPM unknown child alert not valid). (Jakub Zelenka)
22+
. Fixed bug GH-10385 (FPM successful config test early exit). (nielsdos)
2223

2324
- Opcache:
2425
. Fix incorrect page_size check. (nielsdos)

sapi/fpm/fpm/fpm.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct fpm_globals_s fpm_globals = {
4141
.send_config_pipe = {0, 0},
4242
};
4343

44-
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) /* {{{ */
44+
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) /* {{{ */
4545
{
4646
fpm_globals.argc = argc;
4747
fpm_globals.argv = argv;
@@ -67,22 +67,22 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
6767
0 > fpm_event_init_main()) {
6868

6969
if (fpm_globals.test_successful) {
70-
exit(FPM_EXIT_OK);
70+
return FPM_INIT_EXIT_OK;
7171
} else {
7272
zlog(ZLOG_ERROR, "FPM initialization failed");
73-
return -1;
73+
return FPM_INIT_ERROR;
7474
}
7575
}
7676

7777
if (0 > fpm_conf_write_pid()) {
7878
zlog(ZLOG_ERROR, "FPM initialization failed");
79-
return -1;
79+
return FPM_INIT_ERROR;
8080
}
8181

8282
fpm_stdio_init_final();
8383
zlog(ZLOG_NOTICE, "fpm is running, pid %d", (int) fpm_globals.parent_pid);
8484

85-
return 0;
85+
return FPM_INIT_CONTINUE;
8686
}
8787
/* }}} */
8888

sapi/fpm/fpm/fpm.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@
3434
#endif
3535

3636

37+
enum fpm_init_return_status {
38+
FPM_INIT_ERROR,
39+
FPM_INIT_CONTINUE,
40+
FPM_INIT_EXIT_OK,
41+
};
42+
3743
int fpm_run(int *max_requests);
38-
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);
44+
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);
3945

4046
struct fpm_globals_s {
4147
pid_t parent_pid;

sapi/fpm/fpm/fpm_main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,6 @@ int main(int argc, char *argv[])
15321532
int force_stderr = 0;
15331533
int php_information = 0;
15341534
int php_allow_to_run_as_root = 0;
1535-
int ret;
15361535
#if ZEND_RC_DEBUG
15371536
bool old_rc_debug;
15381537
#endif
@@ -1800,21 +1799,24 @@ consult the installation file that came with this distribution, or visit \n\
18001799
zend_rc_debug = 0;
18011800
#endif
18021801

1803-
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);
1802+
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);
18041803

18051804
#if ZEND_RC_DEBUG
18061805
zend_rc_debug = old_rc_debug;
18071806
#endif
18081807

1809-
if (ret < 0) {
1810-
1808+
if (ret == FPM_INIT_ERROR) {
18111809
if (fpm_globals.send_config_pipe[1]) {
18121810
int writeval = 0;
18131811
zlog(ZLOG_DEBUG, "Sending \"0\" (error) to parent via fd=%d", fpm_globals.send_config_pipe[1]);
18141812
zend_quiet_write(fpm_globals.send_config_pipe[1], &writeval, sizeof(writeval));
18151813
close(fpm_globals.send_config_pipe[1]);
18161814
}
1817-
return FPM_EXIT_CONFIG;
1815+
exit_status = FPM_EXIT_CONFIG;
1816+
goto out;
1817+
} else if (ret == FPM_INIT_EXIT_OK) {
1818+
exit_status = FPM_EXIT_OK;
1819+
goto out;
18181820
}
18191821

18201822
if (fpm_globals.send_config_pipe[1]) {

0 commit comments

Comments
 (0)