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.
This commit is contained in:
parent
645603e6d1
commit
cf1375daf7
@ -37,7 +37,8 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
# Include SYSLOG Infrastructure
|
# 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)
|
ifeq ($(CONFIG_SYSLOG_INTBUFFER),y)
|
||||||
CSRCS += syslog_intbuffer.c
|
CSRCS += syslog_intbuffer.c
|
||||||
|
@ -66,6 +66,11 @@ extern "C"
|
|||||||
#define EXTERN extern
|
#define EXTERN extern
|
||||||
#endif
|
#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
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/sched.h>
|
|
||||||
#include <nuttx/syslog/syslog.h>
|
#include <nuttx/syslog/syslog.h>
|
||||||
|
|
||||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||||
@ -90,9 +89,13 @@ static const struct syslog_channel_s g_default_channel =
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
/* This is the current syslog channel in use */
|
/* 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
|
* Private Functions
|
||||||
@ -153,137 +156,3 @@ int syslog_channel(FAR const struct syslog_channel_s *channel)
|
|||||||
|
|
||||||
return -EINVAL;
|
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
|
|
||||||
|
116
drivers/syslog/syslog_emergstream.c
Normal file
116
drivers/syslog/syslog_emergstream.c
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* drivers/syslog/syslog_emergtream.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/syslog/syslog.h>
|
||||||
|
#include <nuttx/streams.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
95
drivers/syslog/syslog_flush.c
Normal file
95
drivers/syslog/syslog_flush.c
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* drivers/syslog/syslog_flush.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <nuttx/syslog/syslog.h>
|
||||||
|
|
||||||
|
#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
|
85
drivers/syslog/syslog_force.c
Normal file
85
drivers/syslog/syslog_force.c
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* drivers/syslog/syslog_force.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <nuttx/syslog/syslog.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
110
drivers/syslog/syslog_putc.c
Normal file
110
drivers/syslog/syslog_putc.c
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* drivers/syslog/syslog_putc.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/sched.h>
|
||||||
|
#include <nuttx/syslog/syslog.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
@ -86,39 +86,6 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
|
|||||||
while (errno == -EINTR);
|
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
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -147,28 +114,3 @@ void syslogstream(FAR struct lib_outstream_s *stream)
|
|||||||
#endif
|
#endif
|
||||||
stream->nput = 0;
|
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;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user