|
Karel Zak |
101ae8 |
From cac75d851c5e6ba1afb3bf55552fd10666a03ea9 Mon Sep 17 00:00:00 2001
|
|
Karel Zak |
101ae8 |
From: Karel Zak <kzak@redhat.com>
|
|
Karel Zak |
101ae8 |
Date: Thu, 21 Oct 2021 18:47:40 +0200
|
|
Karel Zak |
101ae8 |
Subject: logger: fix --size use for stdin
|
|
Karel Zak |
101ae8 |
MIME-Version: 1.0
|
|
Karel Zak |
101ae8 |
Content-Type: text/plain; charset=UTF-8
|
|
Karel Zak |
101ae8 |
Content-Transfer-Encoding: 8bit
|
|
Karel Zak |
101ae8 |
|
|
Karel Zak |
101ae8 |
The stdin version counts log header into the message size, but
|
|
Karel Zak |
101ae8 |
for example when it reads message from argv[] it counts only message
|
|
Karel Zak |
101ae8 |
itself.
|
|
Karel Zak |
101ae8 |
|
|
Karel Zak |
101ae8 |
$ logger --stderr --size 3 "abcd"
|
|
Karel Zak |
101ae8 |
<13>Oct 21 18:48:29 kzak: abc
|
|
Karel Zak |
101ae8 |
|
|
Karel Zak |
101ae8 |
$ echo "abcd" | logger --stderr --size 3
|
|
Karel Zak |
101ae8 |
logger: cannot allocate 18446744073709551597 bytes: Cannot allocate memory
|
|
Karel Zak |
101ae8 |
|
|
Karel Zak |
101ae8 |
Upstream: http://github.com/util-linux/util-linux/commit/58e4ee082bca100034791a4a74481f263bb30a25
|
|
Karel Zak |
101ae8 |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2033622
|
|
Karel Zak |
101ae8 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
Karel Zak |
101ae8 |
---
|
|
Karel Zak |
101ae8 |
misc-utils/logger.c | 9 +++------
|
|
Karel Zak |
101ae8 |
1 file changed, 3 insertions(+), 6 deletions(-)
|
|
Karel Zak |
101ae8 |
|
|
Karel Zak |
101ae8 |
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
|
|
Karel Zak |
101ae8 |
index 5b122de79..43284caeb 100644
|
|
Karel Zak |
101ae8 |
--- a/misc-utils/logger.c
|
|
Karel Zak |
101ae8 |
+++ b/misc-utils/logger.c
|
|
Karel Zak |
101ae8 |
@@ -976,8 +976,7 @@ static void logger_stdin(struct logger_ctl *ctl)
|
|
Karel Zak |
101ae8 |
int has_header = 1;
|
|
Karel Zak |
101ae8 |
int default_priority = ctl->pri;
|
|
Karel Zak |
101ae8 |
int last_pri = default_priority;
|
|
Karel Zak |
101ae8 |
- size_t max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
|
|
Karel Zak |
101ae8 |
- char *const buf = xmalloc(max_usrmsg_size + 2 + 2);
|
|
Karel Zak |
101ae8 |
+ char *buf = xmalloc(ctl->max_message_size + 2 + 2);
|
|
Karel Zak |
101ae8 |
int pri;
|
|
Karel Zak |
101ae8 |
int c;
|
|
Karel Zak |
101ae8 |
size_t i;
|
|
Karel Zak |
101ae8 |
@@ -1004,16 +1003,14 @@ static void logger_stdin(struct logger_ctl *ctl)
|
|
Karel Zak |
101ae8 |
ctl->pri = default_priority;
|
|
Karel Zak |
101ae8 |
|
|
Karel Zak |
101ae8 |
if (ctl->pri != last_pri) {
|
|
Karel Zak |
101ae8 |
- has_header = 0;
|
|
Karel Zak |
101ae8 |
- max_usrmsg_size =
|
|
Karel Zak |
101ae8 |
- ctl->max_message_size - strlen(ctl->hdr);
|
|
Karel Zak |
101ae8 |
+ generate_syslog_header(ctl);
|
|
Karel Zak |
101ae8 |
last_pri = ctl->pri;
|
|
Karel Zak |
101ae8 |
}
|
|
Karel Zak |
101ae8 |
if (c != EOF && c != '\n')
|
|
Karel Zak |
101ae8 |
c = getchar();
|
|
Karel Zak |
101ae8 |
}
|
|
Karel Zak |
101ae8 |
|
|
Karel Zak |
101ae8 |
- while (c != EOF && c != '\n' && i < max_usrmsg_size) {
|
|
Karel Zak |
101ae8 |
+ while (c != EOF && c != '\n' && i < ctl->max_message_size) {
|
|
Karel Zak |
101ae8 |
buf[i++] = c;
|
|
Karel Zak |
101ae8 |
c = getchar();
|
|
Karel Zak |
101ae8 |
}
|
|
Karel Zak |
101ae8 |
--
|
|
Karel Zak |
101ae8 |
2.34.1
|
|
Karel Zak |
101ae8 |
|