This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3a718caaf43df3aabbf6e3fcfcd3395452d61ca2 Author: Bowen Wang <[email protected]> AuthorDate: Thu Jul 2 22:09:41 2026 +0800 drivers/syslog: fix syslog write busy loop when a channel is full syslog_write_foreach() treated a zero-length channel write the same as a successful one. When a channel buffer is full its sc_write() returns 0, but the old code still emitted the trailing CR/LF and advanced nwritten past data that was never stored; in the tail path it counted the blocked channel as having written 0 bytes and let it update nwritten_max. With every channel full the function returned 0, which the caller interprets as "no progress" and retries, spinning the CPU. Treat a 0 return the same as a write error. In the CRLF path skip the CR/LF emission and leave nwritten untouched; in the tail path continue to the next channel. A fully blocked channel no longer contributes to nwritten_max, so syslog_write_foreach() returns the initial negative error instead of 0 and the caller stops retrying. Signed-off-by: Bowen Wang <[email protected]> --- drivers/syslog/syslog_write.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/syslog/syslog_write.c b/drivers/syslog/syslog_write.c index 8a86e2074e1..33f597c46c0 100644 --- a/drivers/syslog/syslog_write.c +++ b/drivers/syslog/syslog_write.c @@ -188,16 +188,12 @@ ssize_t syslog_write_foreach(int priority, FAR const char *buffer, } ret = write(channel, buffer + nwritten, head - nwritten); - if (ret >= 0) - { - ret = write(channel, "\r\n", 2); - } - - if (ret < 0) + if (ret <= 0) { continue; } + ret = write(channel, "\r\n", 2); nwritten = head + 1; } } @@ -206,14 +202,12 @@ ssize_t syslog_write_foreach(int priority, FAR const char *buffer, if (nwritten < buflen) { ret = write(channel, buffer + nwritten, buflen - nwritten); - if (ret < 0) + if (ret <= 0) { continue; } - else - { - nwritten += ret; - } + + nwritten += ret; } } else
