mirror of
https://github.com/pygos/init.git
synced 2024-11-22 11:19:45 +01:00
Normalize syslog message line endings
Most syslog messages have a line feed at the end, but some don't. This patch removes trailing spaces from all syslog messages that have one and always adds a line feed in the logging back end. Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
parent
73404a09d4
commit
532f5e6819
2 changed files with 8 additions and 2 deletions
|
@ -151,10 +151,10 @@ static int logfile_write(logfile_t *file, const syslog_msg_t *msg)
|
|||
if (fac_name == NULL)
|
||||
return -1;
|
||||
|
||||
ret = dprintf(file->fd, "[%s][%s][%s][%u] %s", timebuf,
|
||||
ret = dprintf(file->fd, "[%s][%s][%s][%u] %s\n", timebuf,
|
||||
fac_name, lvl_str, msg->pid, msg->message);
|
||||
} else {
|
||||
ret = dprintf(file->fd, "[%s][%s][%u] %s", timebuf, lvl_str,
|
||||
ret = dprintf(file->fd, "[%s][%s][%u] %s\n", timebuf, lvl_str,
|
||||
msg->pid, msg->message);
|
||||
}
|
||||
|
||||
|
|
|
@ -132,6 +132,7 @@ int syslog_msg_parse(syslog_msg_t *msg, char *str)
|
|||
struct tm tstamp;
|
||||
pid_t pid = 0;
|
||||
int priority;
|
||||
size_t len;
|
||||
|
||||
memset(msg, 0, sizeof(*msg));
|
||||
|
||||
|
@ -177,6 +178,11 @@ int syslog_msg_parse(syslog_msg_t *msg, char *str)
|
|||
msg->ident = ident;
|
||||
msg->message = str;
|
||||
|
||||
len = strlen(str);
|
||||
while (len > 0 && isspace(str[len - 1]))
|
||||
--len;
|
||||
str[len] = '\0';
|
||||
|
||||
if (ident != NULL) {
|
||||
for (ptr = ident; *ptr != '\0'; ++ptr) {
|
||||
if (!isalnum(*ptr))
|
||||
|
|
Loading…
Reference in a new issue