mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
syslog: If syslog timestamping is enabled, don't try to get the time if the timer hardware has not yet been initialized.
This commit is contained in:
@@ -11456,3 +11456,6 @@
|
|||||||
some logic that may attempt to run early in the start-up sequence but
|
some logic that may attempt to run early in the start-up sequence but
|
||||||
cannot run if a sufficient level of initialization has not yet occurred
|
cannot run if a sufficient level of initialization has not yet occurred
|
||||||
(2016-02-05).
|
(2016-02-05).
|
||||||
|
* libc/syslog/lib_syslog.c: If syslog timestamping is enabled, don't try to
|
||||||
|
get the time if the timer hardware has not yet been initialized
|
||||||
|
(2016-02-05).
|
||||||
|
|||||||
+25
-57
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/syslog/lib_syslog.c
|
* libc/syslog/lib_syslog.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2014, 2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -42,43 +42,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <nuttx/init.h>
|
||||||
#include <nuttx/clock.h>
|
#include <nuttx/clock.h>
|
||||||
#include <nuttx/streams.h>
|
#include <nuttx/streams.h>
|
||||||
|
|
||||||
#include "syslog/syslog.h"
|
#include "syslog/syslog.h"
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Type Declarations
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Constant Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Constant Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -104,11 +73,19 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap)
|
|||||||
|
|
||||||
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Get the current time */
|
/* Get the current time. Since debug output may be generated very early
|
||||||
|
* in the start-up sequence, hardware timer support may not yet be
|
||||||
|
* available.
|
||||||
|
*/
|
||||||
|
|
||||||
ret = clock_systimespec(&ts);
|
if (!OSINIT_HW_READY() || clock_systimespec(&ts) < 0)
|
||||||
|
{
|
||||||
|
/* Timer hardware is not available, or clock_systimespec failed */
|
||||||
|
|
||||||
|
ts.tv_sec = 0;
|
||||||
|
ts.tv_nsec = 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_SYSLOG)
|
#if defined(CONFIG_SYSLOG)
|
||||||
@@ -119,14 +96,11 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap)
|
|||||||
lib_syslogstream((FAR struct lib_outstream_s *)&stream);
|
lib_syslogstream((FAR struct lib_outstream_s *)&stream);
|
||||||
|
|
||||||
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
||||||
/* Pre-pend the message with the current time */
|
/* 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);
|
||||||
|
|
||||||
if (ret == OK)
|
|
||||||
{
|
|
||||||
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
|
|
||||||
"[%6d.%06d]",
|
|
||||||
ts.tv_sec, ts.tv_nsec/1000);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
|
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
|
||||||
@@ -139,14 +113,10 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap)
|
|||||||
lib_rawoutstream(&stream, 1);
|
lib_rawoutstream(&stream, 1);
|
||||||
|
|
||||||
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
||||||
/* Pre-pend the message with the current time */
|
/* Pre-pend the message with the current time, if available */
|
||||||
|
|
||||||
if (ret == OK)
|
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
|
||||||
{
|
"[%6d.%06d]", ts.tv_sec, ts.tv_nsec/1000);
|
||||||
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
|
|
||||||
"[%6d.%06d]",
|
|
||||||
ts.tv_sec, ts.tv_nsec/1000);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return lib_vsprintf(&stream.public, fmt, ap);
|
return lib_vsprintf(&stream.public, fmt, ap);
|
||||||
@@ -159,20 +129,18 @@ static inline int vsyslog_internal(FAR const IPTR char *fmt, va_list ap)
|
|||||||
lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
|
lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
|
||||||
|
|
||||||
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
#if defined(CONFIG_SYSLOG_TIMESTAMP)
|
||||||
/* Pre-pend the message with the current time */
|
/* Pre-pend the message with the current time, if available */
|
||||||
|
|
||||||
if (ret == OK)
|
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
|
||||||
{
|
"[%6d.%06d]", ts.tv_sec, ts.tv_nsec/1000);
|
||||||
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
|
|
||||||
"[%6d.%06d]",
|
|
||||||
ts.tv_sec, ts.tv_nsec/1000);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
|
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
|
||||||
|
|
||||||
#else /* CONFIG_SYSLOG */
|
#else /* CONFIG_SYSLOG */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#endif /* CONFIG_SYSLOG */
|
#endif /* CONFIG_SYSLOG */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user