From 8c811d27cad551babc55188f7d969ffc52c111c7 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Tue, 7 Sep 2021 22:33:12 +0200 Subject: Don't syslog recieved commands with a trailing newline --- mstatus.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mstatus.c b/mstatus.c index f9b341b..83c2a34 100644 --- a/mstatus.c +++ b/mstatus.c @@ -161,12 +161,8 @@ update_bar:; } static bool -process(char *line, ssize_t len, struct Block *b) +process(char *line, struct Block *b) { - /* For some reason output with newlines can cause performance issues */ - if (line[--len] == '\n') - line[len] = '\0'; - if (*line == '-') { b->remove = true; line++; @@ -273,9 +269,14 @@ main(int argc, char **argv) ssize_t nr; while ((nr = getline(&line, &len, fp)) != -1) { + /* For some reason output with newlines can cause performance issues */ + if (line[--nr] == '\n') + line[nr] = '\0'; + syslog(LOG_INFO, "Recieved command '%s'", line); + struct Block b; - if (!process(line, nr, &b)) + if (!process(line, &b)) continue; write_status(b); } -- cgit v1.2.3