summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2015-03-06 12:12:15 +0100
committerKarel Zak <kzak@redhat.com>2015-03-12 10:18:15 +0100
commit48bc4fd2a8535d71b72b01875ec0038c6b331f8b (patch)
treebeff0e7e5ce1709c74711b418d821bae7bbc550d
parentf52c992874e8461b4c121dc8f0573f73b88ddec6 (diff)
downloadutil-linux-48bc4fd2a8535d71b72b01875ec0038c6b331f8b.tar.gz
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);
}