michallenc commented on issue #19173:
URL: https://github.com/apache/nuttx/issues/19173#issuecomment-4742887540

   I think the solution for `lib_syslograwstream.c` is good. We should also fix 
the behavior of `syslog_write_foreach` in `drivers/syslog/syslog_write.c`. We 
return a negated value if `write` fails, but I don't think that is a correct 
behavior if multiple syslog channels are used. We should still log to other 
channels if write to one channel results in error (disconnected USB, faulty NOR 
flash etc...). I would suggest to do something like this in addition to the 
changes proposed by Martin.
   
   ```diff
   diff --git a/drivers/syslog/syslog_write.c b/drivers/syslog/syslog_write.c
   index 8b3fefda70..938c3f9412 100644
   --- a/drivers/syslog/syslog_write.c
   +++ b/drivers/syslog/syslog_write.c
   @@ -107,7 +107,7 @@ ssize_t syslog_write_foreach(FAR const char *buffer,
      syslog_write_t write;
      syslog_putc_t  putc;
      size_t nwritten = 0;
   -  size_t nwritten_max = 0;
   +  ssize_t nwritten_max = -1;
      ssize_t ret;
      int i;
    
   @@ -153,7 +153,7 @@ ssize_t syslog_write_foreach(FAR const char *buffer,
    
                      if (ret < 0)
                        {
   -                      return ret;
   +                      continue;
                        }
    
                      nwritten = head + 1;
   @@ -166,7 +166,7 @@ ssize_t syslog_write_foreach(FAR const char *buffer,
                  ret = write(channel, buffer + nwritten, buflen - nwritten);
                  if (ret < 0)
                    {
   -                  return ret;
   +                  continue;
                    }
                  else
                    {
   ```
   
   This way we skip the faulty channel, but will still attempt to write to the 
other channels. We return -1 if all channels fail or the maximum bytes written 
to one of the channels if at least one worked. The current implementation has 
another issue - we don't provide syslog output at all if the faulty channel is 
the first one.
   
   The issue is easily reproducible if you try to log both to standard serial 
output and to CDC ACM device. Disconnecting USB then leads to 
`syslog_write_foreach` and eventually to an infinite loop in 
`syslograwstream_addstring`.
   
   ping for relevance @acassis @xiaoxiang781216 @linguini1 @cederom @raiden00pl 
@jerpelea 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to