2016-06-19 17:48:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/syslog/syslog_channel.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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-18 20:54:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2016-06-20 15:35:38 +02:00
|
|
|
#include <sys/types.h>
|
2016-06-18 20:54:55 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/syslog/syslog.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_RAMLOG_SYSLOG
|
|
|
|
# include <nuttx/syslog/ramlog.h>
|
|
|
|
#elif defined(CONFIG_ARCH_LOWPUTC)
|
|
|
|
# include <nuttx/arch.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "syslog.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-21 23:08:09 +02:00
|
|
|
#if defined(CONFIG_SYSLOG_SERIAL_CONSOLE) && defined(CONFIG_ARCH_LOWPUTC)
|
|
|
|
# define HAVE_LOWPUTC
|
|
|
|
#elif !defined(CONFIG_RAMLOG_SYSLOG)
|
|
|
|
# define NEED_LOWPUTC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef NEED_LOWPUTC
|
2016-06-18 20:54:55 +02:00
|
|
|
static int syslog_default_putc(int ch);
|
|
|
|
#endif
|
|
|
|
static int syslog_default_flush(void);
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-06-21 20:25:15 +02:00
|
|
|
* Public Data
|
2016-06-18 20:54:55 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_RAMLOG_SYSLOG)
|
2016-06-21 20:25:15 +02:00
|
|
|
const struct syslog_channel_s g_default_channel =
|
2016-06-18 20:54:55 +02:00
|
|
|
{
|
|
|
|
ramlog_putc,
|
|
|
|
ramlog_putc,
|
|
|
|
syslog_default_flush
|
|
|
|
};
|
2016-06-21 23:08:09 +02:00
|
|
|
#elif defined(HAVE_LOWPUTC)
|
2016-06-21 20:25:15 +02:00
|
|
|
const struct syslog_channel_s g_default_channel =
|
2016-06-18 20:54:55 +02:00
|
|
|
{
|
|
|
|
up_putc,
|
|
|
|
up_putc,
|
|
|
|
syslog_default_flush
|
|
|
|
};
|
|
|
|
#else
|
2016-06-21 20:25:15 +02:00
|
|
|
const struct syslog_channel_s g_default_channel =
|
2016-06-18 20:54:55 +02:00
|
|
|
{
|
|
|
|
syslog_default_putc,
|
|
|
|
syslog_default_putc,
|
|
|
|
syslog_default_flush
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This is the current syslog channel in use */
|
|
|
|
|
2016-06-21 01:10:52 +02:00
|
|
|
FAR const struct syslog_channel_s *g_syslog_channel = &g_default_channel;
|
2016-06-18 20:54:55 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-20 15:35:38 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_default_putc and syslog_default_flush
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dummy, no-nothing channel interface methods
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-21 23:08:09 +02:00
|
|
|
#ifdef NEED_LOWPUTC
|
2016-06-18 20:54:55 +02:00
|
|
|
static int syslog_default_putc(int ch)
|
|
|
|
{
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int syslog_default_flush(void)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_channel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the SYSLOGging function to use the provided channel to
|
|
|
|
* generate SYSLOG output.
|
|
|
|
*
|
2016-06-20 15:35:38 +02:00
|
|
|
* Input Parameters:
|
2016-06-18 20:54:55 +02:00
|
|
|
* channel - Provides the interface to the channel to be used.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK)is returned on success. A negated errno value is returned
|
|
|
|
* on any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int syslog_channel(FAR const struct syslog_channel_s *channel)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(channel != NULL);
|
|
|
|
|
|
|
|
if (channel != NULL)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(channel->sc_putc != NULL && channel->sc_force != NULL &&
|
|
|
|
channel->sc_flush != NULL);
|
|
|
|
|
|
|
|
g_syslog_channel = channel;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|