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
|
|
|
int i;
|
|
|
|
size_t nwritten = 0;
|
2017-05-10 22:42:43 +02:00
|
|
|
|
2018-11-09 15:46:32 +01:00
|
|
|
if (up_interrupt_context() || sched_idletask())
|
|
|
|
{
|
|
|
|
for (nwritten = 0; nwritten < buflen; nwritten++)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYSLOG_INTBUFFER
|
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
2021-05-20 09:10:29 +02:00
|
|
|
syslog_add_intbuffer(buffer[nwritten]);
|
2018-11-09 15:46:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2021-03-13 16:37:19 +01:00
|
|
|
for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
|
|
|
|
{
|
|
|
|
if (g_syslog_channel[i] == NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
DEBUGASSERT(g_syslog_channel[i]->sc_ops->sc_force != NULL);
|
|
|
|
g_syslog_channel[i]->sc_ops->sc_force(g_syslog_channel[i],
|
2021-05-20 09:10:29 +02:00
|
|
|
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
|
|
|
{
|
2021-03-13 16:37:19 +01:00
|
|
|
if (g_syslog_channel[i] == NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
if (g_syslog_channel[i]->sc_ops->sc_write)
|
2021-03-13 16:37:19 +01:00
|
|
|
{
|
2021-03-29 14:36:58 +02:00
|
|
|
nwritten =
|
|
|
|
g_syslog_channel[i]->sc_ops->sc_write(g_syslog_channel[i],
|
|
|
|
buffer, buflen);
|
2021-03-13 16:37:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-29 14:36:58 +02:00
|
|
|
DEBUGASSERT(g_syslog_channel[i]->sc_ops->sc_putc != NULL);
|
2021-03-13 16:37:19 +01:00
|
|
|
|
|
|
|
for (nwritten = 0; nwritten < buflen; nwritten++)
|
|
|
|
{
|
2021-03-29 14:36:58 +02:00
|
|
|
g_syslog_channel[i]->sc_ops->sc_putc(g_syslog_channel[i],
|
2021-05-20 09:10:29 +02:00
|
|
|
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
|
|
|
}
|