2016-06-19 21:59:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/syslog/syslog_consolechannel.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-06-19 21:59:43 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-19 21:59: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.
|
2016-06-19 21:59:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2016-06-21 20:25:15 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2021-03-29 14:36:58 +02:00
|
|
|
#include <errno.h>
|
2016-06-21 20:25:15 +02:00
|
|
|
|
2016-06-19 21:59:43 +02:00
|
|
|
#include <nuttx/syslog/syslog.h>
|
|
|
|
|
|
|
|
#include "syslog.h"
|
|
|
|
|
2016-06-21 17:59:09 +02:00
|
|
|
#ifdef CONFIG_SYSLOG_CONSOLE
|
2016-06-19 21:59:43 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2016-06-21 20:25:15 +02:00
|
|
|
* Pre-processor Definitions
|
2016-06-19 21:59:43 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-21 20:25:15 +02:00
|
|
|
#define OPEN_FLAGS (O_WRONLY)
|
|
|
|
#define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR)
|
|
|
|
|
2016-06-19 21:59:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
/* Handle to the SYSLOG channel */
|
|
|
|
|
|
|
|
FAR static struct syslog_channel_s *g_syslog_console_channel;
|
|
|
|
|
2016-06-19 21:59:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_console_channel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure to use the character device (or file) at /dev/console as the
|
|
|
|
* SYSLOG channel.
|
|
|
|
*
|
|
|
|
* 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 /dev/console then calls syslog_channel() to
|
|
|
|
* use that device as the SYSLOG output channel.
|
|
|
|
*
|
|
|
|
* NOTE interrupt level SYSLOG output will be lost in the general case
|
|
|
|
* unless the interrupt buffer is used. As a special case: If the serial
|
|
|
|
* console is used and the architecture provides up_putc(), the interrupt
|
|
|
|
* level output will be directed to up_putc() is the interrupt buffer is
|
|
|
|
* disabled.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int syslog_console_channel(void)
|
|
|
|
{
|
|
|
|
/* Initialize the character driver interface */
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
g_syslog_console_channel = syslog_dev_initialize("/dev/console",
|
|
|
|
OPEN_FLAGS, OPEN_MODE);
|
|
|
|
if (g_syslog_console_channel == NULL)
|
2016-06-19 21:59:43 +02:00
|
|
|
{
|
2021-03-29 14:36:58 +02:00
|
|
|
return -ENOMEM;
|
2016-06-19 21:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the character driver as the SYSLOG channel */
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
return syslog_channel(g_syslog_console_channel);
|
2016-06-19 21:59:43 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 17:59:09 +02:00
|
|
|
#endif /* CONFIG_SYSLOG_CONSOLE */
|