2016-06-20 03:59:43 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/syslog/syslog_devchannel.c
|
|
|
|
*
|
2021-04-02 18:39:20 +08: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-06-20 03:59:43 +08:00
|
|
|
*
|
2021-04-02 18:39:20 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-20 03:59:43 +08:00
|
|
|
*
|
2021-04-02 18:39:20 +08: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-06-20 03:59:43 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2016-06-22 02:25:15 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2021-03-29 20:36:58 +08:00
|
|
|
#include <errno.h>
|
2016-06-22 02:25:15 +08:00
|
|
|
|
2016-06-20 03:59:43 +08:00
|
|
|
#include <nuttx/syslog/syslog.h>
|
|
|
|
|
|
|
|
#include "syslog.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYSLOG_CHAR
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-06-22 02:25:15 +08:00
|
|
|
* Pre-processor Definitions
|
2016-06-20 03:59:43 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-22 02:25:15 +08:00
|
|
|
#define OPEN_FLAGS (O_WRONLY)
|
|
|
|
#define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR)
|
|
|
|
|
2016-06-20 03:59:43 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_dev_channel
|
|
|
|
*
|
|
|
|
* Description:
|
2016-06-22 02:25:15 +08:00
|
|
|
* Configure to use the character device at CONFIG_SYSLOG_DEVPATH as the
|
|
|
|
* SYSLOG channel.
|
2016-06-20 03:59:43 +08:00
|
|
|
*
|
|
|
|
* This tiny function is simply a wrapper around syslog_dev_initialize()
|
|
|
|
* and syslog_channel(). It calls syslog_dev_initialize() to configure
|
|
|
|
* the character device at CONFIG_SYSLOG_DEVPATH then calls
|
|
|
|
* syslog_channel() to use that device as the SYSLOG output channel.
|
|
|
|
*
|
|
|
|
* NOTE interrupt level SYSLOG output will be lost in this case unless
|
|
|
|
* the interrupt buffer is used.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2021-06-03 18:24:49 +08:00
|
|
|
* A pointer to the new SYSLOG channel; NULL is returned on any failure.
|
2016-06-20 03:59:43 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-06-03 18:24:49 +08:00
|
|
|
FAR struct syslog_channel_s *syslog_dev_channel(void)
|
2016-06-20 03:59:43 +08:00
|
|
|
{
|
2022-01-13 20:45:44 +08:00
|
|
|
FAR struct syslog_channel_s *dev_channel;
|
|
|
|
|
2016-06-20 03:59:43 +08:00
|
|
|
/* Initialize the character driver interface */
|
|
|
|
|
2022-01-13 20:45:44 +08:00
|
|
|
dev_channel = syslog_dev_initialize(CONFIG_SYSLOG_DEVPATH,
|
|
|
|
OPEN_FLAGS, OPEN_MODE);
|
|
|
|
if (dev_channel == NULL)
|
2016-06-20 03:59:43 +08:00
|
|
|
{
|
2021-06-03 18:24:49 +08:00
|
|
|
return NULL;
|
2016-06-20 03:59:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the character driver as the SYSLOG channel */
|
|
|
|
|
2022-01-13 20:45:44 +08:00
|
|
|
if (syslog_channel(dev_channel) != OK)
|
2021-06-03 18:24:49 +08:00
|
|
|
{
|
2022-01-13 20:45:44 +08:00
|
|
|
syslog_dev_uninitialize(dev_channel);
|
|
|
|
dev_channel = NULL;
|
2021-06-03 18:24:49 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 20:45:44 +08:00
|
|
|
return dev_channel;
|
2016-06-20 03:59:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SYSLOG_CHAR */
|