Skip to content

Change return values to bool or void in FPM #9911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
287eb5e
Use bool instead of int as return value for FPM status functions
Girgias Nov 8, 2022
f88e57e
Change return type of fpm_children_free() to void
Girgias Nov 8, 2022
c9ab06e
Change return type of fpm_children_init_main() to bool
Girgias Nov 8, 2022
b14200d
Change return type of fpm_cleanup_add() to bool
Girgias Nov 8, 2022
2cdc254
Change return type of fpm_clock_init() to bool
Girgias Nov 8, 2022
2429199
Convert return value to bool or void in fpm_conf.c
Girgias Nov 8, 2022
b1a3d45
Convert return value to bool or void in fpm_env.c
Girgias Nov 8, 2022
931b51d
Convert return values to bool in fpm_events.c
Girgias Nov 8, 2022
df335e9
Convert return values to bool in fpm_log.c
Girgias Nov 8, 2022
0d26974
Convert return values to bool in fpm_php.c
Girgias Nov 8, 2022
a59a942
Change return type of fpm_php_trace_dump() to bool
Girgias Nov 8, 2022
1c5b9c8
Convert return value to bool or void in fpm_process_ctl.c
Girgias Nov 8, 2022
7c8c7dc
Convert return values to bool in fpm_request.c
Girgias Nov 8, 2022
9eae86b
Convert return values to bool in fpm_scoreboard.c
Girgias Nov 8, 2022
7e84171
Formalize return type of fpm_shm_free() to bool
Girgias Nov 8, 2022
84b1372
Convert return values to bool in fpm_signals.c
Girgias Nov 8, 2022
ff7c729
Convert return values to bool in fpm_sockets.c
Girgias Nov 8, 2022
f30a758
Convert return value to bool or void in fpm_stdio.c
Girgias Nov 8, 2022
1d00cf0
Make return type of fpm_systemd_conf() void
Girgias Nov 8, 2022
c9dccc9
Convert return values to bool in fpm_trace.c files
Girgias Nov 8, 2022
f0b2a1f
Convert return values to bool in fpm_unix.c
Girgias Nov 8, 2022
bf93730
Convert return value to bool for fpm_worker_pool_init_main()
Girgias Nov 8, 2022
21023b4
Convert return value to bool for fpm_init()
Girgias Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions sapi/fpm/fpm/fpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct fpm_globals_s fpm_globals = {
.send_config_pipe = {0, 0},
};

int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr) /* {{{ */
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;
Expand All @@ -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;
}
/* }}} */

Expand Down
3 changes: 2 additions & 1 deletion sapi/fpm/fpm/fpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define FPM_H 1

#include <unistd.h>
#include <stdbool.h>

#ifdef HAVE_SYSEXITS_H
#include <sysexits.h>
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 16 additions & 18 deletions sapi/fpm/fpm/fpm_children.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,30 +149,28 @@ 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);
}
}
/* }}} */

int fpm_children_free(struct fpm_child_s *child) /* {{{ */
void fpm_children_free(struct fpm_child_s *child) /* {{{ */
{
struct fpm_child_s *next;

for (; child; child = next) {
next = child->next;
fpm_child_close(child, 0 /* in_event_loop */);
}

return 0;
}
/* }}} */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -470,23 +468,23 @@ 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) {

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;
}
5 changes: 3 additions & 2 deletions sapi/fpm/fpm/fpm_children.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

#include <sys/time.h>
#include <sys/types.h>
#include <stdbool.h>

#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;
Expand Down
6 changes: 3 additions & 3 deletions sapi/fpm/fpm/fpm_cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
/* }}} */

Expand Down
4 changes: 3 additions & 1 deletion sapi/fpm/fpm/fpm_cleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdbool.h>

bool fpm_cleanup_add(int type, void (*cleanup)(int, void *), void *);
void fpm_cleanups_run(int type);

enum {
Expand Down
18 changes: 9 additions & 9 deletions sapi/fpm/fpm/fpm_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +25,7 @@ int fpm_clock_init(void)
monotonic_works = 1;
}

return 0;
return true;
}

int fpm_clock_get(struct timeval *tv) /* {{{ */
Expand Down Expand Up @@ -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;
Expand All @@ -67,18 +67,18 @@ 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 */
ret = clock_get_time(mach_clock, &aTime);

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) /* {{{ */
Expand All @@ -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) /* {{{ */
Expand Down
3 changes: 2 additions & 1 deletion sapi/fpm/fpm/fpm_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#define FPM_CLOCK_H 1

#include <sys/time.h>
#include <stdbool.h>

int fpm_clock_init(void);
bool fpm_clock_init(void);
int fpm_clock_get(struct timeval *tv);

#endif
Loading