2016-06-21 01:10:52 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* drivers/syslog/syslog_emergstream.c
|
2016-06-21 01:10:52 +02:00
|
|
|
*
|
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-21 01:10:52 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-21 01:10:52 +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-21 01:10:52 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/syslog/syslog.h>
|
|
|
|
#include <nuttx/streams.h>
|
|
|
|
|
|
|
|
#include "syslog.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: emergstream_putc
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void emergstream_putc(FAR struct lib_outstream_s *this, int ch)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Try writing until the write was successful or until an irrecoverable
|
|
|
|
* error occurs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Write the character to the supported logging device. On failure,
|
2019-09-16 15:48:48 +02:00
|
|
|
* syslog_force returns a negated errno value.
|
2016-06-21 01:10:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
ret = syslog_force(ch);
|
2019-09-16 15:48:48 +02:00
|
|
|
if (ret >= 0)
|
2016-06-21 01:10:52 +02:00
|
|
|
{
|
|
|
|
this->nput++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-16 15:48:48 +02:00
|
|
|
/* The special return value -EINTR means that syslog_force() was
|
2016-06-21 01:10:52 +02:00
|
|
|
* awakened by a signal. This is not a real error and must be
|
|
|
|
* ignored in this context.
|
|
|
|
*/
|
|
|
|
}
|
2019-09-16 15:48:48 +02:00
|
|
|
while (ret == -EINTR);
|
2016-06-21 01:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: emergstream
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initializes a stream for use with the configured emergency syslog
|
|
|
|
* interface. Only accessible from with the OS SYSLOG logic.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2016-06-21 01:10:52 +02:00
|
|
|
* stream - User allocated, uninitialized instance of struct
|
2017-05-10 22:42:43 +02:00
|
|
|
* lib_outstream_s to be initialized.
|
2016-06-21 01:10:52 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None (User allocated instance initialized).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void emergstream(FAR struct lib_outstream_s *stream)
|
|
|
|
{
|
|
|
|
stream->put = emergstream_putc;
|
|
|
|
stream->flush = lib_noflush;
|
|
|
|
stream->nput = 0;
|
|
|
|
}
|