summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards2015-03-06 12:12:15 +0100
committerRainer Gerhards2015-03-06 12:12:15 +0100
commit940a14a3515a0d8cddb338605e788315565fd6cc (patch)
tree9e98dba84132b0b84755f91d7ee973f626f59784
parentlogger: refactor the way output is written (diff)
downloadkernel-qcow2-util-linux-940a14a3515a0d8cddb338605e788315565fd6cc.tar.gz
kernel-qcow2-util-linux-940a14a3515a0d8cddb338605e788315565fd6cc.tar.xz
kernel-qcow2-util-linux-940a14a3515a0d8cddb338605e788315565fd6cc.zip
logger: bugfix: tcp syslog framing is broken, -T unusable
Logger can send via plain tcp syslog if -n -T options are given. However, the framing is broken so that a syslog receiver can not know where the first message ends and the next one starts. It actually looks like no framing at all is used. Plain TCP syslog framing is described in RFC6587. This patch adds RFC6587 octet-stuffed framing to TCP syslog. For local logging, this is always fine, for remote logging this is NOT recommended by the IETF (the RFC is historic). However, a full blown RFC5425 TLS sender seems to be out of scope for a tool like logger IMO. This patch also refactors the way output is written, seperating the message format generators from the output writer.
-rw-r--r--misc-utils/logger.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 6869f44d7..e19ef0590 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -332,11 +332,26 @@ rfc3164_current_time(void)
return time;
}
+/* writes generated buffer to desired destination. For TCP syslog,
+ * we use RFC6587 octet-stuffing. This is not great, but doing
+ * full blown RFC5425 (TLS) looks like it is too much for the
+ * logger utility.
+ */
static void write_output(const struct logger_ctl *ctl, const char *const buf,
const size_t len)
{
if (write_all(ctl->fd, buf, len) < 0)
warn(_("write failed"));
+ else
+ if (ctl->socket_type == TYPE_TCP)
+ /* using an additional write seems like the best compromise:
+ * - writev() is not yet supported by framework
+ * - adding the \n to the buffer in formatters violates layers
+ * - adding \n after the fact requires memory copy
+ * - logger is not a high-performance app
+ */
+ if (write_all(ctl->fd, "\n", 1) < 0)
+ warn(_("write failed"));
if (ctl->stderr_printout)
fprintf(stderr, "%s\n", buf);
}