@@ -122,7 +122,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
122
122
struct fpm_child_s * child ;
123
123
int is_stdout ;
124
124
struct fpm_event_s * event ;
125
- int in_buf = 0 , pos , start ;
125
+ int in_buf = 0 , cmd_pos = 0 , pos , start ;
126
126
int read_fail = 0 , create_log_stream ;
127
127
struct zlog_stream * log_stream ;
128
128
@@ -163,6 +163,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
163
163
}
164
164
165
165
while (1 ) {
166
+ stdio_read :
166
167
in_buf = read (fd , buf , max_buf_size - 1 );
167
168
if (in_buf <= 0 ) { /* no data */
168
169
if (in_buf == 0 || (errno != EAGAIN && errno != EWOULDBLOCK )) {
@@ -171,21 +172,33 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
171
172
}
172
173
break ;
173
174
}
174
-
175
- for (start = 0 , pos = 0 ; pos < in_buf ; pos ++ ) {
175
+ start = 0 ;
176
+ if (cmd_pos > 0 ) {
177
+ if (!memcmp (buf , & FPM_STDIO_CMD_FLUSH [cmd_pos ], sizeof (FPM_STDIO_CMD_FLUSH ) - cmd_pos )) {
178
+ zlog_stream_finish (log_stream );
179
+ start = cmd_pos ;
180
+ }
181
+ cmd_pos = 0 ;
182
+ }
183
+ for (pos = 0 ; pos < in_buf ; pos ++ ) {
176
184
switch (buf [pos ]) {
177
185
case '\n' :
178
186
zlog_stream_str (log_stream , buf + start , pos - start );
179
187
zlog_stream_finish (log_stream );
180
188
start = pos + 1 ;
181
189
break ;
182
190
case '\0' :
183
- if (pos + sizeof (FPM_STDIO_CMD_FLUSH ) <= in_buf &&
184
- !memcmp (buf + pos , FPM_STDIO_CMD_FLUSH , sizeof (FPM_STDIO_CMD_FLUSH ))) {
191
+ if (pos + sizeof (FPM_STDIO_CMD_FLUSH ) <= in_buf ) {
192
+ if (!memcmp (buf + pos , FPM_STDIO_CMD_FLUSH , sizeof (FPM_STDIO_CMD_FLUSH ))) {
193
+ zlog_stream_str (log_stream , buf + start , pos - start );
194
+ zlog_stream_finish (log_stream );
195
+ start = pos + sizeof (FPM_STDIO_CMD_FLUSH );
196
+ pos = start - 1 ;
197
+ }
198
+ } else if (!memcmp (buf + pos , FPM_STDIO_CMD_FLUSH , in_buf - pos )) {
199
+ cmd_pos = in_buf - pos ;
185
200
zlog_stream_str (log_stream , buf + start , pos - start );
186
- zlog_stream_finish (log_stream );
187
- start = pos + sizeof (FPM_STDIO_CMD_FLUSH );
188
- pos = start - 1 ;
201
+ goto stdio_read ;
189
202
}
190
203
break ;
191
204
}
0 commit comments