Remove some last traces of lowvsyslog that were missed; Add a SYSLOG emergency channel for handling assertion output more cleanly

This commit is contained in:
Gregory Nutt 2016-06-20 16:11:50 -06:00
parent d1a62f1d24
commit 505ca542e8
26 changed files with 177 additions and 72 deletions

View File

@ -151,7 +151,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -193,7 +193,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -185,7 +185,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -198,7 +198,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -186,7 +186,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -109,7 +109,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -144,7 +144,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -109,7 +109,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -110,7 +110,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -103,7 +103,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -109,7 +109,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -108,7 +108,7 @@ static int usbtrace_syslog(FAR const char *fmt, ...)
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_EMERG, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -224,6 +224,25 @@ int syslog_flush_intbuffer(FAR const struct syslog_channel_s *channel,
int syslog_putc(int ch);
/****************************************************************************
* Name: syslog_force
*
* Description:
* This is the low-level system logging interface. This version forces
* the output and is only used in emergency situations (e.g., in assertion
* handling).
*
* Input Parameters:
* ch - The character to add to the SYSLOG (must be positive).
*
* Returned Value:
* On success, the character is echoed back to the caller. A negated
* errno value is returned on any failure.
*
****************************************************************************/
int syslog_force(int ch);
/****************************************************************************
* Name: syslog_dev_putc
*

View File

@ -210,6 +210,40 @@ int syslog_putc(int ch)
}
}
/****************************************************************************
* Name: syslog_force
*
* Description:
* This is the low-level system logging interface. This version forces
* the output and is only used in emergency situations (e.g., in assertion
* handling).
*
* Input Parameters:
* ch - The character to add to the SYSLOG (must be positive).
*
* Returned Value:
* On success, the character is echoed back to the caller. A negated
* errno value is returned on any failure.
*
****************************************************************************/
int syslog_force(int ch)
{
DEBUGASSERT(g_syslog_channel != NULL && g_syslog_channel->sc_force != NULL);
#ifdef CONFIG_SYSLOG_INTBUFFER
/* Flush any characters that may have been added to the interrupt
* buffer through the emergency channel
*/
(void)syslog_flush_intbuffer(g_syslog_channel, true);
#endif
/* Then send the character to the emergency channel */
return g_syslog_channel->sc_force(ch);
}
/****************************************************************************
* Name: syslog_flush
*

View File

@ -86,6 +86,39 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
while (errno == -EINTR);
}
/****************************************************************************
* 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,
* syslog_putc returns EOF with the errno value set;
*/
ret = syslog_force(ch);
if (ret != EOF)
{
this->nput++;
return;
}
/* The special errno value -EINTR means that syslog_putc() was
* awakened by a signal. This is not a real error and must be
* ignored in this context.
*/
}
while (errno == -EINTR);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -114,3 +147,28 @@ void syslogstream(FAR struct lib_outstream_s *stream)
#endif
stream->nput = 0;
}
/****************************************************************************
* Name: emergstream
*
* Description:
* Initializes a stream for use with the configured emergency syslog
* interface. Only accessible from with the OS SYSLOG logic.
*
* Input parameters:
* stream - User allocated, uninitialized instance of struct
* lib_lowoutstream_s to be initialized.
*
* Returned Value:
* None (User allocated instance initialized).
*
****************************************************************************/
void emergstream(FAR struct lib_outstream_s *stream)
{
stream->put = emergstream_putc;
#ifdef CONFIG_STDIO_LINEBUFFER
stream->flush = lib_noflush;
#endif
stream->nput = 0;
}

View File

@ -57,16 +57,15 @@
*
* Description:
* _vsyslog() handles the system logging system calls. It is functionally
* equivalent to vsyslog() except that the per-process priority filtering
* has already been performed and, hence, there is no priority argument.
*
* NOTE: The va_list parameter is passed by reference. That is because
* the va_list is a structure in some compilers and passing of structures
* in the NuttX sycalls does not work.
* equivalent to vsyslog() except that (1) the per-process priority
* filtering has already been performed and the va_list parameter is
* passed by reference. That is because the va_list is a structure in
* some compilers and passing of structures in the NuttX sycalls does
* not work.
*
****************************************************************************/
int _vsyslog(FAR const IPTR char *fmt, FAR va_list *ap)
int _vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
{
struct lib_outstream_s stream;
#ifdef CONFIG_SYSLOG_TIMESTAMP
@ -87,17 +86,28 @@ int _vsyslog(FAR const IPTR char *fmt, FAR va_list *ap)
#endif
/* Wrap the low-level output in a stream object and let lib_vsprintf
* do the work.
* do the work. NOTE that emergency priority output is handled
* differently.. it will use the SYSLOG emergency stream.
*/
syslogstream((FAR struct lib_outstream_s *)&stream);
if (priority == LOG_EMERG)
{
/* Use the SYSLOG emergency stream */
emergstream((FAR struct lib_outstream_s *)&stream);
}
else
{
/* Use the normal SYSLOG stream */
syslogstream((FAR struct lib_outstream_s *)&stream);
}
#if defined(CONFIG_SYSLOG_TIMESTAMP)
/* Pre-pend the message with the current time, if available */
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
"[%6d.%06d]", ts.tv_sec, ts.tv_nsec/1000);
#endif
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, *ap);

