From f31be66141bed8252a98d9c7e3c6df021eaae286 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 22 Feb 2023 10:53:23 +0100 Subject: [PATCH] sapi/fpm: change lots of return types to `zend_result` More of https://github.com/php/php-src/pull/10622 --- sapi/fpm/fpm/fpm.c | 26 ++-- sapi/fpm/fpm/fpm_children.c | 36 +++--- sapi/fpm/fpm/fpm_children.h | 2 +- sapi/fpm/fpm/fpm_cleanup.c | 6 +- sapi/fpm/fpm/fpm_cleanup.h | 2 +- sapi/fpm/fpm/fpm_clock.c | 34 ++--- sapi/fpm/fpm/fpm_clock.h | 6 +- sapi/fpm/fpm/fpm_conf.c | 218 +++++++++++++++----------------- sapi/fpm/fpm/fpm_conf.h | 8 +- sapi/fpm/fpm/fpm_env.c | 20 +-- sapi/fpm/fpm/fpm_env.h | 4 +- sapi/fpm/fpm/fpm_events.c | 92 +++++++------- sapi/fpm/fpm/fpm_events.h | 16 ++- sapi/fpm/fpm/fpm_log.c | 54 ++++---- sapi/fpm/fpm/fpm_log.h | 4 +- sapi/fpm/fpm/fpm_main.c | 4 +- sapi/fpm/fpm/fpm_php.c | 34 ++--- sapi/fpm/fpm/fpm_php.h | 6 +- sapi/fpm/fpm/fpm_php_trace.c | 36 +++--- sapi/fpm/fpm/fpm_process_ctl.c | 30 ++--- sapi/fpm/fpm/fpm_process_ctl.h | 8 +- sapi/fpm/fpm/fpm_scoreboard.c | 18 +-- sapi/fpm/fpm/fpm_scoreboard.h | 5 +- sapi/fpm/fpm/fpm_signals.c | 56 ++++---- sapi/fpm/fpm/fpm_signals.h | 14 +- sapi/fpm/fpm/fpm_sockets.c | 60 ++++----- sapi/fpm/fpm/fpm_sockets.h | 12 +- sapi/fpm/fpm/fpm_status.c | 14 +- sapi/fpm/fpm/fpm_status.h | 4 +- sapi/fpm/fpm/fpm_stdio.c | 86 ++++++------- sapi/fpm/fpm/fpm_stdio.h | 24 ++-- sapi/fpm/fpm/fpm_systemd.c | 4 +- sapi/fpm/fpm/fpm_systemd.h | 2 +- sapi/fpm/fpm/fpm_trace.c | 8 +- sapi/fpm/fpm/fpm_trace.h | 13 +- sapi/fpm/fpm/fpm_trace_mach.c | 32 ++--- sapi/fpm/fpm/fpm_trace_pread.c | 24 ++-- sapi/fpm/fpm/fpm_trace_ptrace.c | 24 ++-- sapi/fpm/fpm/fpm_unix.c | 102 +++++++-------- sapi/fpm/fpm/fpm_unix.h | 10 +- sapi/fpm/fpm/fpm_worker_pool.c | 7 +- sapi/fpm/fpm/fpm_worker_pool.h | 2 +- 42 files changed, 580 insertions(+), 587 deletions(-) diff --git a/sapi/fpm/fpm/fpm.c b/sapi/fpm/fpm/fpm.c index cb86f403b89c9..95ba1c62e3309 100644 --- a/sapi/fpm/fpm/fpm.c +++ b/sapi/fpm/fpm/fpm.c @@ -53,18 +53,18 @@ enum fpm_init_return_status fpm_init(int argc, char **argv, char *config, char * fpm_globals.run_as_root = run_as_root; fpm_globals.force_stderr = force_stderr; - if (0 > fpm_php_init_main() || - 0 > fpm_stdio_init_main() || - 0 > fpm_conf_init_main(test_conf, force_daemon) || - 0 > fpm_unix_init_main() || - 0 > fpm_scoreboard_init_main() || - 0 > fpm_pctl_init_main() || - 0 > fpm_env_init_main() || - 0 > fpm_signals_init_main() || - 0 > fpm_children_init_main() || - 0 > fpm_sockets_init_main() || - 0 > fpm_worker_pool_init_main() || - 0 > fpm_event_init_main()) { + if (fpm_php_init_main() != SUCCESS || + fpm_stdio_init_main() != SUCCESS || + fpm_conf_init_main(test_conf, force_daemon) != SUCCESS || + fpm_unix_init_main() != SUCCESS || + fpm_scoreboard_init_main() != SUCCESS || + fpm_pctl_init_main() != SUCCESS|| + fpm_env_init_main() != SUCCESS || + fpm_signals_init_main() != SUCCESS || + fpm_children_init_main() != SUCCESS || + fpm_sockets_init_main() != SUCCESS || + fpm_worker_pool_init_main() != SUCCESS || + fpm_event_init_main() != SUCCESS) { if (fpm_globals.test_successful) { return FPM_INIT_EXIT_OK; @@ -74,7 +74,7 @@ enum fpm_init_return_status fpm_init(int argc, char **argv, char *config, char * } } - if (0 > fpm_conf_write_pid()) { + if (fpm_conf_write_pid() != SUCCESS) { zlog(ZLOG_ERROR, "FPM initialization failed"); return FPM_INIT_ERROR; } diff --git a/sapi/fpm/fpm/fpm_children.c b/sapi/fpm/fpm/fpm_children.c index 2f8e3dc4d0acc..d376a04500cc2 100644 --- a/sapi/fpm/fpm/fpm_children.c +++ b/sapi/fpm/fpm/fpm_children.c @@ -149,13 +149,13 @@ static void fpm_child_init(struct fpm_worker_pool_s *wp) /* {{{ */ fpm_globals.max_requests = wp->config->pm_max_requests; fpm_globals.listening_socket = dup(wp->listening_socket); - if (0 > fpm_stdio_init_child(wp) || - 0 > fpm_log_init_child(wp) || - 0 > fpm_status_init_child(wp) || - 0 > fpm_unix_init_child(wp) || - 0 > fpm_signals_init_child() || - 0 > fpm_env_init_child(wp) || - 0 > fpm_php_init_child(wp)) { + if (fpm_stdio_init_child(wp) != SUCCESS || + fpm_log_init_child(wp) != SUCCESS || + fpm_status_init_child(wp) != SUCCESS || + fpm_unix_init_child(wp) != SUCCESS || + fpm_signals_init_child() != SUCCESS || + fpm_env_init_child(wp) != SUCCESS || + fpm_php_init_child(wp) != SUCCESS) { zlog(ZLOG_ERROR, "[pool %s] child failed to initialize", wp->config->name); exit(FPM_EXIT_SOFTWARE); @@ -313,21 +313,21 @@ static struct fpm_child_s *fpm_resources_prepare(struct fpm_worker_pool_s *wp) / if (!c) { zlog(ZLOG_ERROR, "[pool %s] unable to malloc new child", wp->config->name); - return 0; + return NULL; } c->wp = wp; c->fd_stdout = -1; c->fd_stderr = -1; - if (0 > fpm_stdio_prepare_pipes(c)) { + if (fpm_stdio_prepare_pipes(c) != SUCCESS) { fpm_child_free(c); - return 0; + return NULL; } - if (0 > fpm_scoreboard_proc_alloc(c)) { + if (fpm_scoreboard_proc_alloc(c) != SUCCESS) { fpm_stdio_discard_pipes(c); fpm_child_free(c); - return 0; + return NULL; } return c; @@ -405,7 +405,7 @@ int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop, int nb_to } zlog(ZLOG_DEBUG, "blocking signals before child birth"); - if (0 > fpm_signals_child_block()) { + if (fpm_signals_child_block() != SUCCESS) { zlog(ZLOG_WARNING, "child may miss signals"); } @@ -472,7 +472,7 @@ int fpm_children_create_initial(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ -int fpm_children_init_main(void) +zend_result fpm_children_init_main(void) { if (fpm_global_config.emergency_restart_threshold && fpm_global_config.emergency_restart_interval) { @@ -480,15 +480,11 @@ int fpm_children_init_main(void) last_faults = malloc(sizeof(time_t) * fpm_global_config.emergency_restart_threshold); if (!last_faults) { - return -1; + return FAILURE; } memset(last_faults, 0, sizeof(time_t) * fpm_global_config.emergency_restart_threshold); } - if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_children_cleanup, 0)) { - return -1; - } - - return 0; + return fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_children_cleanup, 0); } diff --git a/sapi/fpm/fpm/fpm_children.h b/sapi/fpm/fpm/fpm_children.h index 679c34ba0383e..8ff49697f6934 100644 --- a/sapi/fpm/fpm/fpm_children.h +++ b/sapi/fpm/fpm/fpm_children.h @@ -15,7 +15,7 @@ struct fpm_child_s; int fpm_children_create_initial(struct fpm_worker_pool_s *wp); int fpm_children_free(struct fpm_child_s *child); void fpm_children_bury(void); -int fpm_children_init_main(void); +zend_result fpm_children_init_main(void); int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop, int nb_to_spawn, int is_debug); struct fpm_child_s *fpm_child_find(pid_t pid); diff --git a/sapi/fpm/fpm/fpm_cleanup.c b/sapi/fpm/fpm/fpm_cleanup.c index 7c900974a9cfd..48ae7d507ba14 100644 --- a/sapi/fpm/fpm/fpm_cleanup.c +++ b/sapi/fpm/fpm/fpm_cleanup.c @@ -15,21 +15,21 @@ struct cleanup_s { static struct fpm_array_s cleanups = { .sz = sizeof(struct cleanup_s) }; -int fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *arg) /* {{{ */ +zend_result fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *arg) /* {{{ */ { struct cleanup_s *c; c = fpm_array_push(&cleanups); if (!c) { - return -1; + return FAILURE; } c->type = type; c->cleanup = cleanup; c->arg = arg; - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_cleanup.h b/sapi/fpm/fpm/fpm_cleanup.h index 8583143fa20fc..76fc5fb86566a 100644 --- a/sapi/fpm/fpm/fpm_cleanup.h +++ b/sapi/fpm/fpm/fpm_cleanup.h @@ -3,7 +3,7 @@ #ifndef FPM_CLEANUP_H #define FPM_CLEANUP_H 1 -int fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *); +zend_result fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *); void fpm_cleanups_run(int type); enum { diff --git a/sapi/fpm/fpm/fpm_clock.c b/sapi/fpm/fpm/fpm_clock.c index 57faccbe9d80d..8f4ee46f599a5 100644 --- a/sapi/fpm/fpm/fpm_clock.c +++ b/sapi/fpm/fpm/fpm_clock.c @@ -15,7 +15,7 @@ static int monotonic_works; -int fpm_clock_init(void) +zend_result fpm_clock_init(void) { struct timespec ts; @@ -25,25 +25,25 @@ int fpm_clock_init(void) monotonic_works = 1; } - return 0; + return SUCCESS; } -int fpm_clock_get(struct timeval *tv) /* {{{ */ +zend_result fpm_clock_get(struct timeval *tv) /* {{{ */ { if (monotonic_works) { struct timespec ts; if (0 > clock_gettime(CLOCK_MONOTONIC, &ts)) { zlog(ZLOG_SYSERROR, "clock_gettime() failed"); - return -1; + return FAILURE; } tv->tv_sec = ts.tv_sec; tv->tv_usec = ts.tv_nsec / 1000; - return 0; + return SUCCESS; } - return gettimeofday(tv, 0); + return gettimeofday(tv, 0) == 0 ? SUCCESS : FAILURE; } /* }}} */ @@ -58,7 +58,7 @@ static clock_serv_t mach_clock; /* this code borrowed from here: http://lists.apple.com/archives/Darwin-development/2002/Mar/msg00746.html */ /* mach_clock also should be re-initialized in child process after fork */ -int fpm_clock_init(void) +zend_result fpm_clock_init(void) { kern_return_t ret; mach_timespec_t aTime; @@ -67,7 +67,7 @@ int fpm_clock_init(void) if (ret != KERN_SUCCESS) { zlog(ZLOG_ERROR, "host_get_clock_service() failed: %s", mach_error_string(ret)); - return -1; + return FAILURE; } /* test if it works */ @@ -75,13 +75,13 @@ int fpm_clock_init(void) if (ret != KERN_SUCCESS) { zlog(ZLOG_ERROR, "clock_get_time() failed: %s", mach_error_string(ret)); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } -int fpm_clock_get(struct timeval *tv) /* {{{ */ +zend_result fpm_clock_get(struct timeval *tv) /* {{{ */ { kern_return_t ret; mach_timespec_t aTime; @@ -90,26 +90,26 @@ int fpm_clock_get(struct timeval *tv) /* {{{ */ if (ret != KERN_SUCCESS) { zlog(ZLOG_ERROR, "clock_get_time() failed: %s", mach_error_string(ret)); - return -1; + return FAILURE; } tv->tv_sec = aTime.tv_sec; tv->tv_usec = aTime.tv_nsec / 1000; - return 0; + return SUCCESS; } /* }}} */ #else /* no clock */ -int fpm_clock_init(void) +zend_result fpm_clock_init(void) { - return 0; + return SUCCESS; } -int fpm_clock_get(struct timeval *tv) /* {{{ */ +zend_result fpm_clock_get(struct timeval *tv) /* {{{ */ { - return gettimeofday(tv, 0); + return gettimeofday(tv, 0) == 0 ? SUCCESS : FAILURE; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_clock.h b/sapi/fpm/fpm/fpm_clock.h index 1bf38ff63ef80..f48b435b9dad9 100644 --- a/sapi/fpm/fpm/fpm_clock.h +++ b/sapi/fpm/fpm/fpm_clock.h @@ -3,9 +3,11 @@ #ifndef FPM_CLOCK_H #define FPM_CLOCK_H 1 +#include "zend_result.h" + #include -int fpm_clock_init(void); -int fpm_clock_get(struct timeval *tv); +zend_result fpm_clock_init(void); +zend_result fpm_clock_get(struct timeval *tv); #endif diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index 5684a46190eb4..91bde7f855224 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -46,7 +46,7 @@ #define GO(field) offsetof(struct fpm_global_config_s, field) #define WPO(field) offsetof(struct fpm_worker_pool_config_s, field) -static int fpm_conf_load_ini_file(char *filename); +static zend_result fpm_conf_load_ini_file(char *filename); static char *fpm_conf_set_integer(zval *value, void **config, intptr_t offset); #if 0 /* not used for now */ static char *fpm_conf_set_long(zval *value, void **config, intptr_t offset); @@ -164,12 +164,12 @@ static const struct ini_value_parser_s ini_fpm_pool_options[] = { { 0, 0, 0 } }; -static int fpm_conf_is_dir(char *path) /* {{{ */ +static bool fpm_conf_is_dir(char *path) /* {{{ */ { struct stat sb; if (stat(path, &sb) != 0) { - return 0; + return false; } return (sb.st_mode & S_IFMT) == S_IFDIR; @@ -179,11 +179,11 @@ static int fpm_conf_is_dir(char *path) /* {{{ */ /* * Expands the '$pool' token in a dynamically allocated string */ -static int fpm_conf_expand_pool_name(char **value) { +static zend_result fpm_conf_expand_pool_name(char **value) { char *token; if (!value || !*value) { - return 0; + return SUCCESS; } while (*value && (token = strstr(*value, "$pool"))) { @@ -192,7 +192,7 @@ static int fpm_conf_expand_pool_name(char **value) { /* If we are not in a pool, we cannot expand this name now */ if (!current_wp || !current_wp->config || !current_wp->config->name) { - return -1; + return FAILURE; } /* "aaa$poolbbb" becomes "aaa\0oolbbb" */ @@ -207,7 +207,7 @@ static int fpm_conf_expand_pool_name(char **value) { efree(buf); } - return 0; + return SUCCESS; } static char *fpm_conf_set_boolean(zval *value, void **config, intptr_t offset) /* {{{ */ @@ -242,7 +242,7 @@ static char *fpm_conf_set_string(zval *value, void **config, intptr_t offset) /* if (!*config_val) { return "fpm_conf_set_string(): strdup() failed"; } - if (fpm_conf_expand_pool_name(config_val) == -1) { + if (fpm_conf_expand_pool_name(config_val) != SUCCESS) { return "Can't use '$pool' when the pool is not defined"; } @@ -606,14 +606,14 @@ static void *fpm_worker_pool_config_alloc(void) wp = fpm_worker_pool_alloc(); if (!wp) { - return 0; + return NULL; } wp->config = malloc(sizeof(struct fpm_worker_pool_config_s)); if (!wp->config) { fpm_worker_pool_free(wp); - return 0; + return NULL; } memset(wp->config, 0, sizeof(struct fpm_worker_pool_config_s)); @@ -645,7 +645,7 @@ static void *fpm_worker_pool_config_alloc(void) return wp->config; } -int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */ +void fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */ { struct key_value_s *kv, *kv_next; @@ -694,15 +694,13 @@ int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */ free(kv->value); free(kv); } - - return 0; } /* }}} */ #define FPM_WPC_STR_CP_EX(_cfg, _scfg, _sf, _df) \ do { \ if (_scfg->_df && !(_cfg->_sf = strdup(_scfg->_df))) { \ - return -1; \ + return FAILURE; \ } \ } while (0) #define FPM_WPC_STR_CP(_cfg, _scfg, _field) FPM_WPC_STR_CP_EX(_cfg, _scfg, _field, _field) @@ -718,17 +716,17 @@ void fpm_conf_apply_kv_array_to_kv_array(struct key_value_s *src, void *dest) { } } -static int fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_wp) { /* {{{ */ +static zend_result fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_wp) { /* {{{ */ struct fpm_worker_pool_config_s *config, *shared_config; config = fpm_worker_pool_config_alloc(); if (!config) { - return -1; + return FAILURE; } shared_config = shared_wp->config; config->name = malloc(strlen(shared_config->name) + sizeof("_status")); if (!config->name) { - return -1; + return FAILURE; } strcpy(config->name, shared_config->name); strcpy(config->name + strlen(shared_config->name), "_status"); @@ -758,17 +756,17 @@ static int fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_ current_wp->shared = shared_wp; - return 0; + return SUCCESS; } /* }}} */ -static int fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, char *default_prefix, int expand) /* {{{ */ +static zend_result fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, char *default_prefix, int expand) /* {{{ */ { char *prefix = NULL; char *full_path; if (!path || !*path || **path == '/') { - return 0; + return SUCCESS; } if (wp && wp->config) { @@ -792,7 +790,7 @@ static int fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, cha if (tmp != *path) { zlog(ZLOG_ERROR, "'$prefix' must be use at the beginning of the value"); - return -1; + return FAILURE; } if (strlen(*path) > strlen("$prefix")) { @@ -818,17 +816,17 @@ static int fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, cha if (**path != '/' && wp != NULL && wp->config) { return fpm_evaluate_full_path(path, NULL, default_prefix, expand); } - return 0; + return SUCCESS; } /* }}} */ -static int fpm_conf_process_all_pools(void) +static zend_result fpm_conf_process_all_pools(void) { struct fpm_worker_pool_s *wp, *wp2; if (!fpm_worker_all_pools) { zlog(ZLOG_ERROR, "No pool defined. at least one pool section must be specified in config file"); - return -1; + return FAILURE; } for (wp = fpm_worker_all_pools; wp; wp = wp->next) { @@ -839,14 +837,14 @@ static int fpm_conf_process_all_pools(void) if (!fpm_conf_is_dir(wp->config->prefix)) { zlog(ZLOG_ERROR, "[pool %s] the prefix '%s' does not exist or is not a directory", wp->config->name, wp->config->prefix); - return -1; + return FAILURE; } } /* alert if user is not set; only if we are root and fpm is not running with --allow-to-run-as-root */ if (!wp->config->user && !geteuid() && !fpm_globals.run_as_root) { zlog(ZLOG_ALERT, "[pool %s] user has not been defined", wp->config->name); - return -1; + return FAILURE; } /* listen */ @@ -858,24 +856,24 @@ static int fpm_conf_process_all_pools(void) } } else { zlog(ZLOG_ALERT, "[pool %s] no listen address have been defined!", wp->config->name); - return -1; + return FAILURE; } if (wp->config->process_priority != 64 && (wp->config->process_priority < -19 || wp->config->process_priority > 20)) { zlog(ZLOG_ERROR, "[pool %s] process.priority must be included into [-19,20]", wp->config->name); - return -1; + return FAILURE; } /* pm */ if (wp->config->pm != PM_STYLE_STATIC && wp->config->pm != PM_STYLE_DYNAMIC && wp->config->pm != PM_STYLE_ONDEMAND) { zlog(ZLOG_ALERT, "[pool %s] the process manager is missing (static, dynamic or ondemand)", wp->config->name); - return -1; + return FAILURE; } /* pm.max_children */ if (wp->config->pm_max_children < 1) { zlog(ZLOG_ALERT, "[pool %s] pm.max_children must be a positive value", wp->config->name); - return -1; + return FAILURE; } /* pm.start_servers, pm.min_spare_servers, pm.max_spare_servers, pm.max_spawn_rate */ @@ -884,23 +882,23 @@ static int fpm_conf_process_all_pools(void) if (config->pm_min_spare_servers <= 0) { zlog(ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) must be a positive value", wp->config->name, config->pm_min_spare_servers); - return -1; + return FAILURE; } if (config->pm_max_spare_servers <= 0) { zlog(ZLOG_ALERT, "[pool %s] pm.max_spare_servers(%d) must be a positive value", wp->config->name, config->pm_max_spare_servers); - return -1; + return FAILURE; } if (config->pm_min_spare_servers > config->pm_max_children || config->pm_max_spare_servers > config->pm_max_children) { zlog(ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) and pm.max_spare_servers(%d) cannot be greater than pm.max_children(%d)", wp->config->name, config->pm_min_spare_servers, config->pm_max_spare_servers, config->pm_max_children); - return -1; + return FAILURE; } if (config->pm_max_spare_servers < config->pm_min_spare_servers) { zlog(ZLOG_ALERT, "[pool %s] pm.max_spare_servers(%d) must not be less than pm.min_spare_servers(%d)", wp->config->name, config->pm_max_spare_servers, config->pm_min_spare_servers); - return -1; + return FAILURE; } if (config->pm_start_servers <= 0) { @@ -909,24 +907,24 @@ static int fpm_conf_process_all_pools(void) } else if (config->pm_start_servers < config->pm_min_spare_servers || config->pm_start_servers > config->pm_max_spare_servers) { zlog(ZLOG_ALERT, "[pool %s] pm.start_servers(%d) must not be less than pm.min_spare_servers(%d) and not greater than pm.max_spare_servers(%d)", wp->config->name, config->pm_start_servers, config->pm_min_spare_servers, config->pm_max_spare_servers); - return -1; + return FAILURE; } if (config->pm_max_spawn_rate < 1) { zlog(ZLOG_ALERT, "[pool %s] pm.max_spawn_rate must be a positive value", wp->config->name); - return -1; + return FAILURE; } } else if (wp->config->pm == PM_STYLE_ONDEMAND) { struct fpm_worker_pool_config_s *config = wp->config; if (!fpm_event_support_edge_trigger()) { zlog(ZLOG_ALERT, "[pool %s] ondemand process manager can ONLY be used when events.mechanism is either epoll (Linux) or kqueue (*BSD).", wp->config->name); - return -1; + return FAILURE; } if (config->pm_process_idle_timeout < 1) { zlog(ZLOG_ALERT, "[pool %s] pm.process_idle_timeout(%ds) must be greater than 0s", wp->config->name, config->pm_process_idle_timeout); - return -1; + return FAILURE; } if (config->listen_backlog < FPM_BACKLOG_DEFAULT) { @@ -951,18 +949,18 @@ static int fpm_conf_process_all_pools(void) if (*status != '/') { zlog(ZLOG_ERROR, "[pool %s] the status path '%s' must start with a '/'", wp->config->name, status); - return -1; + return FAILURE; } if (!wp->config->pm_status_listen && !wp->shared && strlen(status) < 2) { zlog(ZLOG_ERROR, "[pool %s] the status path '%s' is not long enough", wp->config->name, status); - return -1; + return FAILURE; } for (i = 0; i < strlen(status); i++) { if (!isalnum(status[i]) && status[i] != '/' && status[i] != '-' && status[i] != '_' && status[i] != '.' && status[i] != '~') { zlog(ZLOG_ERROR, "[pool %s] the status path '%s' must contain only the following characters '[alphanum]/_-.~'", wp->config->name, status); - return -1; + return FAILURE; } } } @@ -974,18 +972,18 @@ static int fpm_conf_process_all_pools(void) if (*ping != '/') { zlog(ZLOG_ERROR, "[pool %s] the ping path '%s' must start with a '/'", wp->config->name, ping); - return -1; + return FAILURE; } if (strlen(ping) < 2) { zlog(ZLOG_ERROR, "[pool %s] the ping path '%s' is not long enough", wp->config->name, ping); - return -1; + return FAILURE; } for (i = 0; i < strlen(ping); i++) { if (!isalnum(ping[i]) && ping[i] != '/' && ping[i] != '-' && ping[i] != '_' && ping[i] != '.' && ping[i] != '~') { zlog(ZLOG_ERROR, "[pool %s] the ping path '%s' must contain only the following characters '[alphanum]/_-.~'", wp->config->name, ping); - return -1; + return FAILURE; } } @@ -994,7 +992,7 @@ static int fpm_conf_process_all_pools(void) } else { if (strlen(wp->config->ping_response) < 1) { zlog(ZLOG_ERROR, "[pool %s] the ping response page '%s' is not long enough", wp->config->name, wp->config->ping_response); - return -1; + return FAILURE; } } } else { @@ -1026,7 +1024,7 @@ static int fpm_conf_process_all_pools(void) #if HAVE_FPM_TRACE if (! (wp->config->slowlog && *wp->config->slowlog)) { zlog(ZLOG_ERROR, "[pool %s] 'slowlog' must be specified for use with 'request_slowlog_timeout'", wp->config->name); - return -1; + return FAILURE; } #else static int warned = 0; @@ -1046,7 +1044,7 @@ static int fpm_conf_process_all_pools(void) if (0 > fd) { zlog(ZLOG_SYSERROR, "Unable to create or open slowlog(%s)", wp->config->slowlog); - return -1; + return FAILURE; } close(fd); } @@ -1055,7 +1053,7 @@ static int fpm_conf_process_all_pools(void) if (wp->config->request_terminate_timeout && wp->config->request_slowlog_timeout > wp->config->request_terminate_timeout) { zlog(ZLOG_ERROR, "[pool %s] 'request_slowlog_timeout' (%d) can't be greater than 'request_terminate_timeout' (%d)", wp->config->name, wp->config->request_slowlog_timeout, wp->config->request_terminate_timeout); - return -1; + return FAILURE; } } @@ -1064,7 +1062,7 @@ static int fpm_conf_process_all_pools(void) #if HAVE_FPM_TRACE if (! (wp->config->slowlog && *wp->config->slowlog)) { zlog(ZLOG_ERROR, "[pool %s] 'slowlog' must be specified for use with 'request_slowlog_trace_depth'", wp->config->name); - return -1; + return FAILURE; } #else static int warned = 0; @@ -1077,7 +1075,7 @@ static int fpm_conf_process_all_pools(void) if (wp->config->request_slowlog_trace_depth <= 0) { zlog(ZLOG_ERROR, "[pool %s] 'request_slowlog_trace_depth' (%d) must be a positive value", wp->config->name, wp->config->request_slowlog_trace_depth); - return -1; + return FAILURE; } } else { wp->config->request_slowlog_trace_depth = 20; @@ -1090,12 +1088,12 @@ static int fpm_conf_process_all_pools(void) if (*wp->config->chroot != '/') { zlog(ZLOG_ERROR, "[pool %s] the chroot path '%s' must start with a '/'", wp->config->name, wp->config->chroot); - return -1; + return FAILURE; } if (!fpm_conf_is_dir(wp->config->chroot)) { zlog(ZLOG_ERROR, "[pool %s] the chroot path '%s' does not exist or is not a directory", wp->config->name, wp->config->chroot); - return -1; + return FAILURE; } } @@ -1106,7 +1104,7 @@ static int fpm_conf_process_all_pools(void) if (*wp->config->chdir != '/') { zlog(ZLOG_ERROR, "[pool %s] the chdir path '%s' must start with a '/'", wp->config->name, wp->config->chdir); - return -1; + return FAILURE; } if (wp->config->chroot) { @@ -1117,14 +1115,14 @@ static int fpm_conf_process_all_pools(void) if (!fpm_conf_is_dir(buf)) { zlog(ZLOG_ERROR, "[pool %s] the chdir path '%s' within the chroot path '%s' ('%s') does not exist or is not a directory", wp->config->name, wp->config->chdir, wp->config->chroot, buf); efree(buf); - return -1; + return FAILURE; } efree(buf); } else { if (!fpm_conf_is_dir(wp->config->chdir)) { zlog(ZLOG_ERROR, "[pool %s] the chdir path '%s' does not exist or is not a directory", wp->config->name, wp->config->chdir); - return -1; + return FAILURE; } } } @@ -1160,7 +1158,7 @@ static int fpm_conf_process_all_pools(void) wp->limit_extensions = malloc(sizeof(char *) * (nb_ext + 1)); if (!wp->limit_extensions) { zlog(ZLOG_ERROR, "[pool %s] unable to malloc extensions array", wp->config->name); - return -1; + return FAILURE; } /* strdup because strtok(3) alters the string it parses */ @@ -1214,25 +1212,25 @@ static int fpm_conf_process_all_pools(void) if (wp->config->listen_address && *wp->config->listen_address && wp2->config->listen_address && *wp2->config->listen_address && !strcmp(wp->config->listen_address, wp2->config->listen_address)) { zlog(ZLOG_ERROR, "[pool %s] unable to set listen address as it's already used in another pool '%s'", wp2->config->name, wp->config->name); - return -1; + return FAILURE; } } } - return 0; + return SUCCESS; } -int fpm_conf_unlink_pid(void) +zend_result fpm_conf_unlink_pid(void) { if (fpm_global_config.pid_file) { if (0 > unlink(fpm_global_config.pid_file)) { zlog(ZLOG_SYSERROR, "Unable to remove the PID file (%s).", fpm_global_config.pid_file); - return -1; + return FAILURE; } } - return 0; + return SUCCESS; } -int fpm_conf_write_pid(void) +zend_result fpm_conf_write_pid(void) { int fd; @@ -1245,7 +1243,7 @@ int fpm_conf_write_pid(void) if (fd < 0) { zlog(ZLOG_SYSERROR, "Unable to create the PID file (%s).", fpm_global_config.pid_file); - return -1; + return FAILURE; } len = sprintf(buf, "%d", (int) fpm_globals.parent_pid); @@ -1253,14 +1251,14 @@ int fpm_conf_write_pid(void) if (len != write(fd, buf, len)) { zlog(ZLOG_SYSERROR, "Unable to write to the PID file."); close(fd); - return -1; + return FAILURE; } close(fd); } - return 0; + return SUCCESS; } -static int fpm_conf_post_process(int force_daemon) /* {{{ */ +static zend_result fpm_conf_post_process(int force_daemon) /* {{{ */ { struct fpm_worker_pool_s *wp; @@ -1277,19 +1275,19 @@ static int fpm_conf_post_process(int force_daemon) /* {{{ */ zlog_set_level(fpm_globals.log_level); if (fpm_global_config.log_limit < ZLOG_MIN_LIMIT) { zlog(ZLOG_ERROR, "log_limit must be greater than %d", ZLOG_MIN_LIMIT); - return -1; + return FAILURE; } zlog_set_limit(fpm_global_config.log_limit); zlog_set_buffering(fpm_global_config.log_buffering); if (fpm_global_config.process_max < 0) { zlog(ZLOG_ERROR, "process_max can't be negative"); - return -1; + return FAILURE; } if (fpm_global_config.process_priority != 64 && (fpm_global_config.process_priority < -19 || fpm_global_config.process_priority > 20)) { zlog(ZLOG_ERROR, "process.priority must be included into [-19,20]"); - return -1; + return FAILURE; } if (!fpm_global_config.error_log) { @@ -1297,8 +1295,8 @@ static int fpm_conf_post_process(int force_daemon) /* {{{ */ } #ifdef HAVE_SYSTEMD - if (0 > fpm_systemd_conf()) { - return -1; + if (fpm_systemd_conf() != SUCCESS) { + return FAILURE; } #endif @@ -1317,37 +1315,37 @@ static int fpm_conf_post_process(int force_daemon) /* {{{ */ fpm_evaluate_full_path(&fpm_global_config.error_log, NULL, PHP_LOCALSTATEDIR, 0); } - if (!fpm_global_config.daemonize && 0 > fpm_stdio_save_original_stderr()) { - return -1; + if (!fpm_global_config.daemonize && fpm_stdio_save_original_stderr() != SUCCESS) { + return FAILURE; } - if (0 > fpm_stdio_open_error_log(0)) { - return -1; + if (fpm_stdio_open_error_log(0) != SUCCESS) { + return FAILURE; } - if (0 > fpm_event_pre_init(fpm_global_config.events_mechanism)) { - return -1; + if (fpm_event_pre_init(fpm_global_config.events_mechanism) != SUCCESS) { + return FAILURE; } - if (0 > fpm_conf_process_all_pools()) { - return -1; + if (fpm_conf_process_all_pools() != SUCCESS) { + return FAILURE; } - if (0 > fpm_log_open(0)) { - return -1; + if (fpm_log_open(0) != SUCCESS) { + return FAILURE; } for (wp = fpm_worker_all_pools; wp; wp = wp->next) { if (!wp->config->access_log || !*wp->config->access_log) { continue; } - if (0 > fpm_log_write(wp->config->access_format)) { + if (fpm_log_write(wp->config->access_format) != SUCCESS) { zlog(ZLOG_ERROR, "[pool %s] wrong format for access.format '%s'", wp->config->name, wp->config->access_format); - return -1; + return FAILURE; } } - return 0; + return SUCCESS; } /* }}} */ @@ -1401,7 +1399,7 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */ int len = strlen(g.gl_pathv[i]); if (len < 1) continue; if (g.gl_pathv[i][len - 1] == '/') continue; /* don't parse directories */ - if (0 > fpm_conf_load_ini_file(g.gl_pathv[i])) { + if (fpm_conf_load_ini_file(g.gl_pathv[i]) != SUCCESS) { zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", g.gl_pathv[i], filename, ini_lineno); *error = 1; efree(filename); @@ -1411,7 +1409,7 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */ globfree(&g); } #else /* HAVE_GLOB */ - if (0 > fpm_conf_load_ini_file(inc)) { + if (fpm_conf_load_ini_file(inc) != SUCCESS) { zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", inc, filename, ini_lineno); *error = 1; efree(filename); @@ -1617,7 +1615,7 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback } /* }}} */ -int fpm_conf_load_ini_file(char *filename) /* {{{ */ +zend_result fpm_conf_load_ini_file(char *filename) /* {{{ */ { int error = 0; char *buf = NULL, *newbuf = NULL; @@ -1626,23 +1624,21 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ int nb_read = 1; char c = '*'; - int ret = 1; - if (!filename || !filename[0]) { zlog(ZLOG_ERROR, "configuration filename is empty"); - return -1; + return FAILURE; } fd = open(filename, O_RDONLY, 0); if (fd < 0) { zlog(ZLOG_SYSERROR, "failed to open configuration file '%s'", filename); - return -1; + return FAILURE; } if (ini_recursion++ > 4) { zlog(ZLOG_ERROR, "failed to include more than 5 files recursively"); close(fd); - return -1; + return FAILURE; } ini_lineno = 0; @@ -1658,7 +1654,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); free(buf); - return -1; + return FAILURE; } buf = newbuf; } @@ -1681,7 +1677,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); free(buf); - return -1; + return FAILURE; } if (ini_include) { char *tmp = ini_include; @@ -1693,7 +1689,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); free(buf); - return -1; + return FAILURE; } free(tmp); } @@ -1702,7 +1698,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); - return ret; + return SUCCESS; } /* }}} */ @@ -1817,14 +1813,12 @@ static void fpm_conf_dump(void) } } -int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ +zend_result fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ { - int ret; - if (fpm_globals.prefix && *fpm_globals.prefix) { if (!fpm_conf_is_dir(fpm_globals.prefix)) { zlog(ZLOG_ERROR, "the global prefix '%s' does not exist or is not a directory", fpm_globals.prefix); - return -1; + return FAILURE; } } @@ -1843,7 +1837,7 @@ int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ if (!tmp) { zlog(ZLOG_SYSERROR, "spprintf() failed (tmp for fpm_globals.config)"); - return -1; + return FAILURE; } fpm_globals.config = strdup(tmp); @@ -1851,26 +1845,24 @@ int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ if (!fpm_globals.config) { zlog(ZLOG_SYSERROR, "spprintf() failed (fpm_globals.config)"); - return -1; + return FAILURE; } } - ret = fpm_conf_load_ini_file(fpm_globals.config); - - if (0 > ret) { + if (fpm_conf_load_ini_file(fpm_globals.config) != SUCCESS) { zlog(ZLOG_ERROR, "failed to load configuration file '%s'", fpm_globals.config); - return -1; + return FAILURE; } - if (0 > fpm_conf_post_process(force_daemon)) { + if (fpm_conf_post_process(force_daemon) != SUCCESS) { zlog(ZLOG_ERROR, "failed to post process the configuration"); - return -1; + return FAILURE; } if (test_conf) { for (struct fpm_worker_pool_s *wp = fpm_worker_all_pools; wp; wp = wp->next) { if (!fpm_unix_test_config(wp)) { - return -1; + return FAILURE; } } @@ -1879,13 +1871,13 @@ int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ } zlog(ZLOG_NOTICE, "configuration file %s test is successful\n", fpm_globals.config); fpm_globals.test_successful = 1; - return -1; + return FAILURE; } - if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_conf_cleanup, 0)) { - return -1; + if (fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_conf_cleanup, 0) != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h index 5b354a9bdecef..793d55c7dda7e 100644 --- a/sapi/fpm/fpm/fpm_conf.h +++ b/sapi/fpm/fpm/fpm_conf.h @@ -121,9 +121,9 @@ enum { PM_STYLE_ONDEMAND = 3 }; -int fpm_conf_init_main(int test_conf, int force_daemon); -int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc); -int fpm_conf_write_pid(void); -int fpm_conf_unlink_pid(void); +zend_result fpm_conf_init_main(int test_conf, int force_daemon); +void fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc); +zend_result fpm_conf_write_pid(void); +zend_result fpm_conf_unlink_pid(void); #endif diff --git a/sapi/fpm/fpm/fpm_env.c b/sapi/fpm/fpm/fpm_env.c index 72ed1aa94d383..902fd694c1895 100644 --- a/sapi/fpm/fpm/fpm_env.c +++ b/sapi/fpm/fpm/fpm_env.c @@ -133,7 +133,7 @@ void fpm_env_setproctitle(char *title) /* {{{ */ } /* }}} */ -int fpm_env_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_env_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { struct key_value_s *kv; char *title; @@ -157,11 +157,11 @@ int fpm_env_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ setenv("HOME", wp->home, 1); } - return 0; + return SUCCESS; } /* }}} */ -static int fpm_env_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ +static zend_result fpm_env_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ { struct key_value_s *kv; @@ -190,18 +190,18 @@ static int fpm_env_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ } } - return 0; + return SUCCESS; } /* }}} */ -int fpm_env_init_main(void) +zend_result fpm_env_init_main(void) { struct fpm_worker_pool_s *wp; char *title; for (wp = fpm_worker_all_pools; wp; wp = wp->next) { - if (0 > fpm_env_conf_wp(wp)) { - return -1; + if (fpm_env_conf_wp(wp) != SUCCESS) { + return FAILURE; } } #ifndef HAVE_SETPROCTITLE @@ -241,7 +241,7 @@ int fpm_env_init_main(void) } } if (first == NULL || last == NULL) { - return 0; + return SUCCESS; } fpm_env_argv_len = last - first; @@ -255,7 +255,7 @@ int fpm_env_init_main(void) } if ((new_environ = malloc((1U + env_nb) * sizeof (char *))) == NULL) { - return -1; + return FAILURE; } new_environ[env_nb] = NULL; while (env_nb > 0U) { @@ -270,5 +270,5 @@ int fpm_env_init_main(void) spprintf(&title, 0, "master process (%s)", fpm_globals.config); fpm_env_setproctitle(title); efree(title); - return 0; + return SUCCESS; } diff --git a/sapi/fpm/fpm/fpm_env.h b/sapi/fpm/fpm/fpm_env.h index dacf6f8701544..2275cb0b89265 100644 --- a/sapi/fpm/fpm/fpm_env.h +++ b/sapi/fpm/fpm/fpm_env.h @@ -7,8 +7,8 @@ #define SETPROCTITLE_PREFIX "php-fpm: " -int fpm_env_init_child(struct fpm_worker_pool_s *wp); -int fpm_env_init_main(void); +zend_result fpm_env_init_child(struct fpm_worker_pool_s *wp); +zend_result fpm_env_init_main(void); void fpm_env_setproctitle(char *title); extern char **environ; diff --git a/sapi/fpm/fpm/fpm_events.c b/sapi/fpm/fpm/fpm_events.c index 4cc56067bfc6c..8fb23b954a070 100644 --- a/sapi/fpm/fpm/fpm_events.c +++ b/sapi/fpm/fpm/fpm_events.c @@ -37,8 +37,8 @@ static void fpm_event_cleanup(int which, void *arg); static void fpm_postponed_children_bury(struct fpm_event_s *ev, short which, void *arg); static void fpm_got_signal(struct fpm_event_s *ev, short which, void *arg); static struct fpm_event_s *fpm_event_queue_isset(struct fpm_event_queue_s *queue, struct fpm_event_s *ev); -static int fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_event_s *ev); -static int fpm_event_queue_del(struct fpm_event_queue_s **queue, struct fpm_event_s *ev); +static zend_result fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_event_s *ev); +static zend_result fpm_event_queue_del(struct fpm_event_queue_s **queue, struct fpm_event_s *ev); static void fpm_event_queue_destroy(struct fpm_event_queue_s **queue); static struct fpm_event_module_s *module; @@ -109,7 +109,7 @@ static void fpm_got_signal(struct fpm_event_s *ev, short which, void *arg) /* {{ * access.log if it was configured to write to the stderr. Check #8885. */ fpm_stdio_restore_original_stderr(0); - if (0 == fpm_stdio_open_error_log(1)) { + if (fpm_stdio_open_error_log(1) == SUCCESS) { zlog(ZLOG_NOTICE, "error log file re-opened"); } else { zlog(ZLOG_ERROR, "unable to re-opened error log file"); @@ -159,21 +159,21 @@ static struct fpm_event_s *fpm_event_queue_isset(struct fpm_event_queue_s *queue } /* }}} */ -static int fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_event_s *ev) /* {{{ */ +static zend_result fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_event_s *ev) /* {{{ */ { struct fpm_event_queue_s *elt; if (!queue || !ev) { - return -1; + return FAILURE; } if (fpm_event_queue_isset(*queue, ev)) { - return 0; + return SUCCESS; } if (!(elt = malloc(sizeof(struct fpm_event_queue_s)))) { zlog(ZLOG_SYSERROR, "Unable to add the event to queue: malloc() failed"); - return -1; + return FAILURE; } elt->prev = NULL; elt->next = NULL; @@ -190,15 +190,15 @@ static int fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_even module->add(ev); } - return 0; + return SUCCESS; } /* }}} */ -static int fpm_event_queue_del(struct fpm_event_queue_s **queue, struct fpm_event_s *ev) /* {{{ */ +static zend_result fpm_event_queue_del(struct fpm_event_queue_s **queue, struct fpm_event_s *ev) /* {{{ */ { struct fpm_event_queue_s *q; if (!queue || !ev) { - return -1; + return FAILURE; } q = *queue; while (q) { @@ -222,11 +222,11 @@ static int fpm_event_queue_del(struct fpm_event_queue_s **queue, struct fpm_even } free(q); - return 0; + return SUCCESS; } q = q->next; } - return -1; + return FAILURE; } /* }}} */ @@ -253,13 +253,13 @@ static void fpm_event_queue_destroy(struct fpm_event_queue_s **queue) /* {{{ */ } /* }}} */ -int fpm_event_pre_init(char *mechanism) /* {{{ */ +zend_result fpm_event_pre_init(char *mechanism) /* {{{ */ { /* kqueue */ module = fpm_event_kqueue_module(); if (module) { if (!mechanism || strcasecmp(module->name, mechanism) == 0) { - return 0; + return SUCCESS; } } @@ -267,7 +267,7 @@ int fpm_event_pre_init(char *mechanism) /* {{{ */ module = fpm_event_port_module(); if (module) { if (!mechanism || strcasecmp(module->name, mechanism) == 0) { - return 0; + return SUCCESS; } } @@ -275,7 +275,7 @@ int fpm_event_pre_init(char *mechanism) /* {{{ */ module = fpm_event_epoll_module(); if (module) { if (!mechanism || strcasecmp(module->name, mechanism) == 0) { - return 0; + return SUCCESS; } } @@ -283,7 +283,7 @@ int fpm_event_pre_init(char *mechanism) /* {{{ */ module = fpm_event_devpoll_module(); if (module) { if (!mechanism || strcasecmp(module->name, mechanism) == 0) { - return 0; + return SUCCESS; } } @@ -291,7 +291,7 @@ int fpm_event_pre_init(char *mechanism) /* {{{ */ module = fpm_event_poll_module(); if (module) { if (!mechanism || strcasecmp(module->name, mechanism) == 0) { - return 0; + return SUCCESS; } } @@ -299,7 +299,7 @@ int fpm_event_pre_init(char *mechanism) /* {{{ */ module = fpm_event_select_module(); if (module) { if (!mechanism || strcasecmp(module->name, mechanism) == 0) { - return 0; + return SUCCESS; } } @@ -308,7 +308,7 @@ int fpm_event_pre_init(char *mechanism) /* {{{ */ } else { zlog(ZLOG_ERROR, "unable to find a suitable event mechanism on this system"); } - return -1; + return FAILURE; } /* }}} */ @@ -317,24 +317,24 @@ const char *fpm_event_mechanism_name(void) return module ? module->name : NULL; } -int fpm_event_support_edge_trigger(void) +bool fpm_event_support_edge_trigger(void) { - return module ? module->support_edge_trigger : 0; + return module != NULL && module->support_edge_trigger; } -int fpm_event_init_main(void) +zend_result fpm_event_init_main(void) { struct fpm_worker_pool_s *wp; int max; if (!module) { zlog(ZLOG_ERROR, "no event module found"); - return -1; + return FAILURE; } if (!module->wait) { zlog(ZLOG_ERROR, "Incomplete event implementation. Please open a bug report on https://bugs.php.net."); - return -1; + return FAILURE; } /* count the max number of necessary fds for polling */ @@ -348,15 +348,15 @@ int fpm_event_init_main(void) if (module->init(max) < 0) { zlog(ZLOG_ERROR, "Unable to initialize the event module %s", module->name); - return -1; + return FAILURE; } zlog(ZLOG_DEBUG, "event module is %s and %d fds have been reserved", module->name, max); - if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_event_cleanup, NULL)) { - return -1; + if (fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_event_cleanup, NULL) != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } void fpm_event_loop(int err) /* {{{ */ @@ -488,27 +488,27 @@ void fpm_event_fire(struct fpm_event_s *ev) /* {{{ */ } /* }}} */ -int fpm_event_set(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, void *), void *arg) /* {{{ */ +zend_result fpm_event_set(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, void *), void *arg) /* {{{ */ { if (!ev || !callback || fd < -1) { - return -1; + return FAILURE; } memset(ev, 0, sizeof(struct fpm_event_s)); ev->fd = fd; ev->callback = callback; ev->arg = arg; ev->flags = flags; - return 0; + return SUCCESS; } /* }}} */ -int fpm_event_add(struct fpm_event_s *ev, unsigned long int frequency) /* {{{ */ +zend_result fpm_event_add(struct fpm_event_s *ev, unsigned long int frequency) /* {{{ */ { struct timeval now; struct timeval tmp; if (!ev) { - return -1; + return FAILURE; } ev->index = -1; @@ -516,10 +516,10 @@ int fpm_event_add(struct fpm_event_s *ev, unsigned long int frequency) /* {{{ */ /* it's a triggered event on incoming data */ if (ev->flags & FPM_EV_READ) { ev->which = FPM_EV_READ; - if (fpm_event_queue_add(&fpm_event_queue_fd, ev) != 0) { - return -1; + if (fpm_event_queue_add(&fpm_event_queue_fd, ev) != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } /* it's a timer event */ @@ -536,24 +536,24 @@ int fpm_event_add(struct fpm_event_s *ev, unsigned long int frequency) /* {{{ */ ev->frequency = tmp; fpm_event_set_timeout(ev, now); - if (fpm_event_queue_add(&fpm_event_queue_timer, ev) != 0) { - return -1; + if (fpm_event_queue_add(&fpm_event_queue_timer, ev) != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_event_del(struct fpm_event_s *ev) /* {{{ */ +zend_result fpm_event_del(struct fpm_event_s *ev) /* {{{ */ { - if (ev->index >= 0 && fpm_event_queue_del(&fpm_event_queue_fd, ev) != 0) { - return -1; + if (ev->index >= 0 && fpm_event_queue_del(&fpm_event_queue_fd, ev) != SUCCESS) { + return FAILURE; } - if (ev->index < 0 && fpm_event_queue_del(&fpm_event_queue_timer, ev) != 0) { - return -1; + if (ev->index < 0 && fpm_event_queue_del(&fpm_event_queue_timer, ev) != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_events.h b/sapi/fpm/fpm/fpm_events.h index 5cc2b942ed25b..17c33ee326f14 100644 --- a/sapi/fpm/fpm/fpm_events.h +++ b/sapi/fpm/fpm/fpm_events.h @@ -3,6 +3,10 @@ #ifndef FPM_EVENTS_H #define FPM_EVENTS_H 1 +#include "zend_result.h" + +#include + #define FPM_EV_TIMEOUT (1 << 0) #define FPM_EV_READ (1 << 1) #define FPM_EV_PERSIST (1 << 2) @@ -39,12 +43,12 @@ struct fpm_event_module_s { void fpm_event_loop(int err); void fpm_event_fire(struct fpm_event_s *ev); -int fpm_event_init_main(void); -int fpm_event_set(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, void *), void *arg); -int fpm_event_add(struct fpm_event_s *ev, unsigned long int timeout); -int fpm_event_del(struct fpm_event_s *ev); -int fpm_event_pre_init(char *machanism); +zend_result fpm_event_init_main(void); +zend_result fpm_event_set(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, void *), void *arg); +zend_result fpm_event_add(struct fpm_event_s *ev, unsigned long int timeout); +zend_result fpm_event_del(struct fpm_event_s *ev); +zend_result fpm_event_pre_init(char *machanism); const char *fpm_event_mechanism_name(void); -int fpm_event_support_edge_trigger(void); +bool fpm_event_support_edge_trigger(void); #endif diff --git a/sapi/fpm/fpm/fpm_log.c b/sapi/fpm/fpm/fpm_log.c index bb66c081258d5..28900865ddfbf 100644 --- a/sapi/fpm/fpm/fpm_log.c +++ b/sapi/fpm/fpm/fpm_log.c @@ -29,7 +29,7 @@ static char *fpm_log_format = NULL; static int fpm_log_fd = -1; static struct key_value_s *fpm_access_suppress_paths = NULL; -static int fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc); +static bool fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc); int fpm_log_open(int reopen) /* {{{ */ { @@ -70,10 +70,10 @@ int fpm_log_open(int reopen) /* {{{ */ /* }}} */ /* }}} */ -int fpm_log_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_log_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { if (!wp || !wp->config) { - return -1; + return FAILURE; } if (wp->config->access_log && *wp->config->access_log) { @@ -86,7 +86,7 @@ int fpm_log_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ struct key_value_s *kvcopy = calloc(1, sizeof(*kvcopy)); if (kvcopy == NULL) { zlog(ZLOG_ERROR, "unable to allocate memory while opening the access log"); - return -1; + return FAILURE; } kvcopy->value = strdup(kv->value); kvcopy->next = fpm_access_suppress_paths; @@ -105,11 +105,11 @@ int fpm_log_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } } - return 0; + return SUCCESS; } /* }}} */ -int fpm_log_write(char *log_format) /* {{{ */ +zend_result fpm_log_write(char *log_format) /* {{{ */ { char *s, *b; char buffer[FPM_LOG_BUFFER+1]; @@ -125,7 +125,7 @@ int fpm_log_write(char *log_format) /* {{{ */ #endif if (!log_format && (!fpm_log_format || fpm_log_fd == -1)) { - return -1; + return FAILURE; } if (!log_format) { @@ -141,18 +141,18 @@ int fpm_log_write(char *log_format) /* {{{ */ scoreboard = fpm_scoreboard_get(); if (!scoreboard) { zlog(ZLOG_WARNING, "unable to get scoreboard while preparing the access log"); - return -1; + return FAILURE; } proc_p = fpm_scoreboard_proc_acquire(NULL, -1, 0); if (!proc_p) { zlog(ZLOG_WARNING, "[pool %s] Unable to acquire shm slot while preparing the access log", scoreboard->pool); - return -1; + return FAILURE; } proc = *proc_p; fpm_scoreboard_proc_release(proc_p); if (UNEXPECTED(fpm_access_log_suppress(&proc))) { - return -1; + return FAILURE; } } @@ -206,7 +206,7 @@ int fpm_log_write(char *log_format) /* {{{ */ } } else { zlog(ZLOG_WARNING, "only 'total', 'user' or 'system' are allowed as a modifier for %%%c ('%s')", *s, format); - return -1; + return FAILURE; } format[0] = '\0'; @@ -240,7 +240,7 @@ int fpm_log_write(char *log_format) /* {{{ */ } else { zlog(ZLOG_WARNING, "only 'seconds', 'milli', 'milliseconds', 'micro' or 'microseconds' are allowed as a modifier for %%%c ('%s')", *s, format); - return -1; + return FAILURE; } format[0] = '\0'; break; @@ -248,7 +248,7 @@ int fpm_log_write(char *log_format) /* {{{ */ case 'e': /* fastcgi env */ if (format[0] == '\0') { zlog(ZLOG_WARNING, "the name of the environment variable must be set between embraces for %%%c", *s); - return -1; + return FAILURE; } if (!test) { @@ -297,7 +297,7 @@ int fpm_log_write(char *log_format) /* {{{ */ } else { zlog(ZLOG_WARNING, "only 'bytes', 'kilo', 'kilobytes', 'mega' or 'megabytes' are allowed as a modifier for %%%c ('%s')", *s, format); - return -1; + return FAILURE; } format[0] = '\0'; break; @@ -311,7 +311,7 @@ int fpm_log_write(char *log_format) /* {{{ */ case 'o': /* header output */ if (format[0] == '\0') { zlog(ZLOG_WARNING, "the name of the header must be set between embraces for %%%c", *s); - return -1; + return FAILURE; } if (!test) { sapi_header_struct *h; @@ -448,19 +448,19 @@ int fpm_log_write(char *log_format) /* {{{ */ } if (s[1] == '\0') { zlog(ZLOG_WARNING, "missing closing embrace in the access.format"); - return -1; + return FAILURE; } } break; default: zlog(ZLOG_WARNING, "Invalid token in the access.format (%%%c)", *s); - return -1; + return FAILURE; } if (*s != '}' && format[0] != '\0') { zlog(ZLOG_WARNING, "embrace is not allowed for modifier %%%c", *s); - return -1; + return FAILURE; } s++; if (!test) { @@ -489,15 +489,15 @@ int fpm_log_write(char *log_format) /* {{{ */ zend_quiet_write(fpm_log_fd, buffer, len + 1); } - return 0; + return SUCCESS; } /* }}} */ -static int fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc) +static bool fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc) { // Never suppress when query string is passed if (proc->query_string[0] != '\0') { - return 0; + return false; } // Never suppress if request method is not GET or HEAD @@ -505,25 +505,25 @@ static int fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc) strcmp(proc->request_method, "GET") != 0 && strcmp(proc->request_method, "HEAD") != 0 ) { - return 0; + return false; } // Never suppress when response code does not indicate success if (SG(sapi_headers).http_response_code < 200 || SG(sapi_headers).http_response_code > 299) { - return 0; + return false; } // Never suppress when a body has been sent if (SG(request_info).content_length > 0) { - return 0; + return false; } // Suppress when request URI is an exact match for one of our entries for (struct key_value_s *kv = fpm_access_suppress_paths; kv; kv = kv->next) { if (kv->value && strcmp(kv->value, proc->request_uri) == 0) { - return 1; + return true; } } - return 0; -} \ No newline at end of file + return false; +} diff --git a/sapi/fpm/fpm/fpm_log.h b/sapi/fpm/fpm/fpm_log.h index edad81de2162d..72334e8451e41 100644 --- a/sapi/fpm/fpm/fpm_log.h +++ b/sapi/fpm/fpm/fpm_log.h @@ -4,8 +4,8 @@ #define FPM_LOG_H 1 #include "fpm_worker_pool.h" -int fpm_log_init_child(struct fpm_worker_pool_s *wp); -int fpm_log_write(char *log_format); +zend_result fpm_log_init_child(struct fpm_worker_pool_s *wp); +zend_result fpm_log_write(char *log_format); int fpm_log_open(int reopen); #endif diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 5ba629b395fcb..e133572e3cc15 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1493,7 +1493,7 @@ PHP_FUNCTION(fpm_get_status) /* {{{ */ RETURN_THROWS(); } - if (fpm_status_export_to_zval(return_value)) { + if (fpm_status_export_to_zval(return_value) != SUCCESS) { RETURN_FALSE; } } @@ -1549,7 +1549,7 @@ int main(int argc, char *argv[]) does that for us! thies@thieso.net 20000419 */ - if (0 > fpm_signals_init_mask() || 0 > fpm_signals_block()) { + if (fpm_signals_init_mask() != SUCCESS || fpm_signals_block() != SUCCESS) { zlog(ZLOG_WARNING, "Could die in the case of too early reload signal"); } zlog(ZLOG_DEBUG, "Blocked some signals"); diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index 92b189668206e..8b3d7d211ba21 100644 --- a/sapi/fpm/fpm/fpm_php.c +++ b/sapi/fpm/fpm/fpm_php.c @@ -21,7 +21,7 @@ static char **limit_extensions = NULL; -static int fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_value, int new_value_length, int mode, int stage) /* {{{ */ +static zend_result fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_value, int new_value_length, int mode, int stage) /* {{{ */ { zend_ini_entry *ini_entry; zend_string *duplicate; @@ -111,7 +111,7 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ } /* }}} */ -static int fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */ +static zend_result fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */ { struct key_value_s *kv; @@ -127,21 +127,21 @@ static int fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */ } } - return 0; + return SUCCESS; } /* }}} */ -static int fpm_php_set_allowed_clients(struct fpm_worker_pool_s *wp) /* {{{ */ +static zend_result fpm_php_set_allowed_clients(struct fpm_worker_pool_s *wp) /* {{{ */ { if (wp->listen_address_domain == FPM_AF_INET) { fcgi_set_allowed_clients(wp->config->listen_allowed_clients); } - return 0; + return SUCCESS; } /* }}} */ #if 0 /* Comment out this non used function. It could be used later. */ -static int fpm_php_set_fcgi_mgmt_vars(struct fpm_worker_pool_s *wp) /* {{{ */ +static zend_result fpm_php_set_fcgi_mgmt_vars(struct fpm_worker_pool_s *wp) /* {{{ */ { char max_workers[10 + 1]; /* 4294967295 */ int len; @@ -150,7 +150,7 @@ static int fpm_php_set_fcgi_mgmt_vars(struct fpm_worker_pool_s *wp) /* {{{ */ fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, max_workers, len); fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, max_workers, len); - return 0; + return SUCCESS; } /* }}} */ #endif @@ -200,18 +200,18 @@ void fpm_php_soft_quit(void) fcgi_terminate(); } -int fpm_php_init_main(void) +zend_result fpm_php_init_main(void) { - if (0 > fpm_cleanup_add(FPM_CLEANUP_PARENT, fpm_php_cleanup, 0)) { + if (fpm_cleanup_add(FPM_CLEANUP_PARENT, fpm_php_cleanup, 0) != SUCCESS) { return -1; } return 0; } -int fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { - if (0 > fpm_php_apply_defines(wp) || - 0 > fpm_php_set_allowed_clients(wp)) { + if (fpm_php_apply_defines(wp) != SUCCESS || + fpm_php_set_allowed_clients(wp) != SUCCESS) { return -1; } @@ -224,13 +224,13 @@ int fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ -int fpm_php_limit_extensions(char *path) /* {{{ */ +bool fpm_php_limit_extensions(const char *path) /* {{{ */ { char **p; size_t path_len; if (!path || !limit_extensions) { - return 0; /* allowed by default */ + return false; /* allowed by default */ } p = limit_extensions; @@ -238,9 +238,9 @@ int fpm_php_limit_extensions(char *path) /* {{{ */ while (p && *p) { size_t ext_len = strlen(*p); if (path_len > ext_len) { - char *path_ext = path + path_len - ext_len; + const char *path_ext = path + path_len - ext_len; if (strcmp(*p, path_ext) == 0) { - return 0; /* allow as the extension has been found */ + return false; /* allow as the extension has been found */ } } p++; @@ -248,7 +248,7 @@ int fpm_php_limit_extensions(char *path) /* {{{ */ zlog(ZLOG_NOTICE, "Access to the script '%s' has been denied (see security.limit_extensions)", path); - return 1; /* extension not found: not allowed */ + return true; /* extension not found: not allowed */ } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_php.h b/sapi/fpm/fpm/fpm_php.h index 01ed65799170d..90f8ef2fd116c 100644 --- a/sapi/fpm/fpm/fpm_php.h +++ b/sapi/fpm/fpm/fpm_php.h @@ -30,7 +30,7 @@ struct fpm_worker_pool_s; -int fpm_php_init_child(struct fpm_worker_pool_s *wp); +zend_result fpm_php_init_child(struct fpm_worker_pool_s *wp); char *fpm_php_script_filename(void); char *fpm_php_request_uri(void); char *fpm_php_request_method(void); @@ -38,9 +38,9 @@ char *fpm_php_query_string(void); char *fpm_php_auth_user(void); size_t fpm_php_content_length(void); void fpm_php_soft_quit(void); -int fpm_php_init_main(void); +zend_result fpm_php_init_main(void); int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode); -int fpm_php_limit_extensions(char *path); +bool fpm_php_limit_extensions(const char *path); char* fpm_php_get_string_from_table(zend_string *table, char *key); #endif diff --git a/sapi/fpm/fpm/fpm_php_trace.c b/sapi/fpm/fpm/fpm_php_trace.c index b1535b26e3ef8..cfd1a35ec4f6b 100644 --- a/sapi/fpm/fpm/fpm_php_trace.c +++ b/sapi/fpm/fpm/fpm_php_trace.c @@ -50,19 +50,19 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid); - if (0 > fpm_trace_get_long((long) &SG(request_info).path_translated, &l)) { + if (fpm_trace_get_long((long) &SG(request_info).path_translated, &l) != SUCCESS) { return -1; } path_translated = l; - if (0 > fpm_trace_get_strz(buf, sizeof(buf), path_translated)) { + if (fpm_trace_get_strz(buf, sizeof(buf), path_translated) != SUCCESS) { return -1; } fprintf(slowlog, "script_filename = %s\n", buf); - if (0 > fpm_trace_get_long((long) &EG(current_execute_data), &l)) { + if (fpm_trace_get_long((long) &EG(current_execute_data), &l) != SUCCESS) { return -1; } @@ -75,14 +75,14 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * long prev; uint32_t lineno = 0; - if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, func), &l)) { + if (fpm_trace_get_long(execute_data + offsetof(zend_execute_data, func), &l) != SUCCESS) { return -1; } function = l; if (valid_ptr(function)) { - if (0 > fpm_trace_get_long(function + offsetof(zend_function, common.function_name), &l)) { + if (fpm_trace_get_long(function + offsetof(zend_function, common.function_name), &l) != SUCCESS) { return -1; } @@ -90,7 +90,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * if (function_name == 0) { uint32_t *call_info = (uint32_t *)&l; - if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, This.u1.type_info), &l)) { + if (fpm_trace_get_long(execute_data + offsetof(zend_execute_data, This.u1.type_info), &l) != SUCCESS) { return -1; } @@ -102,7 +102,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * ZEND_UNREACHABLE(); } } else { - if (0 > fpm_trace_get_strz(buf, sizeof(buf), function_name + offsetof(zend_string, val))) { + if (fpm_trace_get_strz(buf, sizeof(buf), function_name + offsetof(zend_string, val)) != SUCCESS) { return -1; } @@ -117,7 +117,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * *buf = '\0'; - if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l)) { + if (fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l) != SUCCESS) { return -1; } @@ -126,7 +126,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * while (prev) { zend_uchar *type; - if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, func), &l)) { + if (fpm_trace_get_long(prev + offsetof(zend_execute_data, func), &l) != SUCCESS) { return -1; } @@ -137,22 +137,22 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * } type = (zend_uchar *)&l; - if (0 > fpm_trace_get_long(function + offsetof(zend_function, type), &l)) { + if (fpm_trace_get_long(function + offsetof(zend_function, type), &l) != SUCCESS) { return -1; } if (ZEND_USER_CODE(*type)) { - if (0 > fpm_trace_get_long(function + offsetof(zend_op_array, filename), &l)) { + if (fpm_trace_get_long(function + offsetof(zend_op_array, filename), &l) != SUCCESS) { return -1; } file_name = l; - if (0 > fpm_trace_get_strz(buf, sizeof(buf), file_name + offsetof(zend_string, val))) { + if (fpm_trace_get_strz(buf, sizeof(buf), file_name + offsetof(zend_string, val)) != SUCCESS) { return -1; } - if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, opline), &l)) { + if (fpm_trace_get_long(prev + offsetof(zend_execute_data, opline), &l) != SUCCESS) { return -1; } @@ -160,7 +160,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * long opline = l; uint32_t *lu = (uint32_t *) &l; - if (0 > fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l)) { + if (fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l) != SUCCESS) { return -1; } @@ -169,7 +169,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * break; } - if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, prev_execute_data), &l)) { + if (fpm_trace_get_long(prev + offsetof(zend_execute_data, prev_execute_data), &l) != SUCCESS) { return -1; } @@ -201,15 +201,15 @@ void fpm_php_trace(struct fpm_child_s *child) /* {{{ */ goto done0; } - if (0 > fpm_trace_ready(child->pid)) { + if (fpm_trace_ready(child->pid) != SUCCESS) { goto done1; } - if (0 > fpm_php_trace_dump(child, slowlog)) { + if (fpm_php_trace_dump(child, slowlog) != SUCCESS) { fprintf(slowlog, "+++ dump failed\n"); } - if (0 > fpm_trace_close(child->pid)) { + if (fpm_trace_close(child->pid) != SUCCESS) { goto done1; } diff --git a/sapi/fpm/fpm/fpm_process_ctl.c b/sapi/fpm/fpm/fpm_process_ctl.c index 48eb0003d4918..072d71eb68de9 100644 --- a/sapi/fpm/fpm/fpm_process_ctl.c +++ b/sapi/fpm/fpm/fpm_process_ctl.c @@ -56,11 +56,10 @@ static void fpm_pctl_action(struct fpm_event_s *ev, short which, void *arg) /* { } /* }}} */ -static int fpm_pctl_timeout_set(int sec) /* {{{ */ +static void fpm_pctl_timeout_set(int sec) /* {{{ */ { fpm_event_set_timer(&pctl_event, 0, &fpm_pctl_action, NULL); fpm_event_add(&pctl_event, sec * 1000); - return 0; } /* }}} */ @@ -78,7 +77,7 @@ static void fpm_pctl_exit(void) static void fpm_pctl_exec(void) { zlog(ZLOG_DEBUG, "Blocking some signals before reexec"); - if (0 > fpm_signals_block()) { + if (fpm_signals_block() != SUCCESS) { zlog(ZLOG_WARNING, "concurrent reloads may be unstable"); } @@ -122,7 +121,7 @@ static void fpm_pctl_action_last(void) } } -int fpm_pctl_kill(pid_t pid, int how) /* {{{ */ +zend_result fpm_pctl_kill(pid_t pid, int how) /* {{{ */ { int s = 0; @@ -145,7 +144,7 @@ int fpm_pctl_kill(pid_t pid, int how) /* {{{ */ default : break; } - return kill(pid, s); + return kill(pid, s) == 0 ? SUCCESS : FAILURE; } /* }}} */ @@ -250,24 +249,23 @@ void fpm_pctl(int new_state, int action) /* {{{ */ } /* }}} */ -int fpm_pctl_can_spawn_children(void) +bool fpm_pctl_can_spawn_children(void) { return fpm_state == FPM_PCTL_STATE_NORMAL; } -int fpm_pctl_child_exited(void) +void fpm_pctl_child_exited(void) { if (fpm_state == FPM_PCTL_STATE_NORMAL) { - return 0; + return; } if (!fpm_globals.running_children) { fpm_pctl(FPM_PCTL_STATE_UNSPECIFIED, FPM_PCTL_ACTION_LAST_CHILD_EXITED); } - return 0; } -int fpm_pctl_init_main(void) +zend_result fpm_pctl_init_main(void) { int i; @@ -275,23 +273,23 @@ int fpm_pctl_init_main(void) saved_argv = malloc(sizeof(char *) * (saved_argc + 1)); if (!saved_argv) { - return -1; + return FAILURE; } for (i = 0; i < saved_argc; i++) { saved_argv[i] = strdup(fpm_globals.argv[i]); if (!saved_argv[i]) { - return -1; + return FAILURE; } } saved_argv[i] = 0; - if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_pctl_cleanup, 0)) { - return -1; + if (fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_pctl_cleanup, 0) != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } static void fpm_pctl_check_request_timeout(struct timeval *now) /* {{{ */ @@ -340,7 +338,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{ /* update status structure for all PMs */ if (wp->listen_address_domain == FPM_AF_INET) { - if (0 > fpm_socket_get_listening_queue(wp->listening_socket, &cur_lq, NULL)) { + if (fpm_socket_get_listening_queue(wp->listening_socket, &cur_lq, NULL) != SUCCESS) { cur_lq = 0; #if 0 } else { diff --git a/sapi/fpm/fpm/fpm_process_ctl.h b/sapi/fpm/fpm/fpm_process_ctl.h index 0db7044c17b81..f111f237aa2a9 100644 --- a/sapi/fpm/fpm/fpm_process_ctl.h +++ b/sapi/fpm/fpm/fpm_process_ctl.h @@ -14,14 +14,14 @@ struct fpm_child_s; void fpm_pctl(int new_state, int action); -int fpm_pctl_can_spawn_children(void); -int fpm_pctl_kill(pid_t pid, int how); +bool fpm_pctl_can_spawn_children(void); +zend_result fpm_pctl_kill(pid_t pid, int how); void fpm_pctl_kill_all(int signo); void fpm_pctl_heartbeat(struct fpm_event_s *ev, short which, void *arg); void fpm_pctl_perform_idle_server_maintenance_heartbeat(struct fpm_event_s *ev, short which, void *arg); void fpm_pctl_on_socket_accept(struct fpm_event_s *ev, short which, void *arg); -int fpm_pctl_child_exited(void); -int fpm_pctl_init_main(void); +void fpm_pctl_child_exited(void); +zend_result fpm_pctl_init_main(void); enum { diff --git a/sapi/fpm/fpm/fpm_scoreboard.c b/sapi/fpm/fpm/fpm_scoreboard.c index 52d10a0416832..19655980e1c34 100644 --- a/sapi/fpm/fpm/fpm_scoreboard.c +++ b/sapi/fpm/fpm/fpm_scoreboard.c @@ -21,7 +21,7 @@ static float fpm_scoreboard_tick; #endif -int fpm_scoreboard_init_main(void) +zend_result fpm_scoreboard_init_main(void) { struct fpm_worker_pool_s *wp; @@ -45,19 +45,19 @@ int fpm_scoreboard_init_main(void) if (wp->config->pm_max_children < 1) { zlog(ZLOG_ERROR, "[pool %s] Unable to create scoreboard SHM because max_client is not set", wp->config->name); - return -1; + return FAILURE; } if (wp->scoreboard) { zlog(ZLOG_ERROR, "[pool %s] Unable to create scoreboard SHM because it already exists", wp->config->name); - return -1; + return FAILURE; } scoreboard_procs_size = sizeof(struct fpm_scoreboard_proc_s) * wp->config->pm_max_children; shm_mem = fpm_shm_alloc(sizeof(struct fpm_scoreboard_s) + scoreboard_procs_size); if (!shm_mem) { - return -1; + return FAILURE; } wp->scoreboard = shm_mem; wp->scoreboard->pm = wp->config->pm; @@ -70,7 +70,7 @@ int fpm_scoreboard_init_main(void) wp->scoreboard->shared = wp->shared->scoreboard; } } - return 0; + return SUCCESS; } static struct fpm_scoreboard_s *fpm_scoreboard_get_for_update(struct fpm_scoreboard_s *scoreboard) /* {{{ */ @@ -392,7 +392,7 @@ void fpm_scoreboard_proc_free(struct fpm_child_s *child) /* {{{ */ } /* }}} */ -int fpm_scoreboard_proc_alloc(struct fpm_child_s *child) /* {{{ */ +zend_result fpm_scoreboard_proc_alloc(struct fpm_child_s *child) /* {{{ */ { int i = -1; struct fpm_worker_pool_s *wp = child->wp; @@ -400,7 +400,7 @@ int fpm_scoreboard_proc_alloc(struct fpm_child_s *child) /* {{{ */ int nprocs = wp->config->pm_max_children; if (!scoreboard) { - return -1; + return FAILURE; } /* first try the slot which is supposed to be free */ @@ -422,7 +422,7 @@ int fpm_scoreboard_proc_alloc(struct fpm_child_s *child) /* {{{ */ /* no free slot */ if (i < 0 || i >= nprocs) { zlog(ZLOG_ERROR, "[pool %s] no free scoreboard slot", scoreboard->pool); - return -1; + return FAILURE; } scoreboard->procs[i].used = 1; @@ -435,7 +435,7 @@ int fpm_scoreboard_proc_alloc(struct fpm_child_s *child) /* {{{ */ scoreboard->free_proc = i + 1; } - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_scoreboard.h b/sapi/fpm/fpm/fpm_scoreboard.h index c488c64bfefc4..f3452df64e38d 100644 --- a/sapi/fpm/fpm/fpm_scoreboard.h +++ b/sapi/fpm/fpm/fpm_scoreboard.h @@ -70,8 +70,7 @@ struct fpm_scoreboard_s { struct fpm_scoreboard_proc_s procs[]; }; -int fpm_scoreboard_init_main(void); -int fpm_scoreboard_init_child(struct fpm_worker_pool_s *wp); +zend_result fpm_scoreboard_init_main(void); void fpm_scoreboard_update_begin(struct fpm_scoreboard_s *scoreboard); void fpm_scoreboard_update_commit(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int slow_rq, int action, struct fpm_scoreboard_s *scoreboard); @@ -91,7 +90,7 @@ void fpm_scoreboard_free(struct fpm_worker_pool_s *wp); void fpm_scoreboard_child_use(struct fpm_child_s *child, pid_t pid); void fpm_scoreboard_proc_free(struct fpm_child_s *child); -int fpm_scoreboard_proc_alloc(struct fpm_child_s *child); +zend_result fpm_scoreboard_proc_alloc(struct fpm_child_s *child); struct fpm_scoreboard_s *fpm_scoreboard_copy(struct fpm_scoreboard_s *scoreboard, int copy_procs); void fpm_scoreboard_free_copy(struct fpm_scoreboard_s *scoreboard); diff --git a/sapi/fpm/fpm/fpm_signals.c b/sapi/fpm/fpm/fpm_signals.c index aca7c9ed58cc4..13d8938a00d07 100644 --- a/sapi/fpm/fpm/fpm_signals.c +++ b/sapi/fpm/fpm/fpm_signals.c @@ -182,23 +182,23 @@ static void sig_handler(int signo) /* {{{ */ } /* }}} */ -int fpm_signals_init_main(void) +zend_result fpm_signals_init_main(void) { struct sigaction act; if (0 > socketpair(AF_UNIX, SOCK_STREAM, 0, sp)) { zlog(ZLOG_SYSERROR, "failed to init signals: socketpair()"); - return -1; + return FAILURE; } - if (0 > fd_set_blocked(sp[0], 0) || 0 > fd_set_blocked(sp[1], 0)) { + if (fd_set_blocked(sp[0], 0) != SUCCESS || fd_set_blocked(sp[1], 0) != SUCCESS) { zlog(ZLOG_SYSERROR, "failed to init signals: fd_set_blocked()"); - return -1; + return FAILURE; } if (0 > fcntl(sp[0], F_SETFD, FD_CLOEXEC) || 0 > fcntl(sp[1], F_SETFD, FD_CLOEXEC)) { zlog(ZLOG_SYSERROR, "failed to init signals: fcntl(F_SETFD, FD_CLOEXEC)"); - return -1; + return FAILURE; } memset(&act, 0, sizeof(act)); @@ -213,17 +213,17 @@ int fpm_signals_init_main(void) 0 > sigaction(SIGQUIT, &act, 0)) { zlog(ZLOG_SYSERROR, "failed to init signals: sigaction()"); - return -1; + return FAILURE; } zlog(ZLOG_DEBUG, "Unblocking all signals"); - if (0 > fpm_signals_unblock()) { - return -1; + if (fpm_signals_unblock() != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } -int fpm_signals_init_child(void) +zend_result fpm_signals_init_child(void) { struct sigaction act, act_dfl; @@ -246,15 +246,15 @@ int fpm_signals_init_child(void) 0 > sigaction(SIGQUIT, &act, 0)) { zlog(ZLOG_SYSERROR, "failed to init child signals: sigaction()"); - return -1; + return FAILURE; } zend_signal_init(); - if (0 > fpm_signals_unblock()) { - return -1; + if (fpm_signals_unblock() != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } int fpm_signals_get_fd(void) @@ -262,7 +262,7 @@ int fpm_signals_get_fd(void) return sp[0]; } -int fpm_signals_init_mask(void) +zend_result fpm_signals_init_mask(void) { /* Subset of signals from fpm_signals_init_main() and fpm_got_signal() blocked to avoid unexpected death during early init @@ -273,7 +273,7 @@ int fpm_signals_init_mask(void) if (0 > sigemptyset(&block_sigset) || 0 > sigemptyset(&child_block_sigset)) { zlog(ZLOG_SYSERROR, "failed to prepare signal block mask: sigemptyset()"); - return -1; + return FAILURE; } for (i = 0; i < size; ++i) { int sig_i = init_signal_array[i]; @@ -285,36 +285,36 @@ int fpm_signals_init_mask(void) } else { zlog(ZLOG_SYSERROR, "failed to prepare signal block mask: sigaddset(%d)", sig_i); } - return -1; + return FAILURE; } } if (0 > sigaddset(&child_block_sigset, SIGTERM) || 0 > sigaddset(&child_block_sigset, SIGQUIT)) { zlog(ZLOG_SYSERROR, "failed to prepare child signal block mask: sigaddset()"); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } -int fpm_signals_block(void) +zend_result fpm_signals_block(void) { if (0 > sigprocmask(SIG_BLOCK, &block_sigset, NULL)) { zlog(ZLOG_SYSERROR, "failed to block signals"); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } -int fpm_signals_child_block(void) +zend_result fpm_signals_child_block(void) { if (0 > sigprocmask(SIG_BLOCK, &child_block_sigset, NULL)) { zlog(ZLOG_SYSERROR, "failed to block child signals"); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } -int fpm_signals_unblock(void) +zend_result fpm_signals_unblock(void) { /* Ensure that during reload after upgrade all signals are unblocked. block_sigset could have different value before execve() */ @@ -322,7 +322,7 @@ int fpm_signals_unblock(void) sigfillset(&all_signals); if (0 > sigprocmask(SIG_UNBLOCK, &all_signals, NULL)) { zlog(ZLOG_SYSERROR, "failed to unblock signals"); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } diff --git a/sapi/fpm/fpm/fpm_signals.h b/sapi/fpm/fpm/fpm_signals.h index 67c12efdf4bac..e18627adf2ce8 100644 --- a/sapi/fpm/fpm/fpm_signals.h +++ b/sapi/fpm/fpm/fpm_signals.h @@ -3,15 +3,17 @@ #ifndef FPM_SIGNALS_H #define FPM_SIGNALS_H 1 +#include "zend_result.h" + #include -int fpm_signals_init_main(void); -int fpm_signals_init_child(void); +zend_result fpm_signals_init_main(void); +zend_result fpm_signals_init_child(void); int fpm_signals_get_fd(void); -int fpm_signals_init_mask(void); -int fpm_signals_block(void); -int fpm_signals_child_block(void); -int fpm_signals_unblock(void); +zend_result fpm_signals_init_mask(void); +zend_result fpm_signals_block(void); +zend_result fpm_signals_child_block(void); +zend_result fpm_signals_unblock(void); extern const char *fpm_signal_names[NSIG + 1]; diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c index 66488b9bf000e..dc34e822bb58e 100644 --- a/sapi/fpm/fpm/fpm_sockets.c +++ b/sapi/fpm/fpm/fpm_sockets.c @@ -219,7 +219,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct } if (wp->listen_address_domain == FPM_AF_UNIX) { - if (fpm_socket_unix_test_connect((struct sockaddr_un *)sa, socklen) == 0) { + if (fpm_socket_unix_test_connect((struct sockaddr_un *)sa, socklen) == SUCCESS) { zlog(ZLOG_ERROR, "Another FPM instance seems to already listen on %s", ((struct sockaddr_un *) sa)->sun_path); close(sock); return -1; @@ -242,7 +242,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct umask(saved_umask); - if (0 > fpm_unix_set_socket_permissions(wp, path)) { + if (fpm_unix_set_socket_permissions(wp, path) != SUCCESS) { close(sock); return -1; } @@ -418,7 +418,7 @@ static zend_result fpm_socket_setfib_init(void) } #endif -int fpm_sockets_init_main(void) +zend_result fpm_sockets_init_main(void) { unsigned i, lq_len; struct fpm_worker_pool_s *wp; @@ -428,12 +428,12 @@ int fpm_sockets_init_main(void) struct listening_socket_s *ls; if (0 == fpm_array_init(&sockets_list, sizeof(struct listening_socket_s), 10)) { - return -1; + return FAILURE; } #ifdef SO_SETFIB if (fpm_socket_setfib_init() == FAILURE) { - return -1; + return FAILURE; } #endif @@ -485,15 +485,15 @@ int fpm_sockets_init_main(void) break; case FPM_AF_UNIX : - if (0 > fpm_unix_resolve_socket_permissions(wp)) { - return -1; + if (fpm_unix_resolve_socket_permissions(wp) != SUCCESS) { + return FAILURE; } wp->listening_socket = fpm_socket_af_unix_listening_socket(wp); break; } if (wp->listening_socket == -1) { - return -1; + return FAILURE; } if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len) >= 0) { @@ -518,10 +518,10 @@ int fpm_sockets_init_main(void) } } - if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_sockets_cleanup, 0)) { - return -1; + if (fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_sockets_cleanup, 0) != SUCCESS) { + return FAILURE; } - return 0; + return SUCCESS; } #if HAVE_FPM_LQ @@ -530,18 +530,18 @@ int fpm_sockets_init_main(void) #include -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +zend_result fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) { struct tcp_info info; socklen_t len = sizeof(info); if (0 > getsockopt(sock, IPPROTO_TCP, TCP_INFO, &info, &len)) { zlog(ZLOG_SYSERROR, "failed to retrieve TCP_INFO for socket"); - return -1; + return FAILURE; } #if defined(__FreeBSD__) || defined(__NetBSD__) if (info.__tcpi_sacked == 0) { - return -1; + return FAILURE; } if (cur_lq) { @@ -554,7 +554,7 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) #else /* kernel >= 2.6.24 return non-zero here, that means operation is supported */ if (info.tcpi_sacked == 0) { - return -1; + return FAILURE; } if (cur_lq) { @@ -566,21 +566,21 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) } #endif - return 0; + return SUCCESS; } #elif defined(HAVE_LQ_TCP_CONNECTION_INFO) #include -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +zend_result fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) { struct tcp_connection_info info; socklen_t len = sizeof(info); if (0 > getsockopt(sock, IPPROTO_TCP, TCP_CONNECTION_INFO, &info, &len)) { zlog(ZLOG_SYSERROR, "failed to retrieve TCP_CONNECTION_INFO for socket"); - return -1; + return FAILURE; } if (cur_lq) { @@ -591,20 +591,20 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) *max_lq = 0; } - return 0; + return SUCCESS; } #endif #ifdef HAVE_LQ_SO_LISTENQ -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +zend_result fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) { int val; socklen_t len = sizeof(val); if (cur_lq) { if (0 > getsockopt(sock, SOL_SOCKET, SO_LISTENQLEN, &val, &len)) { - return -1; + return FAILURE; } *cur_lq = val; @@ -612,44 +612,44 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) if (max_lq) { if (0 > getsockopt(sock, SOL_SOCKET, SO_LISTENQLIMIT, &val, &len)) { - return -1; + return FAILURE; } *max_lq = val; } - return 0; + return SUCCESS; } #endif #else -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +zend_result fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) { - return -1; + return FAILURE; } #endif -int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */ +zend_result fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */ { int fd; if (!sock || sock->sun_family != AF_UNIX) { - return -1; + return FAILURE; } if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - return -1; + return FAILURE; } if (connect(fd, (struct sockaddr *)sock, socklen) == -1) { close(fd); - return -1; + return FAILURE; } close(fd); - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_sockets.h b/sapi/fpm/fpm/fpm_sockets.h index 94d903ca45564..1dcd306a059c8 100644 --- a/sapi/fpm/fpm/fpm_sockets.h +++ b/sapi/fpm/fpm/fpm_sockets.h @@ -27,17 +27,17 @@ #define FPM_ENV_SOCKET_SET_SIZE 128 enum fpm_address_domain fpm_sockets_domain_from_address(char *addr); -int fpm_sockets_init_main(void); -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq); -int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen); +zend_result fpm_sockets_init_main(void); +zend_result fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq); +zend_result fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen); -static inline int fd_set_blocked(int fd, int blocked) /* {{{ */ +static inline zend_result fd_set_blocked(int fd, int blocked) /* {{{ */ { int flags = fcntl(fd, F_GETFL); if (flags < 0) { - return -1; + return FAILURE; } if (blocked) { @@ -45,7 +45,7 @@ static inline int fd_set_blocked(int fd, int blocked) /* {{{ */ } else { flags |= O_NONBLOCK; } - return fcntl(fd, F_SETFL, flags); + return fcntl(fd, F_SETFL, flags) == 0 ? SUCCESS : FAILURE; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index 514d60d176e39..bd9f7c8d06ee0 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -20,11 +20,11 @@ static char *fpm_status_ping_uri = NULL; static char *fpm_status_ping_response = NULL; -int fpm_status_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_status_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { if (!wp || !wp->config) { zlog(ZLOG_ERROR, "unable to init fpm_status because conf structure is NULL"); - return -1; + return FAILURE; } if (wp->config->pm_status_path) { @@ -34,17 +34,17 @@ int fpm_status_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ if (wp->config->ping_path) { if (!wp->config->ping_response) { zlog(ZLOG_ERROR, "[pool %s] ping is set (%s) but ping.response is not set.", wp->config->name, wp->config->ping_path); - return -1; + return FAILURE; } fpm_status_ping_uri = strdup(wp->config->ping_path); fpm_status_ping_response = strdup(wp->config->ping_response); } - return 0; + return SUCCESS; } /* }}} */ -int fpm_status_export_to_zval(zval *status) +zend_result fpm_status_export_to_zval(zval *status) { struct fpm_scoreboard_s scoreboard, *scoreboard_p; zval fpm_proc_stats, fpm_proc_stat; @@ -56,7 +56,7 @@ int fpm_status_export_to_zval(zval *status) scoreboard_p = fpm_scoreboard_acquire(NULL, 1); if (!scoreboard_p) { zlog(ZLOG_NOTICE, "[pool %s] status: scoreboard already in use.", scoreboard_p->pool); - return -1; + return FAILURE; } /* copy the scoreboard not to bother other processes */ @@ -130,7 +130,7 @@ int fpm_status_export_to_zval(zval *status) add_next_index_zval(&fpm_proc_stats, &fpm_proc_stat); } add_assoc_zval(status, "procs", &fpm_proc_stats); - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_status.h b/sapi/fpm/fpm/fpm_status.h index bc90c6a9df681..03cf349575e8e 100644 --- a/sapi/fpm/fpm/fpm_status.h +++ b/sapi/fpm/fpm/fpm_status.h @@ -19,14 +19,14 @@ struct fpm_status_s { struct timeval last_update; }; -int fpm_status_init_child(struct fpm_worker_pool_s *wp); +zend_result fpm_status_init_child(struct fpm_worker_pool_s *wp); void fpm_status_update_activity(struct fpm_shm_s *shm, int idle, int active, int total, unsigned cur_lq, int max_lq, int clear_last_update); void fpm_status_update_accepted_conn(struct fpm_shm_s *shm, unsigned long int accepted_conn); void fpm_status_increment_accepted_conn(struct fpm_shm_s *shm); void fpm_status_set_pm(struct fpm_shm_s *shm, int pm); void fpm_status_update_max_children_reached(struct fpm_shm_s *shm, unsigned int max_children_reached); void fpm_status_increment_max_children_reached(struct fpm_shm_s *shm); -int fpm_status_export_to_zval(zval *status); +zend_result fpm_status_export_to_zval(zval *status); int fpm_status_handle_request(void); extern struct fpm_shm_s *fpm_status_shm; diff --git a/sapi/fpm/fpm/fpm_stdio.c b/sapi/fpm/fpm/fpm_stdio.c index a6c0793d9347e..5be0ffc1f68c7 100644 --- a/sapi/fpm/fpm/fpm_stdio.c +++ b/sapi/fpm/fpm/fpm_stdio.c @@ -24,25 +24,25 @@ static int fd_stderr_original = -1; static int fd_stdout[2]; static int fd_stderr[2]; -int fpm_stdio_init_main(void) +zend_result fpm_stdio_init_main(void) { int fd = open("/dev/null", O_RDWR); if (0 > fd) { zlog(ZLOG_SYSERROR, "failed to init stdio: open(\"/dev/null\")"); - return -1; + return FAILURE; } if (0 > dup2(fd, STDIN_FILENO) || 0 > dup2(fd, STDOUT_FILENO)) { zlog(ZLOG_SYSERROR, "failed to init stdio: dup2()"); close(fd); - return -1; + return FAILURE; } close(fd); - return 0; + return SUCCESS; } -static inline int fpm_use_error_log(void) { +static inline bool fpm_use_error_log(void) { /* * the error_log is NOT used when running in foreground * and from a tty (user looking at output). @@ -55,25 +55,25 @@ static inline int fpm_use_error_log(void) { #else if (fpm_global_config.daemonize) { #endif - return 1; + return true; } - return 0; + return false; } -int fpm_stdio_init_final(void) +zend_result fpm_stdio_init_final(void) { - if (0 > fpm_stdio_redirect_stderr_to_error_log() || - 0 > fpm_stdio_redirect_stderr_to_dev_null_for_syslog()) { + if (fpm_stdio_redirect_stderr_to_error_log() != SUCCESS || + fpm_stdio_redirect_stderr_to_dev_null_for_syslog() != SUCCESS) { - return -1; + return FAILURE; } zlog_set_launched(); - return 0; + return SUCCESS; } /* }}} */ -int fpm_stdio_save_original_stderr(void) +zend_result fpm_stdio_save_original_stderr(void) { /* STDERR fd gets lost after calling fpm_stdio_init_final() (check GH-8555) so it can be saved. * It should be used only when PHP-FPM is not daemonized otherwise it might break some @@ -82,20 +82,20 @@ int fpm_stdio_save_original_stderr(void) fd_stderr_original = dup(STDERR_FILENO); if (0 > fd_stderr_original) { zlog(ZLOG_SYSERROR, "failed to save original STDERR fd, access.log records may appear in error_log: dup()"); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } -int fpm_stdio_restore_original_stderr(int close_after_restore) +zend_result fpm_stdio_restore_original_stderr(int close_after_restore) { /* Restore original STDERR fd if it was previously saved. */ if (-1 != fd_stderr_original) { zlog(ZLOG_DEBUG, "restoring original STDERR fd: dup2()"); if (0 > dup2(fd_stderr_original, STDERR_FILENO)) { zlog(ZLOG_SYSERROR, "failed to restore original STDERR fd, access.log records may appear in error_log: dup2()"); - return -1; + return FAILURE; } else { if (close_after_restore) { close(fd_stderr_original); @@ -103,10 +103,10 @@ int fpm_stdio_restore_original_stderr(int close_after_restore) } } - return 0; + return SUCCESS; } -int fpm_stdio_redirect_stderr_to_error_log(void) +zend_result fpm_stdio_redirect_stderr_to_error_log(void) { if (fpm_use_error_log()) { /* prevent duping if logging to syslog */ @@ -115,15 +115,15 @@ int fpm_stdio_redirect_stderr_to_error_log(void) /* there might be messages to stderr from other parts of the code, we need to log them all */ if (0 > dup2(fpm_globals.error_log_fd, STDERR_FILENO)) { zlog(ZLOG_SYSERROR, "failed to tie stderr fd with error_log fd: dup2()"); - return -1; + return FAILURE; } } } - return 0; + return SUCCESS; } -int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void) +zend_result fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void) { if (fpm_use_error_log()) { #ifdef HAVE_SYSLOG_H @@ -134,10 +134,10 @@ int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void) #endif } - return 0; + return SUCCESS; } -int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { #ifdef HAVE_SYSLOG_H if (fpm_globals.error_log_fd == ZLOG_SYSLOG) { @@ -155,13 +155,13 @@ int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ fpm_globals.error_log_fd = -1; zlog_set_fd(-1); - return 0; + return SUCCESS; } /* }}} */ #define FPM_STDIO_CMD_FLUSH "\0fscf" -int fpm_stdio_flush_child(void) +zend_result fpm_stdio_flush_child(void) { return write(STDERR_FILENO, FPM_STDIO_CMD_FLUSH, sizeof(FPM_STDIO_CMD_FLUSH)); } @@ -287,40 +287,40 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg) } /* }}} */ -int fpm_stdio_prepare_pipes(struct fpm_child_s *child) /* {{{ */ +zend_result fpm_stdio_prepare_pipes(struct fpm_child_s *child) /* {{{ */ { if (0 == child->wp->config->catch_workers_output) { /* not required */ - return 0; + return SUCCESS; } if (0 > pipe(fd_stdout)) { zlog(ZLOG_SYSERROR, "failed to prepare the stdout pipe"); - return -1; + return FAILURE; } if (0 > pipe(fd_stderr)) { zlog(ZLOG_SYSERROR, "failed to prepare the stderr pipe"); close(fd_stdout[0]); close(fd_stdout[1]); - return -1; + return FAILURE; } - if (0 > fd_set_blocked(fd_stdout[0], 0) || 0 > fd_set_blocked(fd_stderr[0], 0)) { + if (fd_set_blocked(fd_stdout[0], 0) != SUCCESS || fd_set_blocked(fd_stderr[0], 0) != SUCCESS) { zlog(ZLOG_SYSERROR, "failed to unblock pipes"); close(fd_stdout[0]); close(fd_stdout[1]); close(fd_stderr[0]); close(fd_stderr[1]); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */ +zend_result fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */ { if (0 == child->wp->config->catch_workers_output) { /* not required */ - return 0; + return SUCCESS; } close(fd_stdout[1]); @@ -334,14 +334,14 @@ int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */ fpm_event_set(&child->ev_stderr, child->fd_stderr, FPM_EV_READ, fpm_stdio_child_said, (void *) (intptr_t) child->pid); fpm_event_add(&child->ev_stderr, 0); - return 0; + return SUCCESS; } /* }}} */ -int fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */ +zend_result fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */ { if (0 == child->wp->config->catch_workers_output) { /* not required */ - return 0; + return SUCCESS; } close(fd_stdout[1]); @@ -349,7 +349,7 @@ int fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */ close(fd_stdout[0]); close(fd_stderr[0]); - return 0; + return SUCCESS; } /* }}} */ @@ -367,7 +367,7 @@ void fpm_stdio_child_use_pipes(struct fpm_child_s *child) /* {{{ */ } /* }}} */ -int fpm_stdio_open_error_log(int reopen) /* {{{ */ +zend_result fpm_stdio_open_error_log(int reopen) /* {{{ */ { int fd; @@ -378,14 +378,14 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */ if (fpm_use_error_log()) { zlog_set_fd(fpm_globals.error_log_fd); } - return 0; + return SUCCESS; } #endif fd = open(fpm_global_config.error_log, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); if (0 > fd) { zlog(ZLOG_SYSERROR, "failed to open error_log (%s)", fpm_global_config.error_log); - return -1; + return FAILURE; } if (reopen) { @@ -401,6 +401,6 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */ if (0 > fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)) { zlog(ZLOG_WARNING, "failed to change attribute of error_log"); } - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_stdio.h b/sapi/fpm/fpm/fpm_stdio.h index 49be50de562d9..f5d930d013ffd 100644 --- a/sapi/fpm/fpm/fpm_stdio.h +++ b/sapi/fpm/fpm/fpm_stdio.h @@ -7,18 +7,18 @@ #define STREAM_SET_MSG_PREFIX_FMT "[pool %s] child %d said into %s: " -int fpm_stdio_init_main(void); -int fpm_stdio_init_final(void); -int fpm_stdio_init_child(struct fpm_worker_pool_s *wp); -int fpm_stdio_flush_child(void); -int fpm_stdio_prepare_pipes(struct fpm_child_s *child); +zend_result fpm_stdio_init_main(void); +zend_result fpm_stdio_init_final(void); +zend_result fpm_stdio_init_child(struct fpm_worker_pool_s *wp); +zend_result fpm_stdio_flush_child(void); +zend_result fpm_stdio_prepare_pipes(struct fpm_child_s *child); void fpm_stdio_child_use_pipes(struct fpm_child_s *child); -int fpm_stdio_parent_use_pipes(struct fpm_child_s *child); -int fpm_stdio_discard_pipes(struct fpm_child_s *child); -int fpm_stdio_open_error_log(int reopen); -int fpm_stdio_save_original_stderr(void); -int fpm_stdio_restore_original_stderr(int close_after_restore); -int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void); -int fpm_stdio_redirect_stderr_to_error_log(void); +zend_result fpm_stdio_parent_use_pipes(struct fpm_child_s *child); +zend_result fpm_stdio_discard_pipes(struct fpm_child_s *child); +zend_result fpm_stdio_open_error_log(int reopen); +zend_result fpm_stdio_save_original_stderr(void); +zend_result fpm_stdio_restore_original_stderr(int close_after_restore); +zend_result fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void); +zend_result fpm_stdio_redirect_stderr_to_error_log(void); #endif diff --git a/sapi/fpm/fpm/fpm_systemd.c b/sapi/fpm/fpm/fpm_systemd.c index 175312412330f..7200ae69e0f9c 100644 --- a/sapi/fpm/fpm/fpm_systemd.c +++ b/sapi/fpm/fpm/fpm_systemd.c @@ -78,7 +78,7 @@ void fpm_systemd_heartbeat(struct fpm_event_s *ev, short which, void *arg) /* {{ } /* }}} */ -int fpm_systemd_conf(void) +zend_result fpm_systemd_conf(void) { char *watchdog; int interval = 0; @@ -106,5 +106,5 @@ int fpm_systemd_conf(void) /* sec to msec */ fpm_global_config.systemd_interval *= 1000; } - return 0; + return SUCCESS; } diff --git a/sapi/fpm/fpm/fpm_systemd.h b/sapi/fpm/fpm/fpm_systemd.h index 93a70fb5266e4..434f24cbdcb7a 100644 --- a/sapi/fpm/fpm/fpm_systemd.h +++ b/sapi/fpm/fpm/fpm_systemd.h @@ -7,6 +7,6 @@ #define FPM_SYSTEMD_DEFAULT_HEARTBEAT (10000) void fpm_systemd_heartbeat(struct fpm_event_s *ev, short which, void *arg); -int fpm_systemd_conf(void); +zend_result fpm_systemd_conf(void); #endif diff --git a/sapi/fpm/fpm/fpm_trace.c b/sapi/fpm/fpm/fpm_trace.c index 3d0b9de98a0bb..b489f2c12e499 100644 --- a/sapi/fpm/fpm/fpm_trace.c +++ b/sapi/fpm/fpm/fpm_trace.c @@ -6,7 +6,7 @@ #include "fpm_trace.h" -int fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */ +zend_result fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */ { int i; long l = addr; @@ -15,8 +15,8 @@ int fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */ i = l % SIZEOF_LONG; l -= i; for (addr = l; ; addr += SIZEOF_LONG) { - if (0 > fpm_trace_get_long(addr, &l)) { - return -1; + if (fpm_trace_get_long(addr, &l) != SUCCESS) { + return FAILURE; } for ( ; i < SIZEOF_LONG; i++) { --sz; @@ -25,7 +25,7 @@ int fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */ continue; } *buf = '\0'; - return 0; + return SUCCESS; } i = 0; } diff --git a/sapi/fpm/fpm/fpm_trace.h b/sapi/fpm/fpm/fpm_trace.h index 4ee021229db6d..f971995f6e2c2 100644 --- a/sapi/fpm/fpm/fpm_trace.h +++ b/sapi/fpm/fpm/fpm_trace.h @@ -3,12 +3,15 @@ #ifndef FPM_TRACE_H #define FPM_TRACE_H 1 +#include "zend_result.h" + +#include #include -int fpm_trace_signal(pid_t pid); -int fpm_trace_ready(pid_t pid); -int fpm_trace_close(pid_t pid); -int fpm_trace_get_long(long addr, long *data); -int fpm_trace_get_strz(char *buf, size_t sz, long addr); +zend_result fpm_trace_signal(pid_t pid); +zend_result fpm_trace_ready(pid_t pid); +zend_result fpm_trace_close(pid_t pid); +zend_result fpm_trace_get_long(long addr, long *data); +zend_result fpm_trace_get_strz(char *buf, size_t sz, long addr); #endif diff --git a/sapi/fpm/fpm/fpm_trace_mach.c b/sapi/fpm/fpm/fpm_trace_mach.c index 092858e287d46..412bd5a5037b0 100644 --- a/sapi/fpm/fpm/fpm_trace_mach.c +++ b/sapi/fpm/fpm/fpm_trace_mach.c @@ -28,30 +28,30 @@ static void fpm_mach_vm_deallocate(void) } } -static int fpm_mach_vm_read_page(vm_offset_t page) /* {{{ */ +static zend_result fpm_mach_vm_read_page(vm_offset_t page) /* {{{ */ { kern_return_t kr; kr = mach_vm_read(target, page, fpm_pagesize, &local_page, &local_size); if (kr != KERN_SUCCESS) { zlog(ZLOG_ERROR, "failed to read vm page: mach_vm_read(): %s (%d)", mach_error_string(kr), kr); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_signal(pid_t pid) /* {{{ */ +zend_result fpm_trace_signal(pid_t pid) /* {{{ */ { - if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) { + if (fpm_pctl_kill(pid, FPM_PCTL_STOP) != SUCCESS) { zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_ready(pid_t pid) /* {{{ */ +zend_result fpm_trace_ready(pid_t pid) /* {{{ */ { kern_return_t kr; @@ -63,32 +63,32 @@ int fpm_trace_ready(pid_t pid) /* {{{ */ msg = " It seems that master process does not have enough privileges to trace processes."; } zlog(ZLOG_ERROR, "task_for_pid() failed: %s (%d)%s", mach_error_string(kr), kr, msg); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_close(pid_t pid) /* {{{ */ +zend_result fpm_trace_close(pid_t pid) /* {{{ */ { fpm_mach_vm_deallocate(); target = 0; - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_get_long(long addr, long *data) /* {{{ */ +zend_result fpm_trace_get_long(long addr, long *data) /* {{{ */ { size_t offset = ((uintptr_t) (addr) % fpm_pagesize); vm_offset_t base = (uintptr_t) (addr) - offset; if (base != target_page_base) { fpm_mach_vm_deallocate(); - if (0 > fpm_mach_vm_read_page(base)) { - return -1; + if (fpm_mach_vm_read_page(base) != SUCCESS) { + return FAILURE; } } *data = * (long *) (local_page + offset); - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_trace_pread.c b/sapi/fpm/fpm/fpm_trace_pread.c index 8bf4223410993..6d14e98399b7c 100644 --- a/sapi/fpm/fpm/fpm_trace_pread.c +++ b/sapi/fpm/fpm/fpm_trace_pread.c @@ -19,17 +19,17 @@ static int mem_file = -1; -int fpm_trace_signal(pid_t pid) /* {{{ */ +zend_result fpm_trace_signal(pid_t pid) /* {{{ */ { - if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) { + if (fpm_pctl_kill(pid, FPM_PCTL_STOP) != SUCCESS) { zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_ready(pid_t pid) /* {{{ */ +zend_result fpm_trace_ready(pid_t pid) /* {{{ */ { char buf[128]; @@ -37,26 +37,26 @@ int fpm_trace_ready(pid_t pid) /* {{{ */ mem_file = open(buf, O_RDONLY); if (0 > mem_file) { zlog(ZLOG_SYSERROR, "failed to open %s", buf); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_close(pid_t pid) /* {{{ */ +zend_result fpm_trace_close(pid_t pid) /* {{{ */ { close(mem_file); mem_file = -1; - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_get_long(long addr, long *data) /* {{{ */ +zend_result fpm_trace_get_long(long addr, long *data) /* {{{ */ { if (sizeof(*data) != pread(mem_file, (void *) data, sizeof(*data), (uintptr_t) addr)) { zlog(ZLOG_SYSERROR, "pread() failed"); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_trace_ptrace.c b/sapi/fpm/fpm/fpm_trace_ptrace.c index a2a3d25e30ef3..21ea52c4a7e0f 100644 --- a/sapi/fpm/fpm/fpm_trace_ptrace.c +++ b/sapi/fpm/fpm/fpm_trace_ptrace.c @@ -24,35 +24,35 @@ static pid_t traced_pid; -int fpm_trace_signal(pid_t pid) /* {{{ */ +zend_result fpm_trace_signal(pid_t pid) /* {{{ */ { if (0 > ptrace(PTRACE_ATTACH, pid, 0, 0)) { zlog(ZLOG_SYSERROR, "failed to ptrace(ATTACH) child %d", pid); - return -1; + return FAILURE; } - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_ready(pid_t pid) /* {{{ */ +zend_result fpm_trace_ready(pid_t pid) /* {{{ */ { traced_pid = pid; - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_close(pid_t pid) /* {{{ */ +zend_result fpm_trace_close(pid_t pid) /* {{{ */ { if (0 > ptrace(PTRACE_DETACH, pid, (void *) 1, 0)) { zlog(ZLOG_SYSERROR, "failed to ptrace(DETACH) child %d", pid); - return -1; + return FAILURE; } traced_pid = 0; - return 0; + return SUCCESS; } /* }}} */ -int fpm_trace_get_long(long addr, long *data) /* {{{ */ +zend_result fpm_trace_get_long(long addr, long *data) /* {{{ */ { #ifdef PT_IO struct ptrace_io_desc ptio = { @@ -64,16 +64,16 @@ int fpm_trace_get_long(long addr, long *data) /* {{{ */ if (0 > ptrace(PT_IO, traced_pid, (void *) &ptio, 0)) { zlog(ZLOG_SYSERROR, "failed to ptrace(PT_IO) pid %d", traced_pid); - return -1; + return FAILURE; } #else errno = 0; *data = ptrace(PTRACE_PEEKDATA, traced_pid, (void *) addr, 0); if (errno) { zlog(ZLOG_SYSERROR, "failed to ptrace(PEEKDATA) pid %d", traced_pid); - return -1; + return FAILURE; } #endif - return 0; + return SUCCESS; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_unix.c b/sapi/fpm/fpm/fpm_unix.c index d10a6f3254b24..935dab2cf15ba 100644 --- a/sapi/fpm/fpm/fpm_unix.c +++ b/sapi/fpm/fpm/fpm_unix.c @@ -95,7 +95,7 @@ bool fpm_unix_test_config(struct fpm_worker_pool_s *wp) ); } -int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ { struct fpm_worker_pool_config_s *c = wp->config; #ifdef HAVE_FPM_ACL @@ -109,7 +109,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ wp->socket_mode = 0660; if (!c) { - return 0; + return SUCCESS; } if (c->listen_mode && *c->listen_mode) { @@ -143,7 +143,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ acl = acl_init(n); if (!acl) { zlog(ZLOG_SYSERROR, "[pool %s] cannot allocate ACL", wp->config->name); - return -1; + return FAILURE; } /* Create USER ACL */ if (c->listen_acl_users && *c->listen_acl_users) { @@ -160,7 +160,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ } else { acl_free(acl); efree(tmp); - return -1; + return FAILURE; } if (0 > acl_create_entry(&acl, &entry) || 0 > acl_set_tag_type(entry, ACL_USER) || @@ -172,7 +172,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ zlog(ZLOG_SYSERROR, "[pool %s] cannot create ACL for user '%s'", wp->config->name, p); acl_free(acl); efree(tmp); - return -1; + return FAILURE; } } efree(tmp); @@ -192,7 +192,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ } else { acl_free(acl); efree(tmp); - return -1; + return FAILURE; } if (0 > acl_create_entry(&acl, &entry) || 0 > acl_set_tag_type(entry, ACL_GROUP) || @@ -204,7 +204,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ zlog(ZLOG_SYSERROR, "[pool %s] cannot create ACL for group '%s'", wp->config->name, p); acl_free(acl); efree(tmp); - return -1; + return FAILURE; } } efree(tmp); @@ -216,7 +216,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ zlog(ZLOG_WARNING, "[pool %s] ACL set, listen.group = '%s' is ignored", wp->config->name, c->listen_group); } wp->socket_acl = acl; - return 0; + return SUCCESS; } /* When listen.users and listen.groups not configured, continue with standard right */ #endif @@ -229,7 +229,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ pwd = fpm_unix_get_passwd(wp, c->listen_owner, ZLOG_SYSERROR); if (!pwd) { - return -1; + return FAILURE; } wp->socket_uid = pwd->pw_uid; @@ -245,17 +245,17 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ grp = fpm_unix_get_group(wp, c->listen_group, ZLOG_SYSERROR); if (!grp) { - return -1; + return FAILURE; } wp->socket_gid = grp->gr_gid; } } - return 0; + return SUCCESS; } /* }}} */ -int fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *path) /* {{{ */ +zend_result fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *path) /* {{{ */ { #ifdef HAVE_FPM_ACL if (wp->socket_acl) { @@ -268,7 +268,7 @@ int fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *pa aclfile = acl_get_file (path, ACL_TYPE_ACCESS); if (!aclfile) { zlog(ZLOG_SYSERROR, "[pool %s] failed to read the ACL of the socket '%s'", wp->config->name, path); - return -1; + return FAILURE; } /* Copy the new ACL entry from config */ for (i=ACL_FIRST_ENTRY ; acl_get_entry(aclconf, i, &entryconf) ; i=ACL_NEXT_ENTRY) { @@ -276,7 +276,7 @@ int fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *pa 0 > acl_copy_entry(entryfile, entryconf)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to add entry to the ACL of the socket '%s'", wp->config->name, path); acl_free(aclfile); - return -1; + return FAILURE; } } /* Write the socket ACL */ @@ -285,13 +285,13 @@ int fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *pa 0 > acl_set_file (path, ACL_TYPE_ACCESS, aclfile)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to write the ACL of the socket '%s'", wp->config->name, path); acl_free(aclfile); - return -1; + return FAILURE; } else { zlog(ZLOG_DEBUG, "[pool %s] ACL of the socket '%s' is set", wp->config->name, path); } acl_free(aclfile); - return 0; + return SUCCESS; } /* When listen.users and listen.groups not configured, continue with standard right */ #endif @@ -299,25 +299,25 @@ int fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *pa if (wp->socket_uid != -1 || wp->socket_gid != -1) { if (0 > chown(path, wp->socket_uid, wp->socket_gid)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to chown() the socket '%s'", wp->config->name, wp->config->listen_address); - return -1; + return FAILURE; } } - return 0; + return SUCCESS; } /* }}} */ -int fpm_unix_free_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_unix_free_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ { #ifdef HAVE_FPM_ACL if (wp->socket_acl) { - return acl_free(wp->socket_acl); + return acl_free(wp->socket_acl) == 0 ? SUCCESS : FAILURE; } #endif - return 0; + return SUCCESS; } /* }}} */ -static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ +static zend_result fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ { struct passwd *pwd; int is_root = !geteuid(); @@ -336,7 +336,7 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ pwd = fpm_unix_get_passwd(wp, wp->config->user, ZLOG_ERROR); if (!pwd) { - return -1; + return FAILURE; } wp->set_uid = pwd->pw_uid; @@ -355,7 +355,7 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ grp = fpm_unix_get_group(wp, wp->config->group, ZLOG_ERROR); if (!grp) { - return -1; + return FAILURE; } wp->set_gid = grp->gr_gid; } @@ -364,7 +364,7 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ if (!fpm_globals.run_as_root) { if (wp->set_uid == 0 || wp->set_gid == 0) { zlog(ZLOG_ERROR, "[pool %s] please specify user and group other than root", wp->config->name); - return -1; + return FAILURE; } } } else { /* not root */ @@ -388,11 +388,11 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ wp->home = strdup(pwd->pw_dir); } } - return 0; + return SUCCESS; } /* }}} */ -int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +zend_result fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { int is_root = !geteuid(); int made_chroot = 0; @@ -420,7 +420,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ if (is_root && wp->config->chroot && *wp->config->chroot) { if (0 > chroot(wp->config->chroot)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to chroot(%s)", wp->config->name, wp->config->chroot); - return -1; + return FAILURE; } made_chroot = 1; } @@ -428,7 +428,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ if (wp->config->chdir && *wp->config->chdir) { if (0 > chdir(wp->config->chdir)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to chdir(%s)", wp->config->name, wp->config->chdir); - return -1; + return FAILURE; } } else if (made_chroot) { if (0 > chdir("/")) { @@ -441,24 +441,24 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ if (wp->config->process_priority != 64) { if (setpriority(PRIO_PROCESS, 0, wp->config->process_priority) < 0) { zlog(ZLOG_SYSERROR, "[pool %s] Unable to set priority for this new process", wp->config->name); - return -1; + return FAILURE; } } if (wp->set_gid) { if (0 > setgid(wp->set_gid)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to setgid(%d)", wp->config->name, wp->set_gid); - return -1; + return FAILURE; } } if (wp->set_uid) { if (0 > initgroups(wp->set_user ? wp->set_user : wp->config->user, wp->set_gid)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to initgroups(%s, %d)", wp->config->name, wp->config->user, wp->set_gid); - return -1; + return FAILURE; } if (0 > setuid(wp->set_uid)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to setuid(%d)", wp->config->name, wp->set_uid); - return -1; + return FAILURE; } } } @@ -491,8 +491,8 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } #endif - if (0 > fpm_clock_init()) { - return -1; + if (fpm_clock_init() != SUCCESS) { + return FAILURE; } #ifdef HAVE_APPARMOR @@ -501,28 +501,28 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ if (aa_getcon(&con, NULL) == -1) { zlog(ZLOG_SYSERROR, "[pool %s] failed to query apparmor confinement. Please check if \"/proc/*/attr/current\" is read and writeable.", wp->config->name); - return -1; + return FAILURE; } new_con = malloc(strlen(con) + strlen(wp->config->apparmor_hat) + 3); // // + 0 Byte if (!new_con) { zlog(ZLOG_SYSERROR, "[pool %s] failed to allocate memory for apparmor hat change.", wp->config->name); free(con); - return -1; + return FAILURE; } if (0 > sprintf(new_con, "%s//%s", con, wp->config->apparmor_hat)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to construct apparmor confinement.", wp->config->name); free(con); free(new_con); - return -1; + return FAILURE; } if (0 > aa_change_profile(new_con)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to change to new confinement (%s). Please check if \"/proc/*/attr/current\" is read and writeable and \"change_profile -> %s//*\" is allowed.", wp->config->name, new_con, con); free(con); free(new_con); - return -1; + return FAILURE; } free(con); @@ -530,11 +530,11 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } #endif - return 0; + return SUCCESS; } /* }}} */ -int fpm_unix_init_main(void) +zend_result fpm_unix_init_main(void) { struct fpm_worker_pool_s *wp; int is_root = !geteuid(); @@ -546,7 +546,7 @@ int fpm_unix_init_main(void) if (0 > setrlimit(RLIMIT_NOFILE, &r)) { zlog(ZLOG_SYSERROR, "failed to set rlimit_files for this pool. Please check your system limits or decrease rlimit_files. setrlimit(RLIMIT_NOFILE, %d)", fpm_global_config.rlimit_files); - return -1; + return FAILURE; } } @@ -557,7 +557,7 @@ int fpm_unix_init_main(void) if (0 > setrlimit(RLIMIT_CORE, &r)) { zlog(ZLOG_SYSERROR, "failed to set rlimit_core for this pool. Please check your system limits or decrease rlimit_core. setrlimit(RLIMIT_CORE, %d)", fpm_global_config.rlimit_core); - return -1; + return FAILURE; } } @@ -581,7 +581,7 @@ int fpm_unix_init_main(void) if (pipe(fpm_globals.send_config_pipe) == -1) { zlog(ZLOG_SYSERROR, "failed to create pipe"); - return -1; + return FAILURE; } /* then fork */ @@ -590,7 +590,7 @@ int fpm_unix_init_main(void) case -1 : /* error */ zlog(ZLOG_SYSERROR, "failed to daemonize"); - return -1; + return FAILURE; case 0 : /* children */ close(fpm_globals.send_config_pipe[0]); /* close the read side of the pipe */ @@ -647,15 +647,15 @@ int fpm_unix_init_main(void) /* continue as a child */ setsid(); - if (0 > fpm_clock_init()) { - return -1; + if (fpm_clock_init() != SUCCESS) { + return FAILURE; } if (fpm_global_config.process_priority != 64) { if (is_root) { if (setpriority(PRIO_PROCESS, 0, fpm_global_config.process_priority) < 0) { zlog(ZLOG_SYSERROR, "Unable to set priority for the master process"); - return -1; + return FAILURE; } } else { zlog(ZLOG_NOTICE, "'process.priority' directive is ignored when FPM is not running as root"); @@ -664,10 +664,10 @@ int fpm_unix_init_main(void) fpm_globals.parent_pid = getpid(); for (wp = fpm_worker_all_pools; wp; wp = wp->next) { - if (0 > fpm_unix_conf_wp(wp)) { - return -1; + if (fpm_unix_conf_wp(wp) != SUCCESS) { + return FAILURE; } } - return 0; + return SUCCESS; } diff --git a/sapi/fpm/fpm/fpm_unix.h b/sapi/fpm/fpm/fpm_unix.h index 6fc9e5e8450dc..d154fb830fa88 100644 --- a/sapi/fpm/fpm/fpm_unix.h +++ b/sapi/fpm/fpm/fpm_unix.h @@ -7,12 +7,12 @@ bool fpm_unix_test_config(struct fpm_worker_pool_s *wp); -int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp); -int fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *path); -int fpm_unix_free_socket_permissions(struct fpm_worker_pool_s *wp); +zend_result fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp); +zend_result fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *path); +zend_result fpm_unix_free_socket_permissions(struct fpm_worker_pool_s *wp); -int fpm_unix_init_child(struct fpm_worker_pool_s *wp); -int fpm_unix_init_main(void); +zend_result fpm_unix_init_child(struct fpm_worker_pool_s *wp); +zend_result fpm_unix_init_main(void); extern size_t fpm_pagesize; diff --git a/sapi/fpm/fpm/fpm_worker_pool.c b/sapi/fpm/fpm/fpm_worker_pool.c index 6016b5867f5c6..cf12dd1a63474 100644 --- a/sapi/fpm/fpm/fpm_worker_pool.c +++ b/sapi/fpm/fpm/fpm_worker_pool.c @@ -81,10 +81,7 @@ struct fpm_worker_pool_s *fpm_worker_pool_alloc(void) return ret; } -int fpm_worker_pool_init_main(void) +zend_result fpm_worker_pool_init_main(void) { - if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_worker_pool_cleanup, 0)) { - return -1; - } - return 0; + return fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_worker_pool_cleanup, 0); } diff --git a/sapi/fpm/fpm/fpm_worker_pool.h b/sapi/fpm/fpm/fpm_worker_pool.h index efb8640cd32f0..0ff27270ef92e 100644 --- a/sapi/fpm/fpm/fpm_worker_pool.h +++ b/sapi/fpm/fpm/fpm_worker_pool.h @@ -50,7 +50,7 @@ struct fpm_worker_pool_s { struct fpm_worker_pool_s *fpm_worker_pool_alloc(void); void fpm_worker_pool_free(struct fpm_worker_pool_s *wp); -int fpm_worker_pool_init_main(void); +zend_result fpm_worker_pool_init_main(void); void fpm_worker_pool_free_limit_extensions(char **limit_extensions);