From cf1375daf7c5054d6dc965e38cec4c3309ec90ce Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 20 Jun 2016 17:10:52 -0600 Subject: [PATCH] Break syslog_channel.c up into syslog_channel.c, syslog_putc.c, syslog_force.c and syslog_flush.c to limited what is brought into the link. Separate syslog_emergstream.c from syslog_stream.c. Didn't help in the case I was looking at. --- drivers/syslog/Make.defs | 3 +- drivers/syslog/syslog.h | 5 + drivers/syslog/syslog_channel.c | 141 +--------------------------- drivers/syslog/syslog_emergstream.c | 116 +++++++++++++++++++++++ drivers/syslog/syslog_flush.c | 95 +++++++++++++++++++ drivers/syslog/syslog_force.c | 85 +++++++++++++++++ drivers/syslog/syslog_putc.c | 110 ++++++++++++++++++++++ drivers/syslog/syslog_stream.c | 58 ------------ 8 files changed, 418 insertions(+), 195 deletions(-) create mode 100644 drivers/syslog/syslog_emergstream.c create mode 100644 drivers/syslog/syslog_flush.c create mode 100644 drivers/syslog/syslog_force.c create mode 100644 drivers/syslog/syslog_putc.c diff --git a/drivers/syslog/Make.defs b/drivers/syslog/Make.defs index 86d36151b4..f9e54d49a3 100644 --- a/drivers/syslog/Make.defs +++ b/drivers/syslog/Make.defs @@ -37,7 +37,8 @@ ############################################################################ # Include SYSLOG Infrastructure -CSRCS += vsyslog.c syslog_stream.c syslog_channel.c +CSRCS += vsyslog.c syslog_stream.c syslog_emergstream.c syslog_channel.c +CSRCS += syslog_putc.c syslog_force.c syslog_flush.c ifeq ($(CONFIG_SYSLOG_INTBUFFER),y) CSRCS += syslog_intbuffer.c diff --git a/drivers/syslog/syslog.h b/drivers/syslog/syslog.h index 7a90bb3541..5068767ae1 100644 --- a/drivers/syslog/syslog.h +++ b/drivers/syslog/syslog.h @@ -66,6 +66,11 @@ extern "C" #define EXTERN extern #endif +/* This is the current syslog channel in use */ + +struct syslog_channel_s; /* Forward reference */ +FAR const struct syslog_channel_s *g_syslog_channel; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c index fbdde1fdf9..20a0ca7f49 100644 --- a/drivers/syslog/syslog_channel.c +++ b/drivers/syslog/syslog_channel.c @@ -43,7 +43,6 @@ #include #include -#include #include #ifdef CONFIG_RAMLOG_SYSLOG @@ -90,9 +89,13 @@ static const struct syslog_channel_s g_default_channel = }; #endif +/**************************************************************************** + * Public Data + ****************************************************************************/ + /* This is the current syslog channel in use */ -static FAR const struct syslog_channel_s *g_syslog_channel = &g_default_channel; +FAR const struct syslog_channel_s *g_syslog_channel = &g_default_channel; /**************************************************************************** * Private Functions @@ -153,137 +156,3 @@ int syslog_channel(FAR const struct syslog_channel_s *channel) return -EINVAL; } - -/**************************************************************************** - * Name: syslog_putc - * - * Description: - * This is the low-level system logging interface. - * - * Input Parameters: - * ch - The character to add to the SYSLOG (must be positive). - * - * Returned Value: - * On success, the character is echoed back to the caller. A negated - * errno value is returned on any failure. - * - ****************************************************************************/ - -int syslog_putc(int ch) -{ - DEBUGASSERT(g_syslog_channel != NULL); - - /* Is this an attempt to do SYSLOG output from an interrupt handler? */ - - if (up_interrupt_context() || sched_idletask()) - { -#if defined(CONFIG_SYSLOG_INTBUFFER) - /* Buffer the character in the interrupt buffer. The interrupt buffer - * will be flushed before the next normal, non-interrupt SYSLOG output. - */ - - return syslog_add_intbuffer(ch); -#else - /* Force the character to the SYSLOG device immediately (if possible). - * This means that the interrupt data may not be in synchronization - * with output data that may have been buffered by sc_putc(). - */ - - DEBUGASSERT(g_syslog_channel->sc_force != NULL); - - return g_syslog_channel->sc_force(ch); -#endif - } - else - { - DEBUGASSERT(g_syslog_channel->sc_putc != NULL); - -#ifdef CONFIG_SYSLOG_INTBUFFER - /* Flush any characters that may have been added to the interrupt - * buffer. - */ - - (void)syslog_flush_intbuffer(g_syslog_channel, false); -#endif - - return g_syslog_channel->sc_putc(ch); - } -} - -/**************************************************************************** - * Name: syslog_force - * - * Description: - * This is the low-level system logging interface. This version forces - * the output and is only used in emergency situations (e.g., in assertion - * handling). - * - * Input Parameters: - * ch - The character to add to the SYSLOG (must be positive). - * - * Returned Value: - * On success, the character is echoed back to the caller. A negated - * errno value is returned on any failure. - * - ****************************************************************************/ - -int syslog_force(int ch) -{ - DEBUGASSERT(g_syslog_channel != NULL && g_syslog_channel->sc_force != NULL); - -#ifdef CONFIG_SYSLOG_INTBUFFER - /* Flush any characters that may have been added to the interrupt - * buffer through the emergency channel - */ - - (void)syslog_flush_intbuffer(g_syslog_channel, true); -#endif - - /* Then send the character to the emergency channel */ - - return g_syslog_channel->sc_force(ch); -} - -/**************************************************************************** - * Name: syslog_flush - * - * Description: - * This is called by system crash-handling logic. It must flush any - * buffered data to the SYSLOG device. - * - * Interrupts are disabled at the time of the crash and this logic must - * perform the flush using low-level, non-interrupt driven logic. - * - * Input Parameters: - * ch - The character to add to the SYSLOG (must be positive). - * - * Returned Value: - * Zero (OK)is returned on success. A negated errno value is returned - * on any failure. - * - ****************************************************************************/ - -#if 0 -/* REVISIT: (1) Not yet integrated into assertion handlers and (2) there is - * an implementation problem in that if a character driver is the underlying - * device, then there is no mechanism to flush the data buffered in the - * driver with interrupts disabled. - */ - -int syslog_flush(void) -{ - DEBUGASSERT(g_syslog_channel != NULL && g_syslog_channel->sc_flush != NULL); - -#ifdef CONFIG_SYSLOG_INTBUFFER - /* Flush any characters that may have been added to the interrupt - * buffer. - */ - - (void)syslog_flush_intbuffer(g_syslog_channel, true); -#endif - - /* Then flush all of the buffered output to the SYSLOG device */ - - return g_syslog_channel->sc_flush(); -} -#endif diff --git a/drivers/syslog/syslog_emergstream.c b/drivers/syslog/syslog_emergstream.c new file mode 100644 index 0000000000..e0cc2be6ed --- /dev/null +++ b/drivers/syslog/syslog_emergstream.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * drivers/syslog/syslog_emergtream.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "syslog.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: emergstream_putc + ****************************************************************************/ + +static void emergstream_putc(FAR struct lib_outstream_s *this, int ch) +{ + int ret; + + /* Try writing until the write was successful or until an irrecoverable + * error occurs. + */ + + do + { + /* Write the character to the supported logging device. On failure, + * syslog_putc returns EOF with the errno value set; + */ + + ret = syslog_force(ch); + if (ret != EOF) + { + this->nput++; + return; + } + + /* The special errno value -EINTR means that syslog_putc() was + * awakened by a signal. This is not a real error and must be + * ignored in this context. + */ + } + while (errno == -EINTR); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: emergstream + * + * Description: + * Initializes a stream for use with the configured emergency syslog + * interface. Only accessible from with the OS SYSLOG logic. + * + * Input parameters: + * stream - User allocated, uninitialized instance of struct + * lib_lowoutstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void emergstream(FAR struct lib_outstream_s *stream) +{ + stream->put = emergstream_putc; +#ifdef CONFIG_STDIO_LINEBUFFER + stream->flush = lib_noflush; +#endif + stream->nput = 0; +} diff --git a/drivers/syslog/syslog_flush.c b/drivers/syslog/syslog_flush.c new file mode 100644 index 0000000000..bd30c8a506 --- /dev/null +++ b/drivers/syslog/syslog_flush.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * drivers/syslog/syslog_flush.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "syslog.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: syslog_flush + * + * Description: + * This is called by system crash-handling logic. It must flush any + * buffered data to the SYSLOG device. + * + * Interrupts are disabled at the time of the crash and this logic must + * perform the flush using low-level, non-interrupt driven logic. + * + * Input Parameters: + * ch - The character to add to the SYSLOG (must be positive). + * + * Returned Value: + * Zero (OK)is returned on success. A negated errno value is returned + * on any failure. + * + ****************************************************************************/ + +#if 0 +/* REVISIT: (1) Not yet integrated into assertion handlers and (2) there is + * an implementation problem in that if a character driver is the underlying + * device, then there is no mechanism to flush the data buffered in the + * driver with interrupts disabled. + */ + +int syslog_flush(void) +{ + DEBUGASSERT(g_syslog_channel != NULL && g_syslog_channel->sc_flush != NULL); + +#ifdef CONFIG_SYSLOG_INTBUFFER + /* Flush any characters that may have been added to the interrupt + * buffer. + */ + + (void)syslog_flush_intbuffer(g_syslog_channel, true); +#endif + + /* Then flush all of the buffered output to the SYSLOG device */ + + return g_syslog_channel->sc_flush(); +} +#endif diff --git a/drivers/syslog/syslog_force.c b/drivers/syslog/syslog_force.c new file mode 100644 index 0000000000..aebc6a6ced --- /dev/null +++ b/drivers/syslog/syslog_force.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * drivers/syslog/syslog_force.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "syslog.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: syslog_force + * + * Description: + * This is the low-level system logging interface. This version forces + * the output and is only used in emergency situations (e.g., in assertion + * handling). + * + * Input Parameters: + * ch - The character to add to the SYSLOG (must be positive). + * + * Returned Value: + * On success, the character is echoed back to the caller. A negated + * errno value is returned on any failure. + * + ****************************************************************************/ + +int syslog_force(int ch) +{ + DEBUGASSERT(g_syslog_channel != NULL && g_syslog_channel->sc_force != NULL); + +#ifdef CONFIG_SYSLOG_INTBUFFER + /* Flush any characters that may have been added to the interrupt + * buffer through the emergency channel + */ + + (void)syslog_flush_intbuffer(g_syslog_channel, true); +#endif + + /* Then send the character to the emergency channel */ + + return g_syslog_channel->sc_force(ch); +} diff --git a/drivers/syslog/syslog_putc.c b/drivers/syslog/syslog_putc.c new file mode 100644 index 0000000000..3f19b6c005 --- /dev/null +++ b/drivers/syslog/syslog_putc.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * drivers/syslog/syslog_putc.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "syslog.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: syslog_putc + * + * Description: + * This is the low-level system logging interface. + * + * Input Parameters: + * ch - The character to add to the SYSLOG (must be positive). + * + * Returned Value: + * On success, the character is echoed back to the caller. A negated + * errno value is returned on any failure. + * + ****************************************************************************/ + +int syslog_putc(int ch) +{ + DEBUGASSERT(g_syslog_channel != NULL); + + /* Is this an attempt to do SYSLOG output from an interrupt handler? */ + + if (up_interrupt_context() || sched_idletask()) + { +#if defined(CONFIG_SYSLOG_INTBUFFER) + /* Buffer the character in the interrupt buffer. The interrupt buffer + * will be flushed before the next normal, non-interrupt SYSLOG output. + */ + + return syslog_add_intbuffer(ch); +#else + /* Force the character to the SYSLOG device immediately (if possible). + * This means that the interrupt data may not be in synchronization + * with output data that may have been buffered by sc_putc(). + */ + + DEBUGASSERT(g_syslog_channel->sc_force != NULL); + + return g_syslog_channel->sc_force(ch); +#endif + } + else + { + DEBUGASSERT(g_syslog_channel->sc_putc != NULL); + +#ifdef CONFIG_SYSLOG_INTBUFFER + /* Flush any characters that may have been added to the interrupt + * buffer. + */ + + (void)syslog_flush_intbuffer(g_syslog_channel, false); +#endif + + return g_syslog_channel->sc_putc(ch); + } +} diff --git a/drivers/syslog/syslog_stream.c b/drivers/syslog/syslog_stream.c index ecb68d256b..491da95c26 100644 --- a/drivers/syslog/syslog_stream.c +++ b/drivers/syslog/syslog_stream.c @@ -86,39 +86,6 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) while (errno == -EINTR); } -/**************************************************************************** - * Name: emergstream_putc - ****************************************************************************/ - -static void emergstream_putc(FAR struct lib_outstream_s *this, int ch) -{ - int ret; - - /* Try writing until the write was successful or until an irrecoverable - * error occurs. - */ - - do - { - /* Write the character to the supported logging device. On failure, - * syslog_putc returns EOF with the errno value set; - */ - - ret = syslog_force(ch); - if (ret != EOF) - { - this->nput++; - return; - } - - /* The special errno value -EINTR means that syslog_putc() was - * awakened by a signal. This is not a real error and must be - * ignored in this context. - */ - } - while (errno == -EINTR); -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -147,28 +114,3 @@ void syslogstream(FAR struct lib_outstream_s *stream) #endif stream->nput = 0; } - -/**************************************************************************** - * Name: emergstream - * - * Description: - * Initializes a stream for use with the configured emergency syslog - * interface. Only accessible from with the OS SYSLOG logic. - * - * Input parameters: - * stream - User allocated, uninitialized instance of struct - * lib_lowoutstream_s to be initialized. - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void emergstream(FAR struct lib_outstream_s *stream) -{ - stream->put = emergstream_putc; -#ifdef CONFIG_STDIO_LINEBUFFER - stream->flush = lib_noflush; -#endif - stream->nput = 0; -}