]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: add hostname to rfc3164 message
authorSami Kerola <kerolasa@iki.fi>
Sun, 27 Jul 2014 17:33:22 +0000 (18:33 +0100)
committerSami Kerola <kerolasa@iki.fi>
Mon, 28 Jul 2014 20:15:18 +0000 (21:15 +0100)
This makes the obsolete protocol a little bit more compliant with the
internet standard, but few should care now when we have rfc5424 support,
and rfc3164 feels broken.  For example it requires hostname to be not
fully qualified, which is hard to understand, and should make users to
prefer the new protocol.

Reported-by: Frank Thilo <thilo@unix-ag.org>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=705217
CC: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/logger.c

index ac583fd1044a5b8a7af4f6d27b44135b9e34605f..9da404d26e5fe25b85f908e6868b4e10a0d997da 100644 (file)
@@ -298,7 +298,7 @@ static pid_t get_process_id(struct logger_ctl *ctl)
 
 static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
 {
-       char buf[1000], pid[30], *cp, *tp;
+       char buf[1000], pid[30], *cp, *tp, *hostname, *dot;
        time_t now;
        pid_t process;
 
@@ -312,10 +312,15 @@ static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
                cp = ctl->tag;
        else
                cp = xgetlogin();
+       hostname = xgethostname();
+       dot = strchr(hostname, '.');
+       if (dot)
+               *dot = '\0';
        time(&now);
        tp = ctime(&now) + 4;
-       snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
-                ctl->pri, tp, cp, pid, msg);
+       snprintf(buf, sizeof(buf), "<%d>%.15s %s %.200s%s: %.400s",
+                ctl->pri, tp, hostname, cp, pid, msg);
+       free(hostname);
        if (write_all(ctl->fd, buf, strlen(buf) + 1) < 0)
                warn(_("write failed"));
        if (ctl->logflags & LOG_PERROR)