@@ -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
@@ -152,6 +152,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
152
152
}
153
153
154
154
while (1 ) {
155
+ stdio_read :
155
156
in_buf = read (fd , buf , max_buf_size - 1 );
156
157
if (in_buf <= 0 ) { /* no data */
157
158
if (in_buf == 0 || (errno != EAGAIN && errno != EWOULDBLOCK )) {
@@ -160,21 +161,33 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
160
161
}
161
162
break ;
162
163
}
163
-
164
- for (start = 0 , pos = 0 ; pos < in_buf ; pos ++ ) {
164
+ start = 0 ;
165
+ if (cmd_pos > 0 ) {
166
+ if (!memcmp (buf , & FPM_STDIO_CMD_FLUSH [cmd_pos ], sizeof (FPM_STDIO_CMD_FLUSH ) - cmd_pos )) {
167
+ zlog_stream_finish (log_stream );
168
+ start = cmd_pos ;
169
+ }
170
+ cmd_pos = 0 ;
171
+ }
172
+ for (pos = 0 ; pos < in_buf ; pos ++ ) {
165
173
switch (buf [pos ]) {
166
174
case '\n' :
167
175
zlog_stream_str (log_stream , buf + start , pos - start );
168
176
zlog_stream_finish (log_stream );
169
177
start = pos + 1 ;
170
178
break ;
171
179
case '\0' :
172
- if (pos + sizeof (FPM_STDIO_CMD_FLUSH ) <= in_buf &&
173
- !memcmp (buf + pos , FPM_STDIO_CMD_FLUSH , sizeof (FPM_STDIO_CMD_FLUSH ))) {
180
+ if (pos + sizeof (FPM_STDIO_CMD_FLUSH ) <= in_buf ) {
181
+ if (!memcmp (buf + pos , FPM_STDIO_CMD_FLUSH , sizeof (FPM_STDIO_CMD_FLUSH ))) {
182
+ zlog_stream_str (log_stream , buf + start , pos - start );
183
+ zlog_stream_finish (log_stream );
184
+ start = pos + sizeof (FPM_STDIO_CMD_FLUSH );
185
+ pos = start - 1 ;
186
+ }
187
+ } else if (!memcmp (buf + pos , FPM_STDIO_CMD_FLUSH , in_buf - pos )) {
188
+ cmd_pos = in_buf - pos ;
174
189
zlog_stream_str (log_stream , buf + start , pos - start );
175
- zlog_stream_finish (log_stream );
176
- start = pos + sizeof (FPM_STDIO_CMD_FLUSH );
177
- pos = start - 1 ;
190
+ goto stdio_read ;
178
191
}
179
192
break ;
180
193
}
0 commit comments