Skip to content

Commit 0304eec

Browse files
committed
Fix some issues with zlog stream unbuffered write
1 parent a26eb25 commit 0304eec

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

sapi/fpm/fpm/zlog.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ static inline ssize_t zlog_stream_unbuffered_write(struct zlog_stream *stream, c
323323
{
324324
int finished = 0;
325325
const char *append;
326-
size_t append_len;
326+
size_t append_len = 0;
327+
ssize_t written;
327328

328329
if (stream->len + len >= zlog_limit) {
329330
if (stream->wrap) {
@@ -347,15 +348,27 @@ static inline ssize_t zlog_stream_unbuffered_write(struct zlog_stream *stream, c
347348
zlog_stream_direct_write_ex(stream, buf, len, append, append_len);
348349
}
349350
/* TODO: use loop to speed it up */
350-
return len + zlog_stream_unbuffered_write(stream, buf + len, len);
351+
written = zlog_stream_unbuffered_write(stream, buf + len, len);
352+
if (written > 0) {
353+
return len + written;
354+
}
355+
356+
return written;
351357
}
352358
stream->finished = finished = 1;
353359
append = (stream->len + len == zlog_limit) ? "\n" : "...\n";
354360
append_len = sizeof(append) - 1;
355361
len = zlog_limit - stream->len - append_len;
356362
}
357363

358-
return zlog_stream_direct_write_ex(stream, buf, len, append, append_len);
364+
written = zlog_stream_direct_write_ex(stream, buf, len, append, append_len);
365+
if (written > 0) {
366+
/* currently written will be always len as the write is blocking
367+
* - this should be address if we change to non-blocking write */
368+
stream->len += written;
369+
}
370+
371+
return written;
359372
}
360373
/* }}} */
361374

@@ -460,10 +473,11 @@ ssize_t zlog_stream_set_wrapping_prefix(struct zlog_stream *stream, const char *
460473
va_end(args);
461474

462475
stream->wrap_prefix = malloc(len);
463-
if (stream->wrap_prefix != NULL) {
476+
if (stream->wrap_prefix == NULL) {
464477
return -1;
465478
}
466479
memcpy(stream->wrap_prefix, buf, len);
480+
stream->wrap_prefix_len = len;
467481

468482
return len;
469483
}

0 commit comments

Comments
 (0)