You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/07/10 18:09:08 UTC
[incubator-nuttx] branch master updated: syslog/intbuf: output log
when syslog interrupt buffer is full
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new c8ce33c syslog/intbuf: output log when syslog interrupt buffer is full
c8ce33c is described below
commit c8ce33c634e748063d2b6f7be495c288ae42e6cd
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Wed Jun 2 16:36:30 2021 +0800
syslog/intbuf: output log when syslog interrupt buffer is full
N/A
instead of adding overrun memssage:"[truncated]\n" to the end.
Change-Id: Ie27cdf0ca902d9ba203619a95162f01222e371c5
Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
drivers/syslog/syslog_intbuffer.c | 88 ++++++++++++---------------------------
1 file changed, 26 insertions(+), 62 deletions(-)
diff --git a/drivers/syslog/syslog_intbuffer.c b/drivers/syslog/syslog_intbuffer.c
index 1f4d07d..878ca06 100644
--- a/drivers/syslog/syslog_intbuffer.c
+++ b/drivers/syslog/syslog_intbuffer.c
@@ -40,27 +40,11 @@
* Pre-processor Definitions
****************************************************************************/
-/* Extend the size of the interrupt buffer so that a "[truncated]\n"
- * indication can be append to the end.
- *
- * The usable capacity of the interrupt buffer is
- * (CONFIG_SYSLOG_INTBUFSIZE - 1).
- */
-
-#define SYSLOG_BUFOVERRUN_MESSAGE "[truncated]\n"
-#define SYSLOG_BUFOVERRUN_SIZE 13
-
-#if CONFIG_SYSLOG_INTBUFSIZE > (65535 - SYSLOG_BUFOVERRUN_SIZE)
+#if CONFIG_SYSLOG_INTBUFSIZE > 65535
# undef CONFIG_SYSLOG_INTBUFSIZE
-# define CONFIG_SYSLOG_INTBUFSIZE (65535 - SYSLOG_BUFOVERRUN_SIZE)
-# define SYSLOG_INTBUFSIZE 65535
-#else
-# define SYSLOG_INTBUFSIZE \
- (CONFIG_SYSLOG_INTBUFSIZE + SYSLOG_BUFOVERRUN_SIZE)
+# define CONFIG_SYSLOG_INTBUFSIZE 65535
#endif
-#define USABLE_INTBUFSIZE (CONFIG_SYSLOG_INTBUFSIZE - 1)
-
/****************************************************************************
* Private Types
****************************************************************************/
@@ -71,7 +55,7 @@ struct g_syslog_intbuffer_s
{
volatile uint16_t si_inndx;
volatile uint16_t si_outndx;
- uint8_t si_buffer[SYSLOG_INTBUFSIZE];
+ uint8_t si_buffer[CONFIG_SYSLOG_INTBUFSIZE];
};
/****************************************************************************
@@ -79,8 +63,6 @@ struct g_syslog_intbuffer_s
****************************************************************************/
static struct g_syslog_intbuffer_s g_syslog_intbuffer;
-static const char g_overrun_msg[SYSLOG_BUFOVERRUN_SIZE] =
- SYSLOG_BUFOVERRUN_MESSAGE;
/****************************************************************************
* Private Data
@@ -129,9 +111,9 @@ int syslog_remove_intbuffer(void)
/* Increment the OUT index, handling wrap-around */
- if (++outndx >= SYSLOG_INTBUFSIZE)
+ if (++outndx >= CONFIG_SYSLOG_INTBUFSIZE)
{
- outndx -= SYSLOG_INTBUFSIZE;
+ outndx -= CONFIG_SYSLOG_INTBUFSIZE;
}
g_syslog_intbuffer.si_outndx = (uint16_t)outndx;
@@ -178,7 +160,7 @@ int syslog_add_intbuffer(int ch)
uint32_t outndx;
uint32_t endndx;
unsigned int inuse;
- int ret;
+ int ret = OK;
int i;
/* Disable concurrent modification from interrupt handling logic */
@@ -193,65 +175,47 @@ int syslog_add_intbuffer(int ch)
endndx = inndx;
if (endndx < outndx)
{
- endndx += SYSLOG_INTBUFSIZE;
+ endndx += CONFIG_SYSLOG_INTBUFSIZE;
}
inuse = (unsigned int)(endndx - outndx);
- /* Is there space for another character (reserving space for the overrun
- * message)?
- */
+ /* Is there space for another character */
- if (inuse == USABLE_INTBUFSIZE)
+ if (inuse == CONFIG_SYSLOG_INTBUFSIZE - 1)
{
- /* Copy the truncated message one character at a time, handing index
- * wrap-around on each character.
- */
-
- for (i = 0; i < SYSLOG_BUFOVERRUN_SIZE; i++)
+ int oldch = syslog_remove_intbuffer();
+ for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
{
- /* Copy one character */
-
- g_syslog_intbuffer.si_buffer[inndx] = (uint8_t)g_overrun_msg[i];
+ if (g_syslog_channel[i] == NULL)
+ {
+ break;
+ }
- /* Increment the IN index, handling wrap-around */
+ /* Select which putc function to use for this flush */
- if (++inndx >= SYSLOG_INTBUFSIZE)
+ if (g_syslog_channel[i]->sc_ops->sc_force)
{
- inndx -= SYSLOG_INTBUFSIZE;
+ g_syslog_channel[i]->sc_ops->sc_force(
+ g_syslog_channel[i], oldch);
}
-
- DEBUGASSERT(inndx != outndx);
}
- g_syslog_intbuffer.si_inndx = (uint16_t)inndx;
- ret = -ENOSPC;
+ ret = -ENOSPC;
}
- else if (inuse < USABLE_INTBUFSIZE)
- {
- /* Copy one character */
- g_syslog_intbuffer.si_buffer[inndx] = (uint8_t)ch;
+ /* Copy one character */
- /* Increment the IN index, handling wrap-around */
+ g_syslog_intbuffer.si_buffer[inndx] = (uint8_t)ch;
- if (++inndx >= SYSLOG_INTBUFSIZE)
- {
- inndx -= SYSLOG_INTBUFSIZE;
- }
+ /* Increment the IN index, handling wrap-around */
- g_syslog_intbuffer.si_inndx = (uint16_t)inndx;
- ret = OK;
- }
- else
+ if (++inndx >= CONFIG_SYSLOG_INTBUFSIZE)
{
- /* This character goes to the bit bucket. We have already copied
- * the overrun message so there is nothing else to do.
- */
-
- ret = -ENOSPC;
+ inndx -= CONFIG_SYSLOG_INTBUFSIZE;
}
+ g_syslog_intbuffer.si_inndx = (uint16_t)inndx;
leave_critical_section(flags);
return ret;
}