--- syslogd-busybox-1.1.0/sysklogd/syslogd.c.ori 2021-12-14 16:50:08.004066361 +0100 +++ syslogd-busybox-1.1.0/sysklogd/syslogd.c 2021-12-14 16:50:19.240067568 +0100 @@ -478,6 +478,8 @@ char *timestamp; static char res[20]; int rfc5424 = 0; + int missing_hostname = 0; + int n; #ifdef CONFIG_FEATURE_REMOTE_LOG static char line[MAXLINE + 1]; @@ -504,12 +506,29 @@ time(&now); timestamp = ctime(&now) + 4; timestamp[15] = '\0'; - } else { + /* first rfc3164 header timestamp is missing so we suppose + * the hostname is also missing + */ + missing_hostname = 1; + } + else { timestamp = msg; timestamp[15] = '\0'; msg += 16; + /* rfc3164 timestamp is found + * if first field ending by ':' we consider + * a tag and the hostname is missng + */ + + for (n = 0 ; msg[n] && (msg[n] != '\n') && (msg[n] != ' ') ; n++) { + if (msg[n] == ':') + missing_hostname = 1; + else + missing_hostname = 0; + } } + /* todo: supress duplicates */ #ifdef CONFIG_FEATURE_REMOTE_LOG @@ -522,7 +541,17 @@ /* if we have a valid socket, send the message */ if (-1 != remotefd) { now = 5; /* used as a retry counter */ - snprintf(line, sizeof(line), "<%d>%s", pri, msg); + if (rfc5424) { + /* message is already rfc5424 formatted */ + snprintf(line, sizeof(line), "<%d>%s\n", pri, msg); + } + else if (missing_hostname) { + snprintf(line, sizeof(line), "<%d>%s %s %s\n", pri, timestamp, LocalHostName, msg); + } + else { + snprintf(line, sizeof(line), "<%d>%s %s\n", pri, timestamp, msg); + } + /* send message to remote logger */ while ((now-- > 0) &&