View File

@ -100,10 +100,10 @@ static int usbtrace_syslog(const char *fmt, ...)
va_list ap;
int ret;
/* Let lowvsyslog do the real work */
/* Let vsyslog do the real work */
va_start(ap, fmt);
ret = lowvsyslog(LOG_INFO, fmt, ap);
ret = vsyslog(LOG_INFO, fmt, ap);
va_end(ap);
return ret;
}

View File

@ -371,6 +371,24 @@ void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream);
void syslogstream(FAR struct lib_outstream_s *stream);
/****************************************************************************
* Name: emergstream
*
* Description:
* Initializes a stream for use with the configured emergency syslog
* interface. Only accessible from with the OS SYSLOG logic.
*
* Input parameters:
* stream - User allocated, uninitialized instance of struct
* lib_lowoutstream_s to be initialized.
*
* Returned Value:
* None (User allocated instance initialized).
*
****************************************************************************/
void emergstream(FAR struct lib_outstream_s *stream);
/****************************************************************************
* Name: lib_noflush
*

View File

@ -219,16 +219,15 @@ int syslog_flush(void);
*
* Description:
* _vsyslog() handles the system logging system calls. It is functionally
* equivalent to vsyslog() except that the per-process priority filtering
* has already been performed and, hence, there is no priority argument.
*
* NOTE: The va_list parameter is passed by reference. That is because
* the va_list is a structure in some compilers and passing of structures
* in the NuttX sycalls does not work.
* equivalent to vsyslog() except that (1) the per-process priority
* filtering has already been performed and the va_list parameter is
* passed by reference. That is because the va_list is a structure in
* some compilers and passing of structures in the NuttX sycalls does
* not work.
*
****************************************************************************/
int _vsyslog(FAR const IPTR char *src, FAR va_list *ap);
int _vsyslog(int priority, FAR const IPTR char *src, FAR va_list *ap);
#undef EXTERN
#ifdef __cplusplus

View File

@ -66,7 +66,7 @@ int _alert(const char *format, ...)
int ret;
va_start(ap, format);
ret = lowvsyslog(LOG_EMERG, format, ap);
ret = vsyslog(LOG_EMERG, format, ap);
va_end(ap);
return ret;

View File

@ -33,44 +33,12 @@
*
****************************************************************************/
/****************************************************************************
* Compilation Switches
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Public Constant Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Constant Data
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -1,7 +1,7 @@
/****************************************************************************
* libc/stdio/lib_printf.c
*
* Copyright (C) 2007-2008, 2011-2012, 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2008, 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -60,8 +60,6 @@ int printf(FAR const IPTR char *fmt, ...)
ret = vfprintf(stdout, fmt, ap);
#elif CONFIG_NFILE_DESCRIPTORS > 0
ret = vsyslog(LOG_INFO, fmt, ap);
#elif defined(CONFIG_ARCH_LOWPUTC)
ret = lowvsyslog(LOG_INFO, fmt, ap);
#else
# ifdef CONFIG_CPP_HAVE_WARNING
# warning "printf has no data sink"

View File

@ -67,14 +67,14 @@ int vsyslog(int priority, FAR const IPTR char *fmt, va_list ap)
if ((g_syslog_mask & LOG_MASK(priority)) != 0)
{
/* Yes.. lPerform the _vsyslog system call.
/* Yes.. Perform the _vsyslog system call.
*
* NOTE: The va_list parameter is passed by reference. That is
* because the va_list is a structure in some compilers and passing
* of structures in the NuttX sycalls does not work.
*/
ret = _vsyslog(fmt, &ap);
ret = _vsyslog(priority, fmt, &ap);
}
return ret;

View File

@ -159,7 +159,7 @@
"up_assert","assert.h","","void","FAR const uint8_t*","int"
#"up_assert","assert.h","","void"
"vfork","unistd.h","defined(CONFIG_ARCH_HAVE_VFORK)","pid_t"
"_vsyslog","syslog.h","","int","FAR const IPTR char*","FAR va_list*"
"_vsyslog","syslog.h","","int","int","FAR const IPTR char*","FAR va_list*"
"wait","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","pid_t","int*"
"waitid","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","int","idtype_t","id_t"," FAR siginfo_t *","int"
"waitpid","sys/wait.h","defined(CONFIG_SCHED_WAITPID)","pid_t","pid_t","int*","int"

Can't render this file because it has a wrong number of fields in line 2.

View File

@ -165,7 +165,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
/* System logging */
SYSCALL_LOOKUP(_vsyslog, 2, STUB__vsyslog)
SYSCALL_LOOKUP(_vsyslog, 3, STUB__vsyslog)
/* The following are defined if either file or socket descriptor are
* enabled.

View File

@ -167,7 +167,8 @@ uintptr_t STUB_timer_settime(int nbr, uintptr_t parm1, uintptr_t parm2,
/* System logging */
uintptr_t STUB__vsyslog(int nbr, uintptr_t parm1, uintptr_t parm2);
uintptr_t STUB__vsyslog(int nbr, uintptr_t parm1, uintptr_t parm2,
uintptr_t parm3);
/* The following are defined if either file or socket descriptor are
* enabled.