@@ -24,25 +24,25 @@ static int fd_stderr_original = -1;
24
24
static int fd_stdout [2 ];
25
25
static int fd_stderr [2 ];
26
26
27
- int fpm_stdio_init_main (void )
27
+ bool fpm_stdio_init_main (void )
28
28
{
29
29
int fd = open ("/dev/null" , O_RDWR );
30
30
31
31
if (0 > fd ) {
32
32
zlog (ZLOG_SYSERROR , "failed to init stdio: open(\"/dev/null\")" );
33
- return -1 ;
33
+ return false ;
34
34
}
35
35
36
36
if (0 > dup2 (fd , STDIN_FILENO ) || 0 > dup2 (fd , STDOUT_FILENO )) {
37
37
zlog (ZLOG_SYSERROR , "failed to init stdio: dup2()" );
38
38
close (fd );
39
- return -1 ;
39
+ return false ;
40
40
}
41
41
close (fd );
42
- return 0 ;
42
+ return true ;
43
43
}
44
44
45
- static inline int fpm_use_error_log (void ) {
45
+ static inline bool fpm_use_error_log (void ) {
46
46
/*
47
47
* the error_log is NOT used when running in foreground
48
48
* and from a tty (user looking at output).
@@ -55,25 +55,24 @@ static inline int fpm_use_error_log(void) {
55
55
#else
56
56
if (fpm_global_config .daemonize ) {
57
57
#endif
58
- return 1 ;
58
+ return true ;
59
59
}
60
- return 0 ;
60
+ return false ;
61
61
}
62
62
63
- int fpm_stdio_init_final (void )
63
+ bool fpm_stdio_init_final (void )
64
64
{
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;
69
68
}
70
69
71
70
zlog_set_launched ();
72
- return 0 ;
71
+ return true ;
73
72
}
74
73
/* }}} */
75
74
76
- int fpm_stdio_save_original_stderr (void )
75
+ bool fpm_stdio_save_original_stderr (void )
77
76
{
78
77
/* STDERR fd gets lost after calling fpm_stdio_init_final() (check GH-8555) so it can be saved.
79
78
* 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)
82
81
fd_stderr_original = dup (STDERR_FILENO );
83
82
if (0 > fd_stderr_original ) {
84
83
zlog (ZLOG_SYSERROR , "failed to save original STDERR fd, access.log records may appear in error_log: dup()" );
85
- return -1 ;
84
+ return false ;
86
85
}
87
86
88
- return 0 ;
87
+ return true ;
89
88
}
90
89
91
- int fpm_stdio_restore_original_stderr (int close_after_restore )
90
+ bool fpm_stdio_restore_original_stderr (bool close_after_restore )
92
91
{
93
92
/* Restore original STDERR fd if it was previously saved. */
94
93
if (-1 != fd_stderr_original ) {
95
94
zlog (ZLOG_DEBUG , "restoring original STDERR fd: dup2()" );
96
95
if (0 > dup2 (fd_stderr_original , STDERR_FILENO )) {
97
96
zlog (ZLOG_SYSERROR , "failed to restore original STDERR fd, access.log records may appear in error_log: dup2()" );
98
- return -1 ;
97
+ return false ;
99
98
} else {
100
99
if (close_after_restore ) {
101
100
close (fd_stderr_original );
102
101
}
103
102
}
104
103
}
105
104
106
- return 0 ;
105
+ return true ;
107
106
}
108
107
109
- int fpm_stdio_redirect_stderr_to_error_log (void )
108
+ bool fpm_stdio_redirect_stderr_to_error_log (void )
110
109
{
111
110
if (fpm_use_error_log ()) {
112
111
/* prevent duping if logging to syslog */
@@ -115,15 +114,15 @@ int fpm_stdio_redirect_stderr_to_error_log(void)
115
114
/* there might be messages to stderr from other parts of the code, we need to log them all */
116
115
if (0 > dup2 (fpm_globals .error_log_fd , STDERR_FILENO )) {
117
116
zlog (ZLOG_SYSERROR , "failed to tie stderr fd with error_log fd: dup2()" );
118
- return -1 ;
117
+ return false ;
119
118
}
120
119
}
121
120
}
122
121
123
- return 0 ;
122
+ return true ;
124
123
}
125
124
126
- int fpm_stdio_redirect_stderr_to_dev_null_for_syslog (void )
125
+ void fpm_stdio_redirect_stderr_to_dev_null_for_syslog (void )
127
126
{
128
127
if (fpm_use_error_log ()) {
129
128
#ifdef HAVE_SYSLOG_H
@@ -133,11 +132,9 @@ int fpm_stdio_redirect_stderr_to_dev_null_for_syslog(void)
133
132
}
134
133
#endif
135
134
}
136
-
137
- return 0 ;
138
135
}
139
136
140
- int fpm_stdio_init_child (struct fpm_worker_pool_s * wp ) /* {{{ */
137
+ bool fpm_stdio_init_child (struct fpm_worker_pool_s * wp ) /* {{{ */
141
138
{
142
139
#ifdef HAVE_SYSLOG_H
143
140
if (fpm_globals .error_log_fd == ZLOG_SYSLOG ) {
@@ -155,7 +152,7 @@ int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
155
152
fpm_globals .error_log_fd = -1 ;
156
153
zlog_set_fd (-1 );
157
154
158
- return 0 ;
155
+ return true ;
159
156
}
160
157
/* }}} */
161
158
@@ -285,22 +282,22 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
285
282
}
286
283
/* }}} */
287
284
288
- int fpm_stdio_prepare_pipes (struct fpm_child_s * child ) /* {{{ */
285
+ bool fpm_stdio_prepare_pipes (struct fpm_child_s * child ) /* {{{ */
289
286
{
290
287
if (0 == child -> wp -> config -> catch_workers_output ) { /* not required */
291
- return 0 ;
288
+ return true ;
292
289
}
293
290
294
291
if (0 > pipe (fd_stdout )) {
295
292
zlog (ZLOG_SYSERROR , "failed to prepare the stdout pipe" );
296
- return -1 ;
293
+ return false ;
297
294
}
298
295
299
296
if (0 > pipe (fd_stderr )) {
300
297
zlog (ZLOG_SYSERROR , "failed to prepare the stderr pipe" );
301
298
close (fd_stdout [0 ]);
302
299
close (fd_stdout [1 ]);
303
- return -1 ;
300
+ return false ;
304
301
}
305
302
306
303
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) /* {{{ */
309
306
close (fd_stdout [1 ]);
310
307
close (fd_stderr [0 ]);
311
308
close (fd_stderr [1 ]);
312
- return -1 ;
309
+ return false ;
313
310
}
314
- return 0 ;
311
+ return true ;
315
312
}
316
313
/* }}} */
317
314
318
- int fpm_stdio_parent_use_pipes (struct fpm_child_s * child ) /* {{{ */
315
+ void fpm_stdio_parent_use_pipes (struct fpm_child_s * child ) /* {{{ */
319
316
{
320
317
if (0 == child -> wp -> config -> catch_workers_output ) { /* not required */
321
- return 0 ;
318
+ return ;
322
319
}
323
320
324
321
close (fd_stdout [1 ]);
@@ -332,22 +329,20 @@ int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */
332
329
333
330
fpm_event_set (& child -> ev_stderr , child -> fd_stderr , FPM_EV_READ , fpm_stdio_child_said , child );
334
331
fpm_event_add (& child -> ev_stderr , 0 );
335
- return 0 ;
336
332
}
337
333
/* }}} */
338
334
339
- int fpm_stdio_discard_pipes (struct fpm_child_s * child ) /* {{{ */
335
+ void fpm_stdio_discard_pipes (struct fpm_child_s * child ) /* {{{ */
340
336
{
341
337
if (0 == child -> wp -> config -> catch_workers_output ) { /* not required */
342
- return 0 ;
338
+ return ;
343
339
}
344
340
345
341
close (fd_stdout [1 ]);
346
342
close (fd_stderr [1 ]);
347
343
348
344
close (fd_stdout [0 ]);
349
345
close (fd_stderr [0 ]);
350
- return 0 ;
351
346
}
352
347
/* }}} */
353
348
@@ -365,7 +360,7 @@ void fpm_stdio_child_use_pipes(struct fpm_child_s *child) /* {{{ */
365
360
}
366
361
/* }}} */
367
362
368
- int fpm_stdio_open_error_log (int reopen ) /* {{{ */
363
+ bool fpm_stdio_open_error_log (bool reopen ) /* {{{ */
369
364
{
370
365
int fd ;
371
366
@@ -376,14 +371,14 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */
376
371
if (fpm_use_error_log ()) {
377
372
zlog_set_fd (fpm_globals .error_log_fd );
378
373
}
379
- return 0 ;
374
+ return true ;
380
375
}
381
376
#endif
382
377
383
378
fd = open (fpm_global_config .error_log , O_WRONLY | O_APPEND | O_CREAT , S_IRUSR | S_IWUSR );
384
379
if (0 > fd ) {
385
380
zlog (ZLOG_SYSERROR , "failed to open error_log (%s)" , fpm_global_config .error_log );
386
- return -1 ;
381
+ return false ;
387
382
}
388
383
389
384
if (reopen ) {
@@ -399,6 +394,6 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */
399
394
if (0 > fcntl (fd , F_SETFD , fcntl (fd , F_GETFD ) | FD_CLOEXEC )) {
400
395
zlog (ZLOG_WARNING , "failed to change attribute of error_log" );
401
396
}
402
- return 0 ;
397
+ return true ;
403
398
}
404
399
/* }}} */
0 commit comments