Skip to content

Commit 3aeb74b

Browse files
committed
Convert return value to bool or void in fpm_stdio.c
Either the return value was always the same, or just returned either 0 or -1
1 parent f1385c0 commit 3aeb74b

File tree

6 files changed

+55
-60
lines changed

6 files changed

+55
-60
lines changed

sapi/fpm/fpm/fpm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
5454
fpm_globals.force_stderr = force_stderr;
5555

5656
if (!fpm_php_init_main() ||
57-
0 > fpm_stdio_init_main() ||
57+
!fpm_stdio_init_main() ||
5858
!fpm_conf_init_main(test_conf, force_daemon) ||
5959
0 > fpm_unix_init_main() ||
6060
!fpm_scoreboard_init_main() ||

sapi/fpm/fpm/fpm_children.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void fpm_child_init(struct fpm_worker_pool_s *wp) /* {{{ */
149149
fpm_globals.max_requests = wp->config->pm_max_requests;
150150
fpm_globals.listening_socket = dup(wp->listening_socket);
151151

152-
if (0 > fpm_stdio_init_child(wp) ||
152+
if (!fpm_stdio_init_child(wp) /* Note: this never fails */ ||
153153
!fpm_log_init_child(wp) ||
154154
!fpm_status_init_child(wp) ||
155155
0 > fpm_unix_init_child(wp) ||
@@ -315,7 +315,7 @@ static struct fpm_child_s *fpm_resources_prepare(struct fpm_worker_pool_s *wp) /
315315
c->wp = wp;
316316
c->fd_stdout = -1; c->fd_stderr = -1;
317317

318-
if (0 > fpm_stdio_prepare_pipes(c)) {
318+
if (!fpm_stdio_prepare_pipes(c)) {
319319
fpm_child_free(c);
320320
return 0;
321321
}

sapi/fpm/fpm/fpm_conf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,11 +1315,11 @@ static bool fpm_conf_post_process(int force_daemon) /* {{{ */
13151315
fpm_evaluate_full_path(&fpm_global_config.error_log, NULL, PHP_LOCALSTATEDIR, 0);
13161316
}
13171317

1318-
if (!fpm_global_config.daemonize && 0 > fpm_stdio_save_original_stderr()) {
1318+
if (!fpm_global_config.daemonize && !fpm_stdio_save_original_stderr()) {
13191319
return false;
13201320
}
13211321

1322-
if (0 > fpm_stdio_open_error_log(0)) {
1322+
if (!fpm_stdio_open_error_log(/* reopen */ false)) {
13231323
return false;
13241324
}
13251325

sapi/fpm/fpm/fpm_events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static void fpm_got_signal(struct fpm_event_s *ev, short which, void *arg) /* {{
109109
* access.log if it was configured to write to the stderr. Check #8885. */
110110
fpm_stdio_restore_original_stderr(0);
111111

112-
if (0 == fpm_stdio_open_error_log(1)) {
112+
if (fpm_stdio_open_error_log(/* reopen */ true)) {
113113
zlog(ZLOG_NOTICE, "error log file re-opened");
114114
} else {
115115
zlog(ZLOG_ERROR, "unable to re-opened error log file");

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ static int fd_stderr_original = -1;
2424
static int fd_stdout[2];
2525
static int fd_stderr[2];
2626

27-
int fpm_stdio_init_main(void)
27+
bool fpm_stdio_init_main(void)
2828
{
2929
int fd = open("/dev/null", O_RDWR);
3030

3131
if (0 > fd) {
3232
zlog(ZLOG_SYSERROR, "failed to init stdio: open(\"/dev/null\")");
33-
return -1;
33+
return false;
3434
}
3535

3636
if (0 > dup2(fd, STDIN_FILENO) || 0 > dup2(fd, STDOUT_FILENO)) {
3737
zlog(ZLOG_SYSERROR, "failed to init stdio: dup2()");
3838
close(fd);
39-
return -1;
39+
return false;
4040
}
4141
close(fd);
42-
return 0;
42+
return true;
4343
}
4444

45-
static inline int fpm_use_error_log(void) {
45+
static inline bool fpm_use_error_log(void) {
4646
/*
4747
* the error_log is NOT used when running in foreground
4848
* and from a tty (user looking at output).
@@ -55,25 +55,24 @@ static inline int fpm_use_error_log(void) {
5555
#else
5656
if (fpm_global_config.daemonize) {
5757
#endif
58-
return 1;
58+
return true;
5959
}
60-
return 0;
60+
return false;
6161
}
6262

63-
int fpm_stdio_init_final(void)
63+
bool fpm_stdio_init_final(void)
6464
{
65-
if (0 > fpm_stdio_redirect_stderr_to_error_log() ||
66-
0 > fpm_stdio_redirect_stderr_to_dev_null_for_syslog()) {
67-
68-
return -1;
65+
if (!fpm_stdio_redirect_stderr_to_error_log()) {
66+
fpm_stdio_redirect_stderr_to_dev_null_for_syslog();
67+
return false;
6968
}
7069

7170
zlog_set_launched();
72-
return 0;
71+
return true;
7372
}
7473
/* }}} */
7574

76-
int fpm_stdio_save_original_stderr(void)
75+
bool fpm_stdio_save_original_stderr(void)
7776
{
7877
/* STDERR fd gets lost after calling fpm_stdio_init_final() (check GH-8555) so it can be saved.
7978
* It should be used only when PHP-FPM is not daemonized otherwise it might break some
@@ -82,31 +81,31 @@ int fpm_stdio_save_original_stderr(void)
8281
fd_stderr_original = dup(STDERR_FILENO);
8382
if (0 > fd_stderr_original) {
8483
zlog(ZLOG_SYSERROR, "failed to save original STDERR fd, access.log records may appear in error_log: dup()");
85-
return -1;
84+
return false;
8685
}
8786

88-
return 0;
87+
return true;
8988
}
9089

91-
int fpm_stdio_restore_original_stderr(int close_after_restore)
90+
bool fpm_stdio_restore_original_stderr(bool close_after_restore)
9291
{
9392
/* Restore original STDERR fd if it was previously saved. */
9493
if (-1 != fd_stderr_original) {
9594
zlog(ZLOG_DEBUG, "restoring original STDERR fd: dup2()");
9695
if (0 > dup2(fd_stderr_original, STDERR_FILENO)) {
9796
zlog(ZLOG_SYSERROR, "failed to restore original STDERR fd, access.log records may appear in error_log: dup2()");
98-
return -1;
97+
return false;
9998
} else {
10099
if (close_after_restore) {
101100
close(fd_stderr_original);
102101
}
103102
}
104103
}
105104

106-
return 0;
105+
return true;
107106
}
108107

109-
int fpm_stdio_redirect_stderr_to_error_log(void)
108+
bool fpm_stdio_redirect_stderr_to_error_log(void)
110109
{
111110
if (fpm_use_error_log()) {
112111
/* prevent duping if logging to syslog */
@@ -115,15 +114,15 @@ int fpm_stdio_redirect_stderr_to_error_log(void)
115114
/* there might be messages to stderr from other parts of the code, we need to log them all */
116115
if (0 > dup2(fpm_globals.error_log_fd, STDERR_FILENO)) {
117116
zlog(ZLOG_SYSERROR, "failed to tie stderr fd with error_log fd: dup2()");
118-
return -1;
117+
return false;
119118
}
120119
}
121120
}
122121

123-
return 0;
122+
return true;
124123
}
125124

126-
int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void)
125+
void fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void)
127126
{
128127
if (fpm_use_error_log()) {
129128
#ifdef HAVE_SYSLOG_H
@@ -133,11 +132,9 @@ int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void)
133132
}
134133
#endif
135134
}
136-
137-
return 0;
138135
}
139136

140-
int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
137+
bool fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
141138
{
142139
#ifdef HAVE_SYSLOG_H
143140
if (fpm_globals.error_log_fd == ZLOG_SYSLOG) {
@@ -155,7 +152,7 @@ int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
155152
fpm_globals.error_log_fd = -1;
156153
zlog_set_fd(-1);
157154

158-
return 0;
155+
return true;
159156
}
160157
/* }}} */
161158

@@ -285,22 +282,22 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
285282
}
286283
/* }}} */
287284

288-
int fpm_stdio_prepare_pipes(struct fpm_child_s *child) /* {{{ */
285+
bool fpm_stdio_prepare_pipes(struct fpm_child_s *child) /* {{{ */
289286
{
290287
if (0 == child->wp->config->catch_workers_output) { /* not required */
291-
return 0;
288+
return true;
292289
}
293290

294291
if (0 > pipe(fd_stdout)) {
295292
zlog(ZLOG_SYSERROR, "failed to prepare the stdout pipe");
296-
return -1;
293+
return false;
297294
}
298295

299296
if (0 > pipe(fd_stderr)) {
300297
zlog(ZLOG_SYSERROR, "failed to prepare the stderr pipe");
301298
close(fd_stdout[0]);
302299
close(fd_stdout[1]);
303-
return -1;
300+
return false;
304301
}
305302

306303
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) /* {{{ */
309306
close(fd_stdout[1]);
310307
close(fd_stderr[0]);
311308
close(fd_stderr[1]);
312-
return -1;
309+
return false;
313310
}
314-
return 0;
311+
return true;
315312
}
316313
/* }}} */
317314

318-
int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */
315+
void fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */
319316
{
320317
if (0 == child->wp->config->catch_workers_output) { /* not required */
321-
return 0;
318+
return;
322319
}
323320

324321
close(fd_stdout[1]);
@@ -332,22 +329,20 @@ int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */
332329

333330
fpm_event_set(&child->ev_stderr, child->fd_stderr, FPM_EV_READ, fpm_stdio_child_said, child);
334331
fpm_event_add(&child->ev_stderr, 0);
335-
return 0;
336332
}
337333
/* }}} */
338334

339-
int fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */
335+
void fpm_stdio_discard_pipes(struct fpm_child_s *child) /* {{{ */
340336
{
341337
if (0 == child->wp->config->catch_workers_output) { /* not required */
342-
return 0;
338+
return;
343339
}
344340

345341
close(fd_stdout[1]);
346342
close(fd_stderr[1]);
347343

348344
close(fd_stdout[0]);
349345
close(fd_stderr[0]);
350-
return 0;
351346
}
352347
/* }}} */
353348

@@ -365,7 +360,7 @@ void fpm_stdio_child_use_pipes(struct fpm_child_s *child) /* {{{ */
365360
}
366361
/* }}} */
367362

368-
int fpm_stdio_open_error_log(int reopen) /* {{{ */
363+
bool fpm_stdio_open_error_log(bool reopen) /* {{{ */
369364
{
370365
int fd;
371366

@@ -376,14 +371,14 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */
376371
if (fpm_use_error_log()) {
377372
zlog_set_fd(fpm_globals.error_log_fd);
378373
}
379-
return 0;
374+
return true;
380375
}
381376
#endif
382377

383378
fd = open(fpm_global_config.error_log, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
384379
if (0 > fd) {
385380
zlog(ZLOG_SYSERROR, "failed to open error_log (%s)", fpm_global_config.error_log);
386-
return -1;
381+
return false;
387382
}
388383

389384
if (reopen) {
@@ -399,6 +394,6 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */
399394
if (0 > fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)) {
400395
zlog(ZLOG_WARNING, "failed to change attribute of error_log");
401396
}
402-
return 0;
397+
return true;
403398
}
404399
/* }}} */

sapi/fpm/fpm/fpm_stdio.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
#define STREAM_SET_MSG_PREFIX_FMT "[pool %s] child %d said into %s: "
99

10-
int fpm_stdio_init_main(void);
11-
int fpm_stdio_init_final(void);
12-
int fpm_stdio_init_child(struct fpm_worker_pool_s *wp);
10+
bool fpm_stdio_init_main(void);
11+
bool fpm_stdio_init_final(void);
12+
bool fpm_stdio_init_child(struct fpm_worker_pool_s *wp);
1313
int fpm_stdio_flush_child(void);
14-
int fpm_stdio_prepare_pipes(struct fpm_child_s *child);
14+
bool fpm_stdio_prepare_pipes(struct fpm_child_s *child);
1515
void fpm_stdio_child_use_pipes(struct fpm_child_s *child);
16-
int fpm_stdio_parent_use_pipes(struct fpm_child_s *child);
17-
int fpm_stdio_discard_pipes(struct fpm_child_s *child);
18-
int fpm_stdio_open_error_log(int reopen);
19-
int fpm_stdio_save_original_stderr(void);
20-
int fpm_stdio_restore_original_stderr(int close_after_restore);
21-
int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void);
22-
int fpm_stdio_redirect_stderr_to_error_log(void);
16+
void fpm_stdio_parent_use_pipes(struct fpm_child_s *child);
17+
void fpm_stdio_discard_pipes(struct fpm_child_s *child);
18+
bool fpm_stdio_open_error_log(bool reopen);
19+
bool fpm_stdio_save_original_stderr(void);
20+
bool fpm_stdio_restore_original_stderr(int close_after_restore);
21+
void fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void);
22+
bool fpm_stdio_redirect_stderr_to_error_log(void);
2323

2424
#endif

0 commit comments

Comments
 (0)