Merge pull request #415 from DrDoof/fix/syslog-ring-overrun

syslog: stop the log ring from lapping its reader
This commit is contained in:
feelfree69 authored and GitHub committed 2026-09-22 18:54:51 +02:00
commit 7e6577a811
1 file changed
+13 -2
+13 -2
View File
@@ -254,8 +254,19 @@ void write_char(char c)
write_char_no_syslog(c); write_char_no_syslog(c);
if (syslog_state.enabled) { if (syslog_state.enabled) {
logbuf[syslog_state.writeptr++] = c; __xdata uint16_t next = (syslog_state.writeptr + 1) & (LOGBUF_SIZE - 1);
syslog_state.writeptr &= (LOGBUF_SIZE - 1);
/* The ring is drained once per main loop pass, and a single command
* can print several times its size, so writing on regardless laps
* the reader and the datagram starts mid record. Drop instead, and
* flag a line so the reader empties what is there even if no
* newline has been seen yet. */
if (next == syslog_state.readptr) {
syslog_state.line_available = 1;
return;
}
logbuf[syslog_state.writeptr] = c;
syslog_state.writeptr = next;
if (c == '\n') if (c == '\n')
syslog_state.line_available = 1; syslog_state.line_available = 1;
} }