in_tail: skip null characters from the head
@@ -65,7 +65,8 @@ static int unpack_and_pack(msgpack_packer *pck, msgpack_object *root,
if (val != NULL) {
msgpack_pack_str(pck, val_len);
msgpack_pack_str_body(pck, val, val_len);
- } else {
+ }
+ else {
msgpack_pack_uint64(pck, val_uint64);
}
@@ -201,6 +202,7 @@ int flb_tail_file_pack_line(msgpack_sbuffer *mp_sbuf, msgpack_packer *mp_pck,
static int process_content(struct flb_tail_file *file, size_t *bytes)
{
size_t len;
+ int has_data = FLB_FALSE;
int lines = 0;
int ret;
size_t processed_bytes = 0;
@@ -231,9 +233,15 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
/* Parse the data content */
data = file->buf_data;
end = data + file->buf_len;
- while ((p = memchr(data, '\n', end - data))) {
- len = (p - data);
+ /* Skip null characters from the head (sometimes introduced by copy-truncate log rotation) */
+ while (data < end && *data == '\0') {
+ ++data;
+ }
+
+ while (data < end && (p = memchr(data, '\n', end - data))) {
+ has_data = FLB_TRUE;
+ len = (p - data);
if (file->skip_next == FLB_TRUE) {
data += len + 1;
processed_bytes += len;
@@ -352,14 +360,19 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
lines++;
}
file->parsed = file->buf_len;
- *bytes = processed_bytes;
+ if (has_data) {
/* Append buffer content to a chunk */
+ *bytes = processed_bytes;
flb_input_chunk_append_raw(ctx->ins,
file->tag_buf,
file->tag_len,
out_sbuf->data,
out_sbuf->size);
+ }
+ else {
+ *bytes = file->buf_len;
+ }
msgpack_sbuffer_destroy(out_sbuf);
return lines;
