log: Fix size calculation for number of iovecs

Each log context field can expand to up to three iovecs (key, value
and newline) so let's fix the size calculation to take this into
account.
This commit is contained in:
Daan De Meyer
2024-07-31 11:39:04 +02:00
parent 7881f485c9
commit fc83ff3f55

View File

@@ -747,7 +747,7 @@ static int write_to_journal(
if (LOG_PRI(level) > log_target_max_level[LOG_TARGET_JOURNAL])
return 0;
iovec_len = MIN(6 + _log_context_num_fields * 2, IOVEC_MAX);
iovec_len = MIN(6 + _log_context_num_fields * 3, IOVEC_MAX);
iovec = newa(struct iovec, iovec_len);
log_do_header(header, sizeof(header), level, error, file, line, func, object_field, object, extra_field, extra);
@@ -1099,7 +1099,7 @@ int log_struct_internal(
int r;
bool fallback = false;
iovec_len = MIN(17 + _log_context_num_fields * 2, IOVEC_MAX);
iovec_len = MIN(17 + _log_context_num_fields * 3, IOVEC_MAX);
iovec = newa(struct iovec, iovec_len);
/* If the journal is available do structured logging.
@@ -1196,7 +1196,7 @@ int log_struct_iovec_internal(
struct iovec *iovec;
size_t n = 0, iovec_len;
iovec_len = MIN(1 + n_input_iovec * 2 + _log_context_num_fields * 2, IOVEC_MAX);
iovec_len = MIN(1 + n_input_iovec * 2 + _log_context_num_fields * 3, IOVEC_MAX);
iovec = newa(struct iovec, iovec_len);
log_do_header(header, sizeof(header), level, error, file, line, func, NULL, NULL, NULL, NULL);