@@ -126,6 +126,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
126
126
struct fpm_event_s * event ;
127
127
int fifo_in = 1 , fifo_out = 1 ;
128
128
int in_buf = 0 ;
129
+ int read_fail = 0 ;
129
130
int res ;
130
131
struct zlog_stream stream ;
131
132
@@ -146,31 +147,16 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
146
147
zlog_stream_set_wrapping (& stream , ZLOG_TRUE );
147
148
zlog_stream_set_msg_prefix (& stream , "[pool %s] child %d said into %s: " ,
148
149
child -> wp -> config -> name , (int ) child -> pid , is_stdout ? "stdout" : "stderr" );
149
- zlog_stream_set_msg_suffix (& stream , NULL , ", pipe is closed" );
150
150
zlog_stream_set_msg_quoting (& stream , ZLOG_TRUE );
151
151
152
152
while (fifo_in || fifo_out ) {
153
153
if (fifo_in ) {
154
154
res = read (fd , buf + in_buf , max_buf_size - 1 - in_buf );
155
155
if (res <= 0 ) { /* no data */
156
156
fifo_in = 0 ;
157
- if (res < 0 && (errno == EAGAIN || errno == EWOULDBLOCK )) {
158
- /* just no more data ready */
159
- } else { /* error or pipe is closed */
160
-
161
- if (res < 0 ) { /* error */
162
- zlog (ZLOG_SYSERROR , "unable to read what child say" );
163
- }
164
-
165
- fpm_event_del (event );
166
-
167
- if (is_stdout ) {
168
- close (child -> fd_stdout );
169
- child -> fd_stdout = -1 ;
170
- } else {
171
- close (child -> fd_stderr );
172
- child -> fd_stderr = -1 ;
173
- }
157
+ if (res == 0 || (errno != EAGAIN && errno != EWOULDBLOCK )) {
158
+ /* pipe is closed or error */
159
+ read_fail = (res < 0 ) ? res : 1 ;
174
160
}
175
161
} else {
176
162
in_buf += res ;
@@ -202,7 +188,26 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
202
188
}
203
189
}
204
190
}
205
- zlog_stream_close (& stream );
191
+
192
+ if (read_fail ) {
193
+ zlog_stream_set_msg_suffix (& stream , NULL , ", pipe is closed" );
194
+ zlog_stream_close (& stream );
195
+ if (read_fail < 0 ) {
196
+ zlog (ZLOG_SYSERROR , "unable to read what child say" );
197
+ }
198
+
199
+ fpm_event_del (event );
200
+
201
+ if (is_stdout ) {
202
+ close (child -> fd_stdout );
203
+ child -> fd_stdout = -1 ;
204
+ } else {
205
+ close (child -> fd_stderr );
206
+ child -> fd_stderr = -1 ;
207
+ }
208
+ } else {
209
+ zlog_stream_close (& stream );
210
+ }
206
211
}
207
212
/* }}} */
208
213
@@ -292,7 +297,7 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */
292
297
293
298
#ifdef HAVE_SYSLOG_H
294
299
if (!strcasecmp (fpm_global_config .error_log , "syslog" )) {
295
- php_openlog (fpm_global_config .syslog_ident , LOG_PID | LOG_CONS , fpm_global_config .syslog_facility );
300
+ openlog (fpm_global_config .syslog_ident , LOG_PID | LOG_CONS , fpm_global_config .syslog_facility );
296
301
fpm_globals .error_log_fd = ZLOG_SYSLOG ;
297
302
if (fpm_use_error_log ()) {
298
303
zlog_set_fd (fpm_globals .error_log_fd );
0 commit comments