2017-05-10 22:42:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/syslog/syslog_write.c
|
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-05-10 22:42:43 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-05-10 22:42:43 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-05-10 22:42:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2017-05-16 20:26:23 +02:00
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
2017-05-16 18:56:49 +02:00
|
|
|
#include <nuttx/sched.h>
|
2017-05-10 22:42:43 +02:00
|
|
|
#include <nuttx/syslog/syslog.h>
|
|
|
|
|
|
|
|
#include "syslog.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-11-09 15:46:32 +01:00
|
|
|
* Private Functions
|
2017-05-10 22:42:43 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_default_write
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This provides a default write method for syslog devices that do not
|
|
|
|
* support multiple byte writes This functions simply loops, outputting
|
2018-11-09 15:46:32 +01:00
|
|
|
* one character at a time.
|
2017-05-10 22:42:43 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* buffer - The buffer containing the data to be output
|
|
|
|
* buflen - The number of bytes in the buffer
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, the number of characters written is returned. A negated
|
|
|
|
* errno value is returned on any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-09 15:46:32 +01:00
|
|
|
static ssize_t syslog_default_write(FAR const char *buffer, size_t buflen)
|
2017-05-10 22:42:43 +02:00
|
|
|
{
|
2021-03-13 16:37:19 +01:00
|
|
|
size_t nwritten = 0;
|
2023-06-21 02:16:55 +02:00
|
|
|
int i;
|
2017-05-10 22:42:43 +02:00
|
|
|
|
2018-11-09 15:46:32 +01:00
|
|
|
if (up_interrupt_context() || sched_idletask())
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYSLOG_INTBUFFER
|
2023-06-21 02:16:55 +02:00
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
|
|
|
for (nwritten = 0; nwritten < buflen; nwritten++)
|
2018-11-09 15:46:32 +01:00
|
|
|
{
|
2021-05-20 09:10:29 +02:00
|
|
|
syslog_add_intbuffer(buffer[nwritten]);
|
2018-11-09 15:46:32 +01:00
|
|
|
}
|
2023-06-21 02:16:55 +02:00
|
|
|
}
|
|
|
|
else
|
2018-11-09 15:46:32 +01:00
|
|
|
#endif
|
2023-06-21 02:16:55 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
|
2018-11-09 15:46:32 +01:00
|
|
|
{
|
2023-06-21 02:16:55 +02:00
|
|
|
FAR struct syslog_channel_s *channel = g_syslog_channel[i];
|
|
|
|
|
|
|
|
if (channel == NULL)
|
2021-03-13 16:37:19 +01:00
|
|
|
{
|
2023-06-21 02:16:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->sc_ops->sc_write_force != NULL)
|
|
|
|
{
|
|
|
|
nwritten =
|
|
|
|
channel->sc_ops->sc_write_force(channel, buffer, buflen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUGASSERT(channel->sc_ops->sc_force != NULL);
|
|
|
|
for (nwritten = 0; nwritten < buflen; nwritten++)
|
2021-03-13 16:37:19 +01:00
|
|
|
{
|
2023-06-21 02:16:55 +02:00
|
|
|
channel->sc_ops->sc_force(channel, buffer[nwritten]);
|
2021-03-13 16:37:19 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-09 15:46:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-13 16:37:19 +01:00
|
|
|
for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
|
2018-11-09 15:46:32 +01:00
|
|
|
{
|
2023-06-21 02:16:55 +02:00
|
|
|
FAR struct syslog_channel_s *channel = g_syslog_channel[i];
|
|
|
|
|
|
|
|
if (channel == NULL)
|
2021-03-13 16:37:19 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-06-21 02:16:55 +02:00
|
|
|
if (channel->sc_ops->sc_write != NULL)
|
2021-03-13 16:37:19 +01:00
|
|
|
{
|
2023-06-21 02:16:55 +02:00
|
|
|
nwritten = channel->sc_ops->sc_write(channel, buffer, buflen);
|
2021-03-13 16:37:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-21 02:16:55 +02:00
|
|
|
DEBUGASSERT(channel->sc_ops->sc_putc != NULL);
|
2021-03-13 16:37:19 +01:00
|
|
|
for (nwritten = 0; nwritten < buflen; nwritten++)
|
|
|
|
{
|
2023-06-21 02:16:55 +02:00
|
|
|
channel->sc_ops->sc_putc(channel, buffer[nwritten]);
|
2021-03-13 16:37:19 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-09 15:46:32 +01:00
|
|
|
}
|
2017-05-10 22:42:43 +02:00
|
|
|
}
|
|
|
|
|
2020-07-30 04:31:57 +02:00
|
|
|
return nwritten;
|
2017-05-10 22:42:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-09 15:46:32 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-10 22:42:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_write
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the low-level, multiple character, system logging interface.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* buffer - The buffer containing the data to be output
|
|
|
|
* buflen - The number of bytes in the buffer
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, the number of characters written is returned. A negated
|
|
|
|
* errno value is returned on any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
ssize_t syslog_write(FAR const char *buffer, size_t buflen)
|
|
|
|
{
|
2018-11-09 15:46:32 +01:00
|
|
|
#ifdef CONFIG_SYSLOG_INTBUFFER
|
2017-05-16 18:56:49 +02:00
|
|
|
if (!up_interrupt_context() && !sched_idletask())
|
|
|
|
{
|
|
|
|
/* Flush any characters that may have been added to the interrupt
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
|
2021-03-13 16:37:19 +01:00
|
|
|
syslog_flush_intbuffer(false);
|
2017-05-16 18:56:49 +02:00
|
|
|
}
|
|
|
|
#endif
|
2020-07-30 04:33:06 +02:00
|
|
|
|
2018-11-09 15:46:32 +01:00
|
|
|
return syslog_default_write(buffer, buflen);
|
2017-05-10 22:42:43 +02:00
|
|
|
}
|