2016-07-05 20:58:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/syslog/syslog_chardev.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
|
2016-07-05 20:58:18 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-07-05 20:58:18 +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.
|
2016-07-05 20:58:18 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <errno.h>
|
2023-07-04 11:33:04 +02:00
|
|
|
#include <syslog.h>
|
2016-07-05 20:58:18 +02:00
|
|
|
|
|
|
|
#include <nuttx/fs/fs.h>
|
2023-07-04 11:33:04 +02:00
|
|
|
#include <nuttx/syslog/syslog.h>
|
2016-07-05 20:58:18 +02:00
|
|
|
|
|
|
|
#include "syslog.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYSLOG_CHARDEV
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-10 22:42:43 +02:00
|
|
|
static ssize_t syslog_chardev_write(FAR struct file *filep,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
2023-07-04 11:33:04 +02:00
|
|
|
#ifdef CONFIG_SYSLOG_IOCTL
|
|
|
|
static int syslog_chardev_ioctl(FAR struct file *filep,
|
|
|
|
int cmd, unsigned long arg);
|
|
|
|
#endif
|
2016-07-05 20:58:18 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-04-22 16:43:07 +02:00
|
|
|
static const struct file_operations g_syslog_fops =
|
2016-07-05 20:58:18 +02:00
|
|
|
{
|
2021-03-04 08:02:21 +01:00
|
|
|
NULL, /* open */
|
|
|
|
NULL, /* close */
|
|
|
|
NULL, /* read */
|
2017-05-10 22:42:43 +02:00
|
|
|
syslog_chardev_write, /* write */
|
2023-07-04 11:33:04 +02:00
|
|
|
NULL, /* seek */
|
|
|
|
#ifdef CONFIG_SYSLOG_IOCTL
|
|
|
|
syslog_chardev_ioctl, /* ioctl */
|
|
|
|
#endif
|
2016-07-05 20:58:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-05-10 22:42:43 +02:00
|
|
|
* Name: syslog_chardev_write
|
2016-07-05 20:58:18 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-10 22:42:43 +02:00
|
|
|
static ssize_t syslog_chardev_write(FAR struct file *filep,
|
|
|
|
FAR const char *buffer, size_t len)
|
2016-07-05 20:58:18 +02:00
|
|
|
{
|
2018-11-09 15:49:07 +01:00
|
|
|
syslog(LOG_INFO, "%.*s", (int)len, buffer);
|
|
|
|
return len;
|
2016-07-05 20:58:18 +02:00
|
|
|
}
|
|
|
|
|
2023-07-04 11:33:04 +02:00
|
|
|
#ifdef CONFIG_SYSLOG_IOCTL
|
|
|
|
static int syslog_chardev_ioctl(FAR struct file *filep,
|
|
|
|
int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct syslog_channel_info_s *info;
|
|
|
|
FAR struct syslog_channel_s *channel = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (arg == 0)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd == SYSLOGIOC_GETCHANNELS)
|
|
|
|
{
|
|
|
|
info = (FAR struct syslog_channel_info_s *)arg;
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
|
|
|
|
{
|
|
|
|
channel = g_syslog_channel[i];
|
|
|
|
if (channel == NULL || channel->sc_name[0] == '\0')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
strlcpy(info[i].sc_name, channel->sc_name,
|
|
|
|
sizeof(info[i].sc_name));
|
|
|
|
info[i].sc_disable = channel->sc_disable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd == SYSLOGIOC_SETFILTER)
|
|
|
|
{
|
|
|
|
info = (FAR struct syslog_channel_info_s *)arg;
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
|
|
|
|
{
|
|
|
|
if (strncmp(g_syslog_channel[i]->sc_name, info->sc_name,
|
|
|
|
sizeof(info->sc_name)) == 0)
|
|
|
|
{
|
|
|
|
channel = g_syslog_channel[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel == NULL)
|
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel->sc_disable = info->sc_disable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-05 20:58:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_register
|
|
|
|
*
|
|
|
|
* Description:
|
2021-11-23 08:55:46 +01:00
|
|
|
* Register a simple character driver at /dev/log whose write() method
|
2016-07-05 20:58:18 +02:00
|
|
|
* will transfer data to the SYSLOG device. This can be useful if, for
|
|
|
|
* example, you want to redirect the output of a program to the SYSLOG.
|
|
|
|
*
|
|
|
|
* NOTE that unlike other syslog output, this data is unformatted raw
|
|
|
|
* byte output with no time-stamping or any other SYSLOG features
|
|
|
|
* supported.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void syslog_register(void)
|
|
|
|
{
|
2023-04-22 16:43:07 +02:00
|
|
|
register_driver("/dev/log", &g_syslog_fops, 0222, NULL);
|
2016-07-05 20:58:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SYSLOG_CHARDEV */
|