Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/ctr_logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,18 @@ static int write_journald(int pipe, char *buf, ssize_t buflen)
return 0;
}

/* sd_journal_* doesn't have an option to specify the number of bytes to write in the message, and instead writes the
* entire string. Copying every line doesn't make very much sense, so instead we do this tmp_line_end
* hack to emulate separate strings.
*/
char tmp_line_end = buf[line_len];
buf[line_len] = '\0';

ssize_t msg_len = line_len + MESSAGE_EQ_LEN + *partial_buf_len;
partial_buf[*partial_buf_len] = '\0';
_cleanup_free_ char *message = g_strdup_printf("MESSAGE=%s%s", partial_buf, buf);

_cleanup_free_ char *message = g_malloc(msg_len);

memcpy(message, "MESSAGE=", MESSAGE_EQ_LEN);
memcpy(message + MESSAGE_EQ_LEN, partial_buf, *partial_buf_len);
memcpy(message + MESSAGE_EQ_LEN + *partial_buf_len, buf, line_len);

if (writev_buffer_append_segment(dev_null, &bufv, message, msg_len) < 0)
return -1;

/* Restore state of the buffer */
buf[line_len] = tmp_line_end;

if (writev_buffer_append_segment(dev_null, &bufv, container_id_full, cuuid_len + CID_FULL_EQ_LEN) < 0)
return -1;

Expand All @@ -327,7 +323,7 @@ static int write_journald(int pipe, char *buf, ssize_t buflen)

int err = sd_journal_sendv(bufv.iov, bufv.iovcnt);
if (err < 0) {
pwarn(strerror(err));
pwarn(strerror(-err));
return err;
}

Expand Down