diff --git a/sapi/fpm/fpm/fpm.c b/sapi/fpm/fpm/fpm.c index 30cb9da010bf1..4a6cec95b15c8 100644 --- a/sapi/fpm/fpm/fpm.c +++ b/sapi/fpm/fpm/fpm.c @@ -41,7 +41,7 @@ struct fpm_globals_s fpm_globals = { .send_config_pipe = {0, 0}, }; -int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr) /* {{{ */ +bool fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr) /* {{{ */ { fpm_globals.argc = argc; fpm_globals.argv = argv; @@ -53,36 +53,36 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t 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() || + !fpm_stdio_init_main() || + !fpm_conf_init_main(test_conf, force_daemon) || + !fpm_unix_init_main() || + !fpm_scoreboard_init_main() || + !fpm_pctl_init_main() || + !fpm_env_init_main() || + !fpm_signals_init_main() || + !fpm_children_init_main() || + !fpm_sockets_init_main() || + !fpm_worker_pool_init_main() || + !fpm_event_init_main()) { if (fpm_globals.test_successful) { exit(FPM_EXIT_OK); } else { zlog(ZLOG_ERROR, "FPM initialization failed"); - return -1; + return false; } } - if (0 > fpm_conf_write_pid()) { + if (!fpm_conf_write_pid()) { zlog(ZLOG_ERROR, "FPM initialization failed"); - return -1; + return false; } fpm_stdio_init_final(); zlog(ZLOG_NOTICE, "fpm is running, pid %d", (int) fpm_globals.parent_pid); - return 0; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm.h b/sapi/fpm/fpm/fpm.h index f0610ca46dc62..3d84a067aab33 100644 --- a/sapi/fpm/fpm/fpm.h +++ b/sapi/fpm/fpm/fpm.h @@ -4,6 +4,7 @@ #define FPM_H 1 #include +#include #ifdef HAVE_SYSEXITS_H #include @@ -35,7 +36,7 @@ int fpm_run(int *max_requests); -int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr); +bool fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr); struct fpm_globals_s { pid_t parent_pid; diff --git a/sapi/fpm/fpm/fpm_children.c b/sapi/fpm/fpm/fpm_children.c index 741fc27631516..c558af20fe18d 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) /* Note: this never fails */ || + !fpm_log_init_child(wp) || + !fpm_status_init_child(wp) || + !fpm_unix_init_child(wp) || + !fpm_signals_init_child() || + !fpm_env_init_child(wp) /* Note: this never fails */ || + !fpm_php_init_child(wp) /* Note: this never fails */) { zlog(ZLOG_ERROR, "[pool %s] child failed to initialize", wp->config->name); exit(FPM_EXIT_SOFTWARE); @@ -163,7 +163,7 @@ static void fpm_child_init(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ -int fpm_children_free(struct fpm_child_s *child) /* {{{ */ +void fpm_children_free(struct fpm_child_s *child) /* {{{ */ { struct fpm_child_s *next; @@ -171,8 +171,6 @@ int fpm_children_free(struct fpm_child_s *child) /* {{{ */ next = child->next; fpm_child_close(child, 0 /* in_event_loop */); } - - return 0; } /* }}} */ @@ -317,12 +315,12 @@ static struct fpm_child_s *fpm_resources_prepare(struct fpm_worker_pool_s *wp) / c->wp = wp; c->fd_stdout = -1; c->fd_stderr = -1; - if (0 > fpm_stdio_prepare_pipes(c)) { + if (!fpm_stdio_prepare_pipes(c)) { fpm_child_free(c); return 0; } - if (0 > fpm_scoreboard_proc_alloc(c)) { + if (!fpm_scoreboard_proc_alloc(c)) { fpm_stdio_discard_pipes(c); fpm_child_free(c); return 0; @@ -403,7 +401,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()) { zlog(ZLOG_WARNING, "child may miss signals"); } @@ -470,7 +468,7 @@ int fpm_children_create_initial(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ -int fpm_children_init_main(void) +bool fpm_children_init_main(void) { if (fpm_global_config.emergency_restart_threshold && fpm_global_config.emergency_restart_interval) { @@ -478,15 +476,15 @@ int fpm_children_init_main(void) last_faults = malloc(sizeof(time_t) * fpm_global_config.emergency_restart_threshold); if (!last_faults) { - return -1; + return false; } 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; + if (!fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_children_cleanup, 0)) { + return false; } - return 0; + return true; } diff --git a/sapi/fpm/fpm/fpm_children.h b/sapi/fpm/fpm/fpm_children.h index 5ae4e2062e468..bfe03ce661ca9 100644 --- a/sapi/fpm/fpm/fpm_children.h +++ b/sapi/fpm/fpm/fpm_children.h @@ -5,15 +5,16 @@ #include #include +#include #include "fpm_worker_pool.h" #include "fpm_events.h" #include "zlog.h" int fpm_children_create_initial(struct fpm_worker_pool_s *wp); -int fpm_children_free(struct fpm_child_s *child); +void fpm_children_free(struct fpm_child_s *child); void fpm_children_bury(void); -int fpm_children_init_main(void); +bool 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; diff --git a/sapi/fpm/fpm/fpm_cleanup.c b/sapi/fpm/fpm/fpm_cleanup.c index 7c900974a9cfd..d9de003ffcfbb 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) /* {{{ */ +bool 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 false; } c->type = type; c->cleanup = cleanup; c->arg = arg; - return 0; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_cleanup.h b/sapi/fpm/fpm/fpm_cleanup.h index 8583143fa20fc..c487c596275ea 100644 --- a/sapi/fpm/fpm/fpm_cleanup.h +++ b/sapi/fpm/fpm/fpm_cleanup.h @@ -3,7 +3,9 @@ #ifndef FPM_CLEANUP_H #define FPM_CLEANUP_H 1 -int fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *); +#include + +bool 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..9233323ed15b1 100644 --- a/sapi/fpm/fpm/fpm_clock.c +++ b/sapi/fpm/fpm/fpm_clock.c @@ -13,9 +13,9 @@ /* posix monotonic clock - preferred source of time */ #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) -static int monotonic_works; +static bool monotonic_works; -int fpm_clock_init(void) +bool fpm_clock_init(void) { struct timespec ts; @@ -25,7 +25,7 @@ int fpm_clock_init(void) monotonic_works = 1; } - return 0; + return true; } int fpm_clock_get(struct timeval *tv) /* {{{ */ @@ -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) +bool 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 false; } /* test if it works */ @@ -75,10 +75,10 @@ int fpm_clock_init(void) if (ret != KERN_SUCCESS) { zlog(ZLOG_ERROR, "clock_get_time() failed: %s", mach_error_string(ret)); - return -1; + return false; } - return 0; + return true; } int fpm_clock_get(struct timeval *tv) /* {{{ */ @@ -102,9 +102,9 @@ int fpm_clock_get(struct timeval *tv) /* {{{ */ #else /* no clock */ -int fpm_clock_init(void) +bool fpm_clock_init(void) { - return 0; + return true; } int fpm_clock_get(struct timeval *tv) /* {{{ */ diff --git a/sapi/fpm/fpm/fpm_clock.h b/sapi/fpm/fpm/fpm_clock.h index 1bf38ff63ef80..daf6def70e762 100644 --- a/sapi/fpm/fpm/fpm_clock.h +++ b/sapi/fpm/fpm/fpm_clock.h @@ -4,8 +4,9 @@ #define FPM_CLOCK_H 1 #include +#include -int fpm_clock_init(void); +bool fpm_clock_init(void); int fpm_clock_get(struct timeval *tv); #endif diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index a4be6b22161e0..8c1b3100e6219 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -45,7 +45,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 bool 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); @@ -163,12 +163,12 @@ static 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; @@ -178,11 +178,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 bool fpm_conf_expand_pool_name(char **value) { char *token; if (!value || !*value) { - return 0; + return true; } while (*value && (token = strstr(*value, "$pool"))) { @@ -191,7 +191,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 false; } /* "aaa$poolbbb" becomes "aaa\0oolbbb" */ @@ -206,7 +206,7 @@ static int fpm_conf_expand_pool_name(char **value) { efree(buf); } - return 0; + return true; } static char *fpm_conf_set_boolean(zval *value, void **config, intptr_t offset) /* {{{ */ @@ -241,7 +241,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)) { return "Can't use '$pool' when the pool is not defined"; } @@ -579,7 +579,7 @@ static char *fpm_conf_set_array(zval *key, zval *value, void **config, int conve kv->value = strdup(b ? "1" : "0"); } else { kv->value = strdup(Z_STRVAL_P(value)); - if (fpm_conf_expand_pool_name(&kv->value) == -1) { + if (!fpm_conf_expand_pool_name(&kv->value)) { free(kv->key); free(kv); return "Can't use '$pool' when the pool is not defined"; @@ -644,7 +644,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; @@ -693,8 +693,6 @@ int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */ free(kv->value); free(kv); } - - return 0; } /* }}} */ @@ -717,17 +715,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 bool 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 false; } shared_config = shared_wp->config; config->name = malloc(strlen(shared_config->name) + sizeof("_status")); if (!config->name) { - return -1; + return false; } strcpy(config->name, shared_config->name); strcpy(config->name + strlen(shared_config->name), "_status"); @@ -757,17 +755,17 @@ static int fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_ current_wp->shared = shared_wp; - return 0; + return true; } /* }}} */ -static int fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, char *default_prefix, int expand) /* {{{ */ +static bool fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, char *default_prefix, bool expand) /* {{{ */ { char *prefix = NULL; char *full_path; if (!path || !*path || **path == '/') { - return 0; + return true; } if (wp && wp->config) { @@ -791,7 +789,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 false; } if (strlen(*path) > strlen("$prefix")) { @@ -817,17 +815,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 true; } /* }}} */ -static int fpm_conf_process_all_pools(void) +static bool 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 false; } for (wp = fpm_worker_all_pools; wp; wp = wp->next) { @@ -838,14 +836,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 false; } } /* 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 false; } /* listen */ @@ -857,24 +855,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 false; } 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 false; } /* 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 false; } /* 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 false; } /* pm.start_servers, pm.min_spare_servers, pm.max_spare_servers, pm.max_spawn_rate */ @@ -883,23 +881,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 false; } 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 false; } 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 false; } 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 false; } if (config->pm_start_servers <= 0) { @@ -908,24 +906,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 false; } 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 false; } } 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 false; } 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 false; } if (config->listen_backlog < FPM_BACKLOG_DEFAULT) { @@ -940,7 +938,7 @@ static int fpm_conf_process_all_pools(void) } /* status */ - if (wp->config->pm_status_listen && fpm_worker_pool_shared_status_alloc(wp)) { + if (wp->config->pm_status_listen && !fpm_worker_pool_shared_status_alloc(wp)) { zlog(ZLOG_ERROR, "[pool %s] failed to initialize a status listener pool", wp->config->name); } @@ -950,18 +948,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 false; } 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 false; } 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 false; } } } @@ -973,18 +971,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 false; } if (strlen(ping) < 2) { zlog(ZLOG_ERROR, "[pool %s] the ping path '%s' is not long enough", wp->config->name, ping); - return -1; + return false; } 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 false; } } @@ -993,7 +991,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 false; } } } else { @@ -1025,7 +1023,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 false; } #else static int warned = 0; @@ -1045,7 +1043,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 false; } close(fd); } @@ -1054,7 +1052,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 false; } } @@ -1063,7 +1061,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 false; } #else static int warned = 0; @@ -1076,7 +1074,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 false; } } else { wp->config->request_slowlog_trace_depth = 20; @@ -1089,12 +1087,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 false; } 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 false; } } @@ -1105,7 +1103,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 false; } if (wp->config->chroot) { @@ -1116,14 +1114,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 false; } 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 false; } } } @@ -1159,7 +1157,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 false; } /* 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 false; } } } - return 0; + return true; } -int fpm_conf_unlink_pid(void) +bool 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 false; } } - return 0; + return true; } -int fpm_conf_write_pid(void) +bool 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 false; } 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 false; } close(fd); } - return 0; + return true; } -static int fpm_conf_post_process(int force_daemon) /* {{{ */ +static bool 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 false; } 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 false; } 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 false; } if (!fpm_global_config.error_log) { @@ -1297,9 +1295,7 @@ static int fpm_conf_post_process(int force_daemon) /* {{{ */ } #ifdef HAVE_SYSTEMD - if (0 > fpm_systemd_conf()) { - return -1; - } + fpm_systemd_conf(); #endif #ifdef HAVE_SYSLOG_H @@ -1317,37 +1313,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()) { + return false; } - if (0 > fpm_stdio_open_error_log(0)) { - return -1; + if (!fpm_stdio_open_error_log(/* reopen */ false)) { + return false; } - if (0 > fpm_event_pre_init(fpm_global_config.events_mechanism)) { - return -1; + if (!fpm_event_pre_init(fpm_global_config.events_mechanism)) { + return false; } - if (0 > fpm_conf_process_all_pools()) { - return -1; + if (!fpm_conf_process_all_pools()) { + return false; } if (0 > fpm_log_open(0)) { - return -1; + return false; } 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)) { zlog(ZLOG_ERROR, "[pool %s] wrong format for access.format '%s'", wp->config->name, wp->config->access_format); - return -1; + return false; } } - return 0; + return true; } /* }}} */ @@ -1398,10 +1394,10 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */ } for (i = 0; i < g.gl_pathc; i++) { - int len = strlen(g.gl_pathv[i]); - if (len < 1) continue; + size_t len = strlen(g.gl_pathv[i]); + if (len == 0) 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])) { 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 +1407,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)) { zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", inc, filename, ini_lineno); *error = 1; efree(filename); @@ -1617,7 +1613,7 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback } /* }}} */ -int fpm_conf_load_ini_file(char *filename) /* {{{ */ +static bool fpm_conf_load_ini_file(char *filename) /* {{{ */ { int error = 0; char *buf = NULL, *newbuf = NULL; @@ -1626,23 +1622,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 false; } fd = open(filename, O_RDONLY, 0); if (fd < 0) { zlog(ZLOG_SYSERROR, "failed to open configuration file '%s'", filename); - return -1; + return false; } if (ini_recursion++ > 4) { zlog(ZLOG_ERROR, "failed to include more than 5 files recursively"); close(fd); - return -1; + return false; } ini_lineno = 0; @@ -1658,7 +1652,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); free(buf); - return -1; + return false; } buf = newbuf; } @@ -1681,7 +1675,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); free(buf); - return -1; + return false; } if (ini_include) { char *tmp = ini_include; @@ -1693,7 +1687,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); free(buf); - return -1; + return false; } free(tmp); } @@ -1702,7 +1696,7 @@ int fpm_conf_load_ini_file(char *filename) /* {{{ */ ini_recursion--; close(fd); - return ret; + return true; } /* }}} */ @@ -1817,14 +1811,12 @@ static void fpm_conf_dump(void) } } -int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */ +bool 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 false; } } @@ -1843,7 +1835,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 false; } fpm_globals.config = strdup(tmp); @@ -1851,20 +1843,18 @@ 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 false; } } - ret = fpm_conf_load_ini_file(fpm_globals.config); - - if (0 > ret) { + if (!fpm_conf_load_ini_file(fpm_globals.config)) { zlog(ZLOG_ERROR, "failed to load configuration file '%s'", fpm_globals.config); - return -1; + return false; } - if (0 > fpm_conf_post_process(force_daemon)) { + if (!fpm_conf_post_process(force_daemon)) { zlog(ZLOG_ERROR, "failed to post process the configuration"); - return -1; + return false; } if (test_conf) { @@ -1873,13 +1863,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 false; } - 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)) { + return false; } - return 0; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h index 5b354a9bdecef..d30199cd2407b 100644 --- a/sapi/fpm/fpm/fpm_conf.h +++ b/sapi/fpm/fpm/fpm_conf.h @@ -4,6 +4,7 @@ #define FPM_CONF_H 1 #include +#include #include "php.h" #define PM2STR(a) (a == PM_STYLE_STATIC ? "static" : (a == PM_STYLE_DYNAMIC ? "dynamic" : "ondemand")) @@ -121,9 +122,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); +bool fpm_conf_init_main(int test_conf, int force_daemon); +void fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc); +bool fpm_conf_write_pid(void); +bool fpm_conf_unlink_pid(void); #endif diff --git a/sapi/fpm/fpm/fpm_env.c b/sapi/fpm/fpm/fpm_env.c index 72ed1aa94d383..579c51c33c3a8 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) /* {{{ */ +bool 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 true; } /* }}} */ -static int fpm_env_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ +static void fpm_env_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ { struct key_value_s *kv; @@ -189,20 +189,16 @@ static int fpm_env_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ wp->home = 0; } } - - return 0; } /* }}} */ -int fpm_env_init_main(void) +bool 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; - } + fpm_env_conf_wp(wp); } #ifndef HAVE_SETPROCTITLE #if defined(__linux__) || defined(__APPLE__) @@ -241,7 +237,7 @@ int fpm_env_init_main(void) } } if (first == NULL || last == NULL) { - return 0; + return true; } fpm_env_argv_len = last - first; @@ -255,7 +251,7 @@ int fpm_env_init_main(void) } if ((new_environ = malloc((1U + env_nb) * sizeof (char *))) == NULL) { - return -1; + return false; } new_environ[env_nb] = NULL; while (env_nb > 0U) { @@ -270,5 +266,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 true; } diff --git a/sapi/fpm/fpm/fpm_env.h b/sapi/fpm/fpm/fpm_env.h index dacf6f8701544..fbdf6fc7741ec 100644 --- a/sapi/fpm/fpm/fpm_env.h +++ b/sapi/fpm/fpm/fpm_env.h @@ -3,12 +3,13 @@ #ifndef FPM_ENV_H #define FPM_ENV_H 1 +#include #include "fpm_worker_pool.h" #define SETPROCTITLE_PREFIX "php-fpm: " -int fpm_env_init_child(struct fpm_worker_pool_s *wp); -int fpm_env_init_main(void); +bool fpm_env_init_child(struct fpm_worker_pool_s *wp); +bool 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..12c37c8b2367a 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 bool fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_event_s *ev); +static bool 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(/* reopen */ true)) { 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 bool 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 false; } if (fpm_event_queue_isset(*queue, ev)) { - return 0; + return true; } if (!(elt = malloc(sizeof(struct fpm_event_queue_s)))) { zlog(ZLOG_SYSERROR, "Unable to add the event to queue: malloc() failed"); - return -1; + return false; } 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 true; } /* }}} */ -static int fpm_event_queue_del(struct fpm_event_queue_s **queue, struct fpm_event_s *ev) /* {{{ */ +static bool 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 false; } 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 true; } q = q->next; } - return -1; + return false; } /* }}} */ @@ -253,13 +253,13 @@ static void fpm_event_queue_destroy(struct fpm_event_queue_s **queue) /* {{{ */ } /* }}} */ -int fpm_event_pre_init(char *mechanism) /* {{{ */ +bool fpm_event_pre_init(char *mechanism) /* {{{ */ { /* kqueue */ module = fpm_event_kqueue_module(); if (module) { if (!mechanism || strcasecmp(module->name, mechanism) == 0) { - return 0; + return true; } } @@ -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 true; } } @@ -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 true; } } @@ -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 true; } } @@ -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 true; } } @@ -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 true; } } @@ -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 false; } /* }}} */ @@ -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; } -int fpm_event_init_main(void) +bool 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 false; } if (!module->wait) { zlog(ZLOG_ERROR, "Incomplete event implementation. Please open a bug report on https://bugs.php.net."); - return -1; + return false; } /* 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 false; } 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)) { + return false; } - return 0; + return true; } 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) /* {{{ */ +bool 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 false; } memset(ev, 0, sizeof(struct fpm_event_s)); ev->fd = fd; ev->callback = callback; ev->arg = arg; ev->flags = flags; - return 0; + return true; } /* }}} */ -int fpm_event_add(struct fpm_event_s *ev, unsigned long int frequency) /* {{{ */ +bool fpm_event_add(struct fpm_event_s *ev, unsigned long int frequency) /* {{{ */ { struct timeval now; struct timeval tmp; if (!ev) { - return -1; + return false; } ev->index = -1; @@ -516,10 +516,7 @@ 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; - } - return 0; + return fpm_event_queue_add(&fpm_event_queue_fd, ev); } /* it's a timer event */ @@ -536,24 +533,17 @@ 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; - } - - return 0; + return fpm_event_queue_add(&fpm_event_queue_timer, ev); } /* }}} */ -int fpm_event_del(struct fpm_event_s *ev) /* {{{ */ +bool 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_timer, ev) != 0) { - return -1; + if (ev->index >= 0) { + return fpm_event_queue_del(&fpm_event_queue_fd, ev); } - return 0; + /* else ev->index < 0 */ + return fpm_event_queue_del(&fpm_event_queue_timer, ev); } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_events.h b/sapi/fpm/fpm/fpm_events.h index 5cc2b942ed25b..546f9bc4625af 100644 --- a/sapi/fpm/fpm/fpm_events.h +++ b/sapi/fpm/fpm/fpm_events.h @@ -3,6 +3,8 @@ #ifndef FPM_EVENTS_H #define FPM_EVENTS_H 1 +#include + #define FPM_EV_TIMEOUT (1 << 0) #define FPM_EV_READ (1 << 1) #define FPM_EV_PERSIST (1 << 2) @@ -39,12 +41,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); +bool fpm_event_init_main(void); +bool fpm_event_set(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, void *), void *arg); +bool fpm_event_add(struct fpm_event_s *ev, unsigned long int timeout); +bool fpm_event_del(struct fpm_event_s *ev); +bool 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..5b57d5677e7d3 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) /* {{{ */ +bool fpm_log_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { if (!wp || !wp->config) { - return -1; + return false; } 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 false; } 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 true; } /* }}} */ -int fpm_log_write(char *log_format) /* {{{ */ +bool 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 false; } 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 false; } 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 false; } proc = *proc_p; fpm_scoreboard_proc_release(proc_p); if (UNEXPECTED(fpm_access_log_suppress(&proc))) { - return -1; + return false; } } @@ -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 false; } format[0] = '\0'; @@ -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 false; } 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 false; } 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 false; } 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 false; } } break; default: zlog(ZLOG_WARNING, "Invalid token in the access.format (%%%c)", *s); - return -1; + return false; } if (*s != '}' && format[0] != '\0') { zlog(ZLOG_WARNING, "embrace is not allowed for modifier %%%c", *s); - return -1; + return false; } s++; if (!test) { @@ -489,11 +489,11 @@ int fpm_log_write(char *log_format) /* {{{ */ zend_quiet_write(fpm_log_fd, buffer, len + 1); } - return 0; + return true; } /* }}} */ -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') { @@ -526,4 +526,4 @@ static int fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc) } return 0; -} \ No newline at end of file +} diff --git a/sapi/fpm/fpm/fpm_log.h b/sapi/fpm/fpm/fpm_log.h index edad81de2162d..9b5e4ad9ca519 100644 --- a/sapi/fpm/fpm/fpm_log.h +++ b/sapi/fpm/fpm/fpm_log.h @@ -2,10 +2,12 @@ #ifndef FPM_LOG_H #define FPM_LOG_H 1 + +#include #include "fpm_worker_pool.h" -int fpm_log_init_child(struct fpm_worker_pool_s *wp); -int fpm_log_write(char *log_format); +bool fpm_log_init_child(struct fpm_worker_pool_s *wp); +bool 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 8ce59a43b4145..72bc699d679a9 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1358,7 +1358,7 @@ static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_ key = Z_STRVAL_P(arg1); - if (!key || strlen(key) < 1) { + if (Z_STRLEN_P(arg1) == 0) { zlog(ZLOG_ERROR, "Passing INI directive through FastCGI: empty key"); return; } @@ -1375,7 +1375,7 @@ static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_ kv.key = key; kv.value = value; kv.next = NULL; - if (fpm_php_apply_defines_ex(&kv, *mode) == -1) { + if (!fpm_php_apply_defines_ex(&kv, *mode)) { zlog(ZLOG_ERROR, "Passing INI directive through FastCGI: unable to set '%s'", key); } } @@ -1486,7 +1486,7 @@ PHP_FUNCTION(fpm_get_status) /* {{{ */ RETURN_THROWS(); } - if (fpm_status_export_to_zval(return_value)) { + if (!fpm_status_export_to_zval(return_value)) { RETURN_FALSE; } } @@ -1530,7 +1530,6 @@ int main(int argc, char *argv[]) int force_stderr = 0; int php_information = 0; int php_allow_to_run_as_root = 0; - int ret; #if ZEND_RC_DEBUG bool old_rc_debug; #endif @@ -1543,7 +1542,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() || !fpm_signals_block()) { zlog(ZLOG_WARNING, "Could die in the case of too early reload signal"); } zlog(ZLOG_DEBUG, "Blocked some signals"); @@ -1777,13 +1776,13 @@ consult the installation file that came with this distribution, or visit \n\ zend_rc_debug = 0; #endif - ret = fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root, force_daemon, force_stderr); + bool fpm_status = fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root, force_daemon, force_stderr); #if ZEND_RC_DEBUG zend_rc_debug = old_rc_debug; #endif - if (ret < 0) { + if (!fpm_status) { if (fpm_globals.send_config_pipe[1]) { int writeval = 0; diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index 92b189668206e..155af5027a7ec 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; @@ -77,13 +77,13 @@ static void fpm_php_disable(char *value, int (*zend_disable)(const char *, size_ } /* }}} */ -int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ +bool fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ { char *name = kv->key; char *value = kv->value; - int name_len = strlen(name); - int value_len = strlen(value); + size_t name_len = strlen(name); + size_t value_len = strlen(value); if (!strcmp(name, "extension") && *value) { zval zv; @@ -92,51 +92,48 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ } if (fpm_php_zend_ini_alter_master(name, name_len, value, value_len, mode, PHP_INI_STAGE_ACTIVATE) == FAILURE) { - return -1; + return false; } if (!strcmp(name, "disable_functions") && *value) { zend_disable_functions(value); - return 1; + return true; } if (!strcmp(name, "disable_classes") && *value) { char *v = strdup(value); PG(disable_classes) = v; fpm_php_disable(v, zend_disable_class); - return 1; + return true; } - return 1; + return true; } /* }}} */ -static int fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */ +static void fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */ { struct key_value_s *kv; for (kv = wp->config->php_values; kv; kv = kv->next) { - if (fpm_php_apply_defines_ex(kv, ZEND_INI_USER) == -1) { + if (!fpm_php_apply_defines_ex(kv, ZEND_INI_USER)) { zlog(ZLOG_ERROR, "Unable to set php_value '%s'", kv->key); } } for (kv = wp->config->php_admin_values; kv; kv = kv->next) { - if (fpm_php_apply_defines_ex(kv, ZEND_INI_SYSTEM) == -1) { + if (!fpm_php_apply_defines_ex(kv, ZEND_INI_SYSTEM)) { zlog(ZLOG_ERROR, "Unable to set php_admin_value '%s'", kv->key); } } - - return 0; } /* }}} */ -static int fpm_php_set_allowed_clients(struct fpm_worker_pool_s *wp) /* {{{ */ +static void 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; } /* }}} */ @@ -200,31 +197,26 @@ void fpm_php_soft_quit(void) fcgi_terminate(); } -int fpm_php_init_main(void) +bool fpm_php_init_main(void) { - if (0 > fpm_cleanup_add(FPM_CLEANUP_PARENT, fpm_php_cleanup, 0)) { - return -1; - } - return 0; + return fpm_cleanup_add(FPM_CLEANUP_PARENT, fpm_php_cleanup, 0); } -int fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +bool fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { - if (0 > fpm_php_apply_defines(wp) || - 0 > fpm_php_set_allowed_clients(wp)) { - return -1; - } + fpm_php_apply_defines(wp); + fpm_php_set_allowed_clients(wp); if (wp->limit_extensions) { /* Take ownership of limit_extensions. */ limit_extensions = wp->limit_extensions; wp->limit_extensions = NULL; } - return 0; + return true; } /* }}} */ -int fpm_php_limit_extensions(char *path) /* {{{ */ +bool fpm_php_limit_extensions(char *path) /* {{{ */ { char **p; size_t path_len; diff --git a/sapi/fpm/fpm/fpm_php.h b/sapi/fpm/fpm/fpm_php.h index c494bc89fd063..583108f29efe2 100644 --- a/sapi/fpm/fpm/fpm_php.h +++ b/sapi/fpm/fpm/fpm_php.h @@ -3,6 +3,7 @@ #ifndef FPM_PHP_H #define FPM_PHP_H 1 +#include #include #include "php.h" @@ -31,7 +32,7 @@ struct fpm_worker_pool_s; -int fpm_php_init_child(struct fpm_worker_pool_s *wp); +bool 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); @@ -39,9 +40,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); -int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode); -int fpm_php_limit_extensions(char *path); +bool fpm_php_init_main(void); +bool fpm_php_apply_defines_ex(struct key_value_s *kv, int mode); +bool fpm_php_limit_extensions(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 0e1d8e3f6cee0..e5b9438d831a6 100644 --- a/sapi/fpm/fpm/fpm_php_trace.c +++ b/sapi/fpm/fpm/fpm_php_trace.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -34,7 +35,7 @@ #endif -static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ */ +static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ */ { int callers_limit = child->wp->config->request_slowlog_trace_depth; pid_t pid = child->pid; @@ -51,20 +52,20 @@ 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)) { - return -1; + if (!fpm_trace_get_long((long) &SG(request_info).path_translated, &l)) { + return false; } path_translated = l; - if (0 > fpm_trace_get_strz(buf, buf_size, path_translated)) { - return -1; + if (!fpm_trace_get_strz(buf, buf_size, path_translated)) { + return false; } fprintf(slowlog, "script_filename = %s\n", buf); - if (0 > fpm_trace_get_long((long) &EG(current_execute_data), &l)) { - return -1; + if (!fpm_trace_get_long((long) &EG(current_execute_data), &l)) { + return false; } execute_data = l; @@ -76,35 +77,35 @@ 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)) { - return -1; + if (!fpm_trace_get_long(execute_data + offsetof(zend_execute_data, func), &l)) { + return false; } function = l; if (valid_ptr(function)) { - if (0 > fpm_trace_get_long(function + offsetof(zend_function, common.function_name), &l)) { - return -1; + if (!fpm_trace_get_long(function + offsetof(zend_function, common.function_name), &l)) { + return false; } function_name = l; 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)) { - return -1; + if (!fpm_trace_get_long(execute_data + offsetof(zend_execute_data, This.u1.type_info), &l)) { + return false; } if (ZEND_CALL_KIND_EX(*call_info) == ZEND_CALL_TOP_CODE) { - return 0; + return true; } else if (ZEND_CALL_KIND_EX(*call_info) == ZEND_CALL_NESTED_CODE) { memcpy(buf, "[INCLUDE_OR_EVAL]", sizeof("[INCLUDE_OR_EVAL]")); } else { ZEND_UNREACHABLE(); } } else { - if (0 > fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) { - return -1; + if (!fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) { + return false; } } @@ -118,8 +119,8 @@ 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)) { - return -1; + if (!fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l)) { + return false; } execute_data = prev = l; @@ -127,8 +128,8 @@ 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)) { - return -1; + if (!fpm_trace_get_long(prev + offsetof(zend_execute_data, func), &l)) { + return false; } function = l; @@ -138,31 +139,31 @@ 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)) { - return -1; + if (!fpm_trace_get_long(function + offsetof(zend_function, type), &l)) { + return false; } if (ZEND_USER_CODE(*type)) { - if (0 > fpm_trace_get_long(function + offsetof(zend_op_array, filename), &l)) { - return -1; + if (!fpm_trace_get_long(function + offsetof(zend_op_array, filename), &l)) { + return false; } file_name = l; - if (0 > fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) { - return -1; + if (!fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) { + return false; } - if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, opline), &l)) { - return -1; + if (!fpm_trace_get_long(prev + offsetof(zend_execute_data, opline), &l)) { + return false; } if (valid_ptr(l)) { long opline = l; uint32_t *lu = (uint32_t *) &l; - if (0 > fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l)) { - return -1; + if (!fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l)) { + return false; } lineno = *lu; @@ -170,8 +171,8 @@ 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)) { - return -1; + if (!fpm_trace_get_long(prev + offsetof(zend_execute_data, prev_execute_data), &l)) { + return false; } prev = l; @@ -184,7 +185,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * } } - return 0; + return true; } /* }}} */ @@ -202,15 +203,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)) { goto done1; } - if (0 > fpm_php_trace_dump(child, slowlog)) { + if (!fpm_php_trace_dump(child, slowlog)) { fprintf(slowlog, "+++ dump failed\n"); } - if (0 > fpm_trace_close(child->pid)) { + if (!fpm_trace_close(child->pid)) { goto done1; } diff --git a/sapi/fpm/fpm/fpm_process_ctl.c b/sapi/fpm/fpm/fpm_process_ctl.c index 48eb0003d4918..31842447525bb 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()) { zlog(ZLOG_WARNING, "concurrent reloads may be unstable"); } @@ -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) +bool 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 false; } for (i = 0; i < saved_argc; i++) { saved_argv[i] = strdup(fpm_globals.argv[i]); if (!saved_argv[i]) { - return -1; + return false; } } 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)) { + return false; } - return 0; + return true; } 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)) { 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..befca3588b656 100644 --- a/sapi/fpm/fpm/fpm_process_ctl.h +++ b/sapi/fpm/fpm/fpm_process_ctl.h @@ -3,6 +3,7 @@ #ifndef FPM_PROCESS_CTL_H #define FPM_PROCESS_CTL_H 1 +#include #include "fpm_events.h" /* 1s (in ms) heartbeat for idle server maintenance */ @@ -14,14 +15,14 @@ struct fpm_child_s; void fpm_pctl(int new_state, int action); -int fpm_pctl_can_spawn_children(void); +bool fpm_pctl_can_spawn_children(void); int 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); +bool fpm_pctl_init_main(void); enum { diff --git a/sapi/fpm/fpm/fpm_request.c b/sapi/fpm/fpm/fpm_request.c index 0eb75884d367a..da147f29068ab 100644 --- a/sapi/fpm/fpm/fpm_request.c +++ b/sapi/fpm/fpm/fpm_request.c @@ -278,33 +278,35 @@ void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *now, } /* }}} */ -int fpm_request_is_idle(struct fpm_child_s *child) /* {{{ */ +bool fpm_request_is_idle(struct fpm_child_s *child) /* {{{ */ { struct fpm_scoreboard_proc_s *proc; /* no need in atomicity here */ proc = fpm_scoreboard_proc_get_from_child(child); if (!proc) { - return 0; + return false; } return proc->request_stage == FPM_REQUEST_ACCEPTING; } /* }}} */ -int fpm_request_last_activity(struct fpm_child_s *child, struct timeval *tv) /* {{{ */ +bool fpm_request_last_activity(struct fpm_child_s *child, struct timeval *tv) /* {{{ */ { struct fpm_scoreboard_proc_s *proc; - if (!tv) return -1; + if (!tv) { + return false; + } proc = fpm_scoreboard_proc_get_from_child(child); if (!proc) { - return -1; + return false; } *tv = proc->tv; - return 1; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_request.h b/sapi/fpm/fpm/fpm_request.h index c1cde0111be47..cc894904182ba 100644 --- a/sapi/fpm/fpm/fpm_request.h +++ b/sapi/fpm/fpm/fpm_request.h @@ -3,6 +3,8 @@ #ifndef FPM_REQUEST_H #define FPM_REQUEST_H 1 +#include + /* hanging in accept() */ void fpm_request_accepting(void); /* start reading fastcgi request from very first byte */ @@ -20,9 +22,9 @@ struct fpm_child_s; struct timeval; void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *tv, int terminate_timeout, int slowlog_timeout, int track_finished); -int fpm_request_is_idle(struct fpm_child_s *child); +bool fpm_request_is_idle(struct fpm_child_s *child); const char *fpm_request_get_stage_name(int stage); -int fpm_request_last_activity(struct fpm_child_s *child, struct timeval *tv); +bool fpm_request_last_activity(struct fpm_child_s *child, struct timeval *tv); enum fpm_request_stage_e { FPM_REQUEST_ACCEPTING = 1, diff --git a/sapi/fpm/fpm/fpm_scoreboard.c b/sapi/fpm/fpm/fpm_scoreboard.c index 52d10a0416832..e7a434bbf53c5 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) +bool 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 false; } if (wp->scoreboard) { zlog(ZLOG_ERROR, "[pool %s] Unable to create scoreboard SHM because it already exists", wp->config->name); - return -1; + return false; } 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 false; } 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 true; } 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) /* {{{ */ +bool 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 false; } /* 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 false; } 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 true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_scoreboard.h b/sapi/fpm/fpm/fpm_scoreboard.h index c488c64bfefc4..8f53148ca8088 100644 --- a/sapi/fpm/fpm/fpm_scoreboard.h +++ b/sapi/fpm/fpm/fpm_scoreboard.h @@ -3,6 +3,7 @@ #ifndef FPM_SCOREBOARD_H #define FPM_SCOREBOARD_H 1 +#include #include #ifdef HAVE_TIMES #include @@ -70,8 +71,8 @@ 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); +bool fpm_scoreboard_init_main(void); +int fpm_scoreboard_init_child(struct fpm_worker_pool_s *wp); /* TODO Define this function? */ 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 +92,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); +bool 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_shm.c b/sapi/fpm/fpm/fpm_shm.c index 386fef8c49fa2..3788434ef30ea 100644 --- a/sapi/fpm/fpm/fpm_shm.c +++ b/sapi/fpm/fpm/fpm_shm.c @@ -38,16 +38,16 @@ void *fpm_shm_alloc(size_t size) /* {{{ */ } /* }}} */ -int fpm_shm_free(void *mem, size_t size) /* {{{ */ +bool fpm_shm_free(void *mem, size_t size) /* {{{ */ { if (!mem) { zlog(ZLOG_ERROR, "mem is NULL"); - return 0; + return false; } if (munmap(mem, size) == -1) { zlog(ZLOG_SYSERROR, "Unable to free shm"); - return 0; + return false; } if (fpm_shm_size - size > 0) { @@ -56,7 +56,7 @@ int fpm_shm_free(void *mem, size_t size) /* {{{ */ fpm_shm_size = 0; } - return 1; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_shm.h b/sapi/fpm/fpm/fpm_shm.h index 483e18b4988ba..e3a31aadb0f82 100644 --- a/sapi/fpm/fpm/fpm_shm.h +++ b/sapi/fpm/fpm/fpm_shm.h @@ -3,8 +3,10 @@ #ifndef FPM_SHM_H #define FPM_SHM_H 1 +#include + void *fpm_shm_alloc(size_t size); -int fpm_shm_free(void *mem, size_t size); +bool fpm_shm_free(void *mem, size_t size); size_t fpm_shm_get_size_allocated(void); #endif diff --git a/sapi/fpm/fpm/fpm_signals.c b/sapi/fpm/fpm/fpm_signals.c index 6aad4403768cf..54ac413b4e9f4 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) +bool 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 false; } if (0 > fd_set_blocked(sp[0], 0) || 0 > fd_set_blocked(sp[1], 0)) { zlog(ZLOG_SYSERROR, "failed to init signals: fd_set_blocked()"); - return -1; + return false; } 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 false; } 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 false; } zlog(ZLOG_DEBUG, "Unblocking all signals"); - if (0 > fpm_signals_unblock()) { - return -1; + if (!fpm_signals_unblock()) { + return false; } - return 0; + return true; } -int fpm_signals_init_child(void) +bool 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 false; } zend_signal_init(); - if (0 > fpm_signals_unblock()) { - return -1; + if (!fpm_signals_unblock()) { + return false; } - return 0; + return true; } 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) +bool 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 false; } 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 false; } } 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 false; } - return 0; + return true; } -int fpm_signals_block(void) +bool fpm_signals_block(void) { if (0 > sigprocmask(SIG_BLOCK, &block_sigset, NULL)) { zlog(ZLOG_SYSERROR, "failed to block signals"); - return -1; + return false; } - return 0; + return true; } -int fpm_signals_child_block(void) +bool 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 false; } - return 0; + return true; } -int fpm_signals_unblock(void) +bool 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 false; } - return 0; + return true; } diff --git a/sapi/fpm/fpm/fpm_signals.h b/sapi/fpm/fpm/fpm_signals.h index 67c12efdf4bac..44b32171688cc 100644 --- a/sapi/fpm/fpm/fpm_signals.h +++ b/sapi/fpm/fpm/fpm_signals.h @@ -4,14 +4,15 @@ #define FPM_SIGNALS_H 1 #include +#include -int fpm_signals_init_main(void); -int fpm_signals_init_child(void); +bool fpm_signals_init_main(void); +bool 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); +bool fpm_signals_init_mask(void); +bool fpm_signals_block(void); +bool fpm_signals_child_block(void); +bool 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..207e6570345c9 100644 --- a/sapi/fpm/fpm/fpm_sockets.c +++ b/sapi/fpm/fpm/fpm_sockets.c @@ -201,7 +201,7 @@ static int fpm_sockets_hash_op(int sock, struct sockaddr *sa, char *key, int typ } /* }}} */ -static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, int socklen) /* {{{ */ +static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, socklen_t socklen) /* {{{ */ { int flags = 1; int sock; @@ -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)) { 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)) { close(sock); return -1; } @@ -272,7 +272,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct } /* }}} */ -static int fpm_sockets_get_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, int socklen) /* {{{ */ +static int fpm_sockets_get_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, socklen_t socklen) /* {{{ */ { int sock; @@ -418,7 +418,7 @@ static zend_result fpm_socket_setfib_init(void) } #endif -int fpm_sockets_init_main(void) +bool 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 false; } #ifdef SO_SETFIB if (fpm_socket_setfib_init() == FAILURE) { - return -1; + return false; } #endif @@ -485,18 +485,18 @@ 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)) { + return false; } wp->listening_socket = fpm_socket_af_unix_listening_socket(wp); break; } if (wp->listening_socket == -1) { - return -1; + return false; } - if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len) >= 0) { + if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len)) { fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard); } } @@ -518,10 +518,7 @@ int fpm_sockets_init_main(void) } } - if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_sockets_cleanup, 0)) { - return -1; - } - return 0; + return fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_sockets_cleanup, 0); } #if HAVE_FPM_LQ @@ -530,18 +527,18 @@ int fpm_sockets_init_main(void) #include -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +bool 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 false; } #if defined(__FreeBSD__) || defined(__NetBSD__) if (info.__tcpi_sacked == 0) { - return -1; + return false; } if (cur_lq) { @@ -554,7 +551,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 false; } if (cur_lq) { @@ -566,21 +563,21 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) } #endif - return 0; + return true; } #elif defined(HAVE_LQ_TCP_CONNECTION_INFO) #include -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +bool 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 false; } if (cur_lq) { @@ -591,20 +588,20 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) *max_lq = 0; } - return 0; + return true; } #endif #ifdef HAVE_LQ_SO_LISTENQ -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +bool 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 false; } *cur_lq = val; @@ -612,44 +609,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 false; } *max_lq = val; } - return 0; + return true; } #endif #else -int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +bool fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) { - return -1; + return false; } #endif -int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */ +bool fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */ { int fd; if (!sock || sock->sun_family != AF_UNIX) { - return -1; + return false; } if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - return -1; + return false; } if (connect(fd, (struct sockaddr *)sock, socklen) == -1) { close(fd); - return -1; + return false; } close(fd); - return 0; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_sockets.h b/sapi/fpm/fpm/fpm_sockets.h index 94d903ca45564..513f0ba16a998 100644 --- a/sapi/fpm/fpm/fpm_sockets.h +++ b/sapi/fpm/fpm/fpm_sockets.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "fpm_worker_pool.h" @@ -27,9 +28,9 @@ #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); +bool fpm_sockets_init_main(void); +bool fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq); +bool fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen); static inline int fd_set_blocked(int fd, int blocked) /* {{{ */ diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index 514d60d176e39..1c5a5b599bc87 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) /* {{{ */ +bool 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 false; } 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 false; } fpm_status_ping_uri = strdup(wp->config->ping_path); fpm_status_ping_response = strdup(wp->config->ping_response); } - return 0; + return true; } /* }}} */ -int fpm_status_export_to_zval(zval *status) +bool 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 false; } /* copy the scoreboard not to bother other processes */ @@ -130,11 +130,11 @@ 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 true; } /* }}} */ -int fpm_status_handle_request(void) /* {{{ */ +bool fpm_status_handle_request(void) /* {{{ */ { struct fpm_scoreboard_s *scoreboard_p; struct fpm_scoreboard_proc_s *proc; @@ -146,7 +146,7 @@ int fpm_status_handle_request(void) /* {{{ */ zend_string *_GET_str; if (!SG(request_info).request_uri) { - return 0; + return false; } /* PING */ @@ -159,11 +159,11 @@ int fpm_status_handle_request(void) /* {{{ */ /* handle HEAD */ if (SG(request_info).headers_only) { - return 1; + return true; } PUTS(fpm_status_ping_response); - return 1; + return true; } /* STATUS */ @@ -189,7 +189,7 @@ int fpm_status_handle_request(void) /* {{{ */ sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1); sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1); PUTS("Internal error. Please review log file for errors."); - return 1; + return true; } if (scoreboard_p->idle < 0 || scoreboard_p->active < 0) { @@ -200,7 +200,7 @@ int fpm_status_handle_request(void) /* {{{ */ sapi_add_header_ex(ZEND_STRL("Expires: Thu, 01 Jan 1970 00:00:00 GMT"), 1, 1); sapi_add_header_ex(ZEND_STRL("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"), 1, 1); PUTS("Internal error. Please review log file for errors."); - return 1; + return true; } /* send common headers */ @@ -211,7 +211,7 @@ int fpm_status_handle_request(void) /* {{{ */ /* handle HEAD */ if (SG(request_info).headers_only) { fpm_scoreboard_free_copy(scoreboard_p); - return 1; + return true; } /* HTML */ @@ -600,9 +600,9 @@ int fpm_status_handle_request(void) /* {{{ */ } fpm_scoreboard_free_copy(scoreboard_p); - return 1; + return true; } - return 0; + return false; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_status.h b/sapi/fpm/fpm/fpm_status.h index bc90c6a9df681..54ead72ba575f 100644 --- a/sapi/fpm/fpm/fpm_status.h +++ b/sapi/fpm/fpm/fpm_status.h @@ -2,6 +2,8 @@ #ifndef FPM_STATUS_H #define FPM_STATUS_H 1 + +#include #include "fpm_worker_pool.h" #include "fpm_shm.h" @@ -19,15 +21,15 @@ struct fpm_status_s { struct timeval last_update; }; -int fpm_status_init_child(struct fpm_worker_pool_s *wp); +bool 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); -int fpm_status_handle_request(void); +bool fpm_status_export_to_zval(zval *status); +bool 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 1dc65aaa3452a..9cde293c0190c 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) +bool 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 false; } if (0 > dup2(fd, STDIN_FILENO) || 0 > dup2(fd, STDOUT_FILENO)) { zlog(ZLOG_SYSERROR, "failed to init stdio: dup2()"); close(fd); - return -1; + return false; } close(fd); - return 0; + return true; } -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,24 @@ 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) +bool fpm_stdio_init_final(void) { - if (0 > fpm_stdio_redirect_stderr_to_error_log() || - 0 > fpm_stdio_redirect_stderr_to_dev_null_for_syslog()) { - - return -1; + if (!fpm_stdio_redirect_stderr_to_error_log()) { + fpm_stdio_redirect_stderr_to_dev_null_for_syslog(); + return false; } zlog_set_launched(); - return 0; + return true; } /* }}} */ -int fpm_stdio_save_original_stderr(void) +bool 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 +81,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 false; } - return 0; + return true; } -int fpm_stdio_restore_original_stderr(int close_after_restore) +bool fpm_stdio_restore_original_stderr(bool 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 false; } else { if (close_after_restore) { close(fd_stderr_original); @@ -103,10 +102,10 @@ int fpm_stdio_restore_original_stderr(int close_after_restore) } } - return 0; + return true; } -int fpm_stdio_redirect_stderr_to_error_log(void) +bool fpm_stdio_redirect_stderr_to_error_log(void) { if (fpm_use_error_log()) { /* prevent duping if logging to syslog */ @@ -115,15 +114,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 false; } } } - return 0; + return true; } -int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void) +void fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void) { if (fpm_use_error_log()) { #ifdef HAVE_SYSLOG_H @@ -133,11 +132,9 @@ int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void) } #endif } - - return 0; } -int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +bool fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { #ifdef HAVE_SYSLOG_H if (fpm_globals.error_log_fd == ZLOG_SYSLOG) { @@ -155,7 +152,7 @@ int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ fpm_globals.error_log_fd = -1; zlog_set_fd(-1); - return 0; + return true; } /* }}} */ @@ -285,22 +282,22 @@ 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) /* {{{ */ +bool fpm_stdio_prepare_pipes(struct fpm_child_s *child) /* {{{ */ { if (0 == child->wp->config->catch_workers_output) { /* not required */ - return 0; + return true; } if (0 > pipe(fd_stdout)) { zlog(ZLOG_SYSERROR, "failed to prepare the stdout pipe"); - return -1; + return false; } 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 false; } if (0 > fd_set_blocked(fd_stdout[0], 0) || 0 > fd_set_blocked(fd_stderr[0], 0)) { @@ -309,16 +306,16 @@ int fpm_stdio_prepare_pipes(struct fpm_child_s *child) /* {{{ */ close(fd_stdout[1]); close(fd_stderr[0]); close(fd_stderr[1]); - return -1; + return false; } - return 0; + return true; } /* }}} */ -int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */ +void fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */ { if (0 == child->wp->config->catch_workers_output) { /* not required */ - return 0; + return; } close(fd_stdout[1]); @@ -332,14 +329,13 @@ 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, child); fpm_event_add(&child->ev_stderr, 0); - return 0; } /* }}} */ -int fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */ +void fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */ { if (0 == child->wp->config->catch_workers_output) { /* not required */ - return 0; + return; } close(fd_stdout[1]); @@ -347,7 +343,6 @@ int fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */ close(fd_stdout[0]); close(fd_stderr[0]); - return 0; } /* }}} */ @@ -365,7 +360,7 @@ void fpm_stdio_child_use_pipes(struct fpm_child_s *child) /* {{{ */ } /* }}} */ -int fpm_stdio_open_error_log(int reopen) /* {{{ */ +bool fpm_stdio_open_error_log(bool reopen) /* {{{ */ { int fd; @@ -376,14 +371,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 true; } #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 false; } if (reopen) { @@ -399,6 +394,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 true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_stdio.h b/sapi/fpm/fpm/fpm_stdio.h index 49be50de562d9..7136ac3a7cdff 100644 --- a/sapi/fpm/fpm/fpm_stdio.h +++ b/sapi/fpm/fpm/fpm_stdio.h @@ -3,22 +3,23 @@ #ifndef FPM_STDIO_H #define FPM_STDIO_H 1 +#include #include "fpm_worker_pool.h" #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); +bool fpm_stdio_init_main(void); +bool fpm_stdio_init_final(void); +bool 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); +bool 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); +void fpm_stdio_parent_use_pipes(struct fpm_child_s *child); +void fpm_stdio_discard_pipes(struct fpm_child_s *child); +bool fpm_stdio_open_error_log(bool reopen); +bool fpm_stdio_save_original_stderr(void); +bool fpm_stdio_restore_original_stderr(bool close_after_restore); +void fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void); +bool 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..30cdf00946540 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) +void fpm_systemd_conf(void) { char *watchdog; int interval = 0; @@ -106,5 +106,4 @@ int fpm_systemd_conf(void) /* sec to msec */ fpm_global_config.systemd_interval *= 1000; } - return 0; } diff --git a/sapi/fpm/fpm/fpm_systemd.h b/sapi/fpm/fpm/fpm_systemd.h index 93a70fb5266e4..fa94e251f6d81 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); +void fpm_systemd_conf(void); #endif diff --git a/sapi/fpm/fpm/fpm_trace.c b/sapi/fpm/fpm/fpm_trace.c index 3d0b9de98a0bb..ca9bd0b26a9f6 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) /* {{{ */ +bool 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)) { + return false; } 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 true; } i = 0; } diff --git a/sapi/fpm/fpm/fpm_trace.h b/sapi/fpm/fpm/fpm_trace.h index 4ee021229db6d..2cdda3e7fe61d 100644 --- a/sapi/fpm/fpm/fpm_trace.h +++ b/sapi/fpm/fpm/fpm_trace.h @@ -3,12 +3,13 @@ #ifndef FPM_TRACE_H #define FPM_TRACE_H 1 +#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); +bool fpm_trace_signal(pid_t pid); +bool fpm_trace_ready(pid_t pid); +bool fpm_trace_close(pid_t pid); +bool fpm_trace_get_long(long addr, long *data); +bool 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..8200658939e14 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 bool 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 false; } - return 0; + return true; } /* }}} */ -int fpm_trace_signal(pid_t pid) /* {{{ */ +bool fpm_trace_signal(pid_t pid) /* {{{ */ { if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) { zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid); - return -1; + return false; } - return 0; + return true; } /* }}} */ -int fpm_trace_ready(pid_t pid) /* {{{ */ +bool 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 false; } - return 0; + return true; } /* }}} */ -int fpm_trace_close(pid_t pid) /* {{{ */ +bool fpm_trace_close(pid_t pid) /* {{{ */ { fpm_mach_vm_deallocate(); target = 0; - return 0; + return true; } /* }}} */ -int fpm_trace_get_long(long addr, long *data) /* {{{ */ +bool 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)) { + return false; } } *data = * (long *) (local_page + offset); - return 0; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_trace_pread.c b/sapi/fpm/fpm/fpm_trace_pread.c index 8bf4223410993..d26582dc5ce46 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) /* {{{ */ +bool fpm_trace_signal(pid_t pid) /* {{{ */ { if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) { zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid); - return -1; + return false; } - return 0; + return true; } /* }}} */ -int fpm_trace_ready(pid_t pid) /* {{{ */ +bool 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 false; } - return 0; + return true; } /* }}} */ -int fpm_trace_close(pid_t pid) /* {{{ */ +bool fpm_trace_close(pid_t pid) /* {{{ */ { close(mem_file); mem_file = -1; - return 0; + return true; } /* }}} */ -int fpm_trace_get_long(long addr, long *data) /* {{{ */ +bool 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 false; } - return 0; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_trace_ptrace.c b/sapi/fpm/fpm/fpm_trace_ptrace.c index a2a3d25e30ef3..1b9ffe01739a3 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) /* {{{ */ +bool 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 false; } - return 0; + return true; } /* }}} */ -int fpm_trace_ready(pid_t pid) /* {{{ */ +bool fpm_trace_ready(pid_t pid) /* {{{ */ { traced_pid = pid; - return 0; + return true; } /* }}} */ -int fpm_trace_close(pid_t pid) /* {{{ */ +bool 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 false; } traced_pid = 0; - return 0; + return true; } /* }}} */ -int fpm_trace_get_long(long addr, long *data) /* {{{ */ +bool 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 false; } #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 false; } #endif - return 0; + return true; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_unix.c b/sapi/fpm/fpm/fpm_unix.c index 333265b07bd4a..3372d344560ce 100644 --- a/sapi/fpm/fpm/fpm_unix.c +++ b/sapi/fpm/fpm/fpm_unix.c @@ -46,7 +46,7 @@ size_t fpm_pagesize; -int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ +bool fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ { struct fpm_worker_pool_config_s *c = wp->config; #ifdef HAVE_FPM_ACL @@ -60,7 +60,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ wp->socket_mode = 0660; if (!c) { - return 0; + return true; } if (c->listen_mode && *c->listen_mode) { @@ -94,7 +94,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 false; } /* Create USER ACL */ if (c->listen_acl_users && *c->listen_acl_users) { @@ -112,7 +112,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ zlog(ZLOG_SYSERROR, "[pool %s] cannot get uid for user '%s'", wp->config->name, p); acl_free(acl); efree(tmp); - return -1; + return false; } if (0 > acl_create_entry(&acl, &entry) || 0 > acl_set_tag_type(entry, ACL_USER) || @@ -124,7 +124,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 false; } } efree(tmp); @@ -145,7 +145,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ zlog(ZLOG_SYSERROR, "[pool %s] cannot get gid for group '%s'", wp->config->name, p); acl_free(acl); efree(tmp); - return -1; + return false; } if (0 > acl_create_entry(&acl, &entry) || 0 > acl_set_tag_type(entry, ACL_GROUP) || @@ -157,7 +157,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 false; } } efree(tmp); @@ -169,7 +169,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 true; } /* When listen.users and listen.groups not configured, continue with standard right */ #endif @@ -183,7 +183,7 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ pwd = getpwnam(c->listen_owner); if (!pwd) { zlog(ZLOG_SYSERROR, "[pool %s] cannot get uid for user '%s'", wp->config->name, c->listen_owner); - return -1; + return false; } wp->socket_uid = pwd->pw_uid; @@ -200,17 +200,17 @@ int fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ grp = getgrnam(c->listen_group); if (!grp) { zlog(ZLOG_SYSERROR, "[pool %s] cannot get gid for group '%s'", wp->config->name, c->listen_group); - return -1; + return false; } wp->socket_gid = grp->gr_gid; } } - return 0; + return true; } /* }}} */ -int fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *path) /* {{{ */ +bool fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *path) /* {{{ */ { #ifdef HAVE_FPM_ACL if (wp->socket_acl) { @@ -223,7 +223,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 false; } /* Copy the new ACL entry from config */ for (i=ACL_FIRST_ENTRY ; acl_get_entry(aclconf, i, &entryconf) ; i=ACL_NEXT_ENTRY) { @@ -231,7 +231,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 false; } } /* Write the socket ACL */ @@ -240,13 +240,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 false; } else { zlog(ZLOG_DEBUG, "[pool %s] ACL of the socket '%s' is set", wp->config->name, path); } acl_free(aclfile); - return 0; + return true; } /* When listen.users and listen.groups not configured, continue with standard right */ #endif @@ -254,25 +254,26 @@ 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 false; } } - return 0; + return true; } /* }}} */ -int fpm_unix_free_socket_permissions(struct fpm_worker_pool_s *wp) /* {{{ */ +bool 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); + /* 0 on success, -1 on failure */ + return acl_free(wp->socket_acl) == 0; } #endif - return 0; + return true; } /* }}} */ -static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ +static bool fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ { struct passwd *pwd; int is_root = !geteuid(); @@ -287,7 +288,7 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ pwd = getpwnam(wp->config->user); if (!pwd) { zlog(ZLOG_ERROR, "[pool %s] cannot get uid for user '%s'", wp->config->name, wp->config->user); - return -1; + return false; } wp->set_uid = pwd->pw_uid; @@ -307,7 +308,7 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ grp = getgrnam(wp->config->group); if (!grp) { zlog(ZLOG_ERROR, "[pool %s] cannot get gid for group '%s'", wp->config->name, wp->config->group); - return -1; + return false; } wp->set_gid = grp->gr_gid; } @@ -316,7 +317,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 false; } } } else { /* not root */ @@ -340,11 +341,11 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ wp->home = strdup(pwd->pw_dir); } } - return 0; + return true; } /* }}} */ -int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ +bool fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ { int is_root = !geteuid(); int made_chroot = 0; @@ -372,7 +373,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 false; } made_chroot = 1; } @@ -380,7 +381,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 false; } } else if (made_chroot) { if (0 > chdir("/")) { @@ -393,24 +394,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 false; } } 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 false; } } if (wp->set_uid) { if (0 > initgroups(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 false; } if (0 > setuid(wp->set_uid)) { zlog(ZLOG_SYSERROR, "[pool %s] failed to setuid(%d)", wp->config->name, wp->set_uid); - return -1; + return false; } } } @@ -443,8 +444,8 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } #endif - if (0 > fpm_clock_init()) { - return -1; + if (!fpm_clock_init()) { + return false; } #ifdef HAVE_APPARMOR @@ -453,28 +454,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 false; } 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 false; } 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 false; } 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 false; } free(con); @@ -482,11 +483,11 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } #endif - return 0; + return true; } /* }}} */ -int fpm_unix_init_main(void) +bool fpm_unix_init_main(void) { struct fpm_worker_pool_s *wp; int is_root = !geteuid(); @@ -498,7 +499,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 false; } } @@ -509,7 +510,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 false; } } @@ -533,7 +534,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 false; } /* then fork */ @@ -542,7 +543,7 @@ int fpm_unix_init_main(void) case -1 : /* error */ zlog(ZLOG_SYSERROR, "failed to daemonize"); - return -1; + return false; case 0 : /* children */ close(fpm_globals.send_config_pipe[0]); /* close the read side of the pipe */ @@ -599,15 +600,15 @@ int fpm_unix_init_main(void) /* continue as a child */ setsid(); - if (0 > fpm_clock_init()) { - return -1; + if (!fpm_clock_init()) { + return false; } 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 false; } } else { zlog(ZLOG_NOTICE, "'process.priority' directive is ignored when FPM is not running as root"); @@ -616,10 +617,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)) { + return false; } } - return 0; + return true; } diff --git a/sapi/fpm/fpm/fpm_unix.h b/sapi/fpm/fpm/fpm_unix.h index 0bb22687b02f9..d73153e9253e9 100644 --- a/sapi/fpm/fpm/fpm_unix.h +++ b/sapi/fpm/fpm/fpm_unix.h @@ -3,14 +3,15 @@ #ifndef FPM_UNIX_H #define FPM_UNIX_H 1 +#include #include "fpm_worker_pool.h" -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); +bool fpm_unix_resolve_socket_permissions(struct fpm_worker_pool_s *wp); +bool fpm_unix_set_socket_permissions(struct fpm_worker_pool_s *wp, const char *path); +bool 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); +bool fpm_unix_init_child(struct fpm_worker_pool_s *wp); +bool 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 974238de296d4..f89ac3e305524 100644 --- a/sapi/fpm/fpm/fpm_worker_pool.c +++ b/sapi/fpm/fpm/fpm_worker_pool.c @@ -78,10 +78,7 @@ struct fpm_worker_pool_s *fpm_worker_pool_alloc(void) return ret; } -int fpm_worker_pool_init_main(void) +bool 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 809f53a0545b5..1d05e6261d447 100644 --- a/sapi/fpm/fpm/fpm_worker_pool.h +++ b/sapi/fpm/fpm/fpm_worker_pool.h @@ -3,6 +3,7 @@ #ifndef FPM_WORKER_POOL_H #define FPM_WORKER_POOL_H 1 +#include #include "fpm_conf.h" #include "fpm_shm.h" @@ -49,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); +bool fpm_worker_pool_init_main(void); void fpm_worker_pool_free_limit_extensions(char **limit_extensions);