From f8ed7323c0bca4a3c8fc0505a4ae9ee68d4ce85a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 8 Oct 2014 09:44:15 -0600 Subject: [PATCH] make standard syslog and vsyslog POSIX compliant (also modify non-standard syslog functions for compatibility). This will break a lot of things until ALL usage of syslog is updated to use the modified interfaces --- fs/driver/fs_syslog.c | 7 ++++--- include/debug.h | 8 ++++---- include/syslog.h | 8 ++++---- libc/libc.csv | 4 ++-- libc/misc/lib_dbg.c | 8 ++++---- libc/misc/lib_dumpbuffer.c | 39 ++++++++++++-------------------------- libc/stdio/lib_lowsyslog.c | 6 +++--- libc/stdio/lib_printf.c | 6 +++--- libc/stdio/lib_syslog.c | 6 +++--- 9 files changed, 39 insertions(+), 53 deletions(-) diff --git a/fs/driver/fs_syslog.c b/fs/driver/fs_syslog.c index 93eaa1fc95..ef35fb548e 100644 --- a/fs/driver/fs_syslog.c +++ b/fs/driver/fs_syslog.c @@ -360,9 +360,10 @@ int syslog_initialize(void) * Description: * This is the low-level system logging interface. The debugging/syslogging * interfaces are syslog() and lowsyslog(). The difference is is that - * the syslog() function writes to fd=1 (stdout) whereas lowsyslog() uses - * a lower level interface that works from interrupt handlers. This - * function is a a low-level interface used to implement lowsyslog(). + * the syslog() function writes to syslogging device (usually fd=1, stdout) + * whereas lowsyslog() uses a lower level interface that works from + * interrupt handlers. This function is a a low-level interface used to + * implement lowsyslog(). * ****************************************************************************/ diff --git a/include/debug.h b/include/debug.h index 7fd6bc4977..74f50935a2 100644 --- a/include/debug.h +++ b/include/debug.h @@ -104,22 +104,22 @@ #ifdef CONFIG_DEBUG # define dbg(format, ...) \ - syslog(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # ifdef CONFIG_ARCH_LOWPUTC # define lldbg(format, ...) \ - lowsyslog(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + lowsyslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # else # define lldbg(x...) # endif # ifdef CONFIG_DEBUG_VERBOSE # define vdbg(format, ...) \ - syslog(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + syslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # ifdef CONFIG_ARCH_LOWPUTC # define llvdbg(format, ...) \ - lowsyslog(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + lowsyslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # else # define llvdbg(x...) # endif diff --git a/include/syslog.h b/include/syslog.h index ab0e6073c9..1773159a4c 100644 --- a/include/syslog.h +++ b/include/syslog.h @@ -128,12 +128,12 @@ int setlogmask(int mask); * following. */ -int syslog(FAR const char *format, ...); -int vsyslog(const char *src, va_list ap); +int syslog(int priority, FAR const char *format, ...); +int vsyslog(int priority, FAR const char *src, va_list ap); #ifdef CONFIG_ARCH_LOWPUTC /* Non-standard */ -int lowsyslog(FAR const char *format, ...); -int lowvsyslog(FAR const char *src, va_list ap); +int lowsyslog(int priority, FAR const char *format, ...); +int lowvsyslog(int priority, FAR const char *src, va_list ap); #endif /* Enable or disable syslog output */ diff --git a/libc/libc.csv b/libc/libc.csv index 9b7f7ebfbb..e384e69f3a 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -65,7 +65,7 @@ "llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int" "lldbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." "llvdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." -"lowsyslog","syslog.h","","int","FAR const char *","..." +"lowsyslog","syslog.h","","int","int","FAR const char *","..." "match","nuttx/regex.h","","int","const char *","const char *" "memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t" "memchr","string.h","","FAR void","FAR const void *","int c","size_t" @@ -155,7 +155,7 @@ "strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","const char *nptr","char **endptr","int base" "strtoul","stdlib.h","","unsigned long","const char *","char **","int" "strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","const char *","char **","int" -"syslog","syslog.h","","int","FAR const char *","..." +"syslog","syslog.h","","int","int","FAR const char *","..." "syslog_enable","syslog.h","defined(CONFIG_SYSLOG_ENABLE)","void","bool" "tcflush","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int" "tcgetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *" diff --git a/libc/misc/lib_dbg.c b/libc/misc/lib_dbg.c index 921a4e24d4..41d68ef8ce 100644 --- a/libc/misc/lib_dbg.c +++ b/libc/misc/lib_dbg.c @@ -95,7 +95,7 @@ int dbg(const char *format, ...) #endif { va_start(ap, format); - ret = vsyslog(format, ap); + ret = vsyslog(LOG_DEBUG, format, ap); va_end(ap); } @@ -114,7 +114,7 @@ int lldbg(const char *format, ...) #endif { va_start(ap, format); - ret = lowvsyslog(format, ap); + ret = lowvsyslog(LOG_DEBUG, format, ap); va_end(ap); } @@ -134,7 +134,7 @@ int vdbg(const char *format, ...) #endif { va_start(ap, format); - ret = vsyslog(format, ap); + ret = vsyslog(LOG_DEBUG, format, ap); va_end(ap); } @@ -153,7 +153,7 @@ int llvdbg(const char *format, ...) #endif { va_start(ap, format); - ret = lowvsyslog(format, ap); + ret = lowvsyslog(LOG_DEBUG, format, ap); va_end(ap); } diff --git a/libc/misc/lib_dumpbuffer.c b/libc/misc/lib_dumpbuffer.c index e05c0ea4de..23e7e617b8 100644 --- a/libc/misc/lib_dumpbuffer.c +++ b/libc/misc/lib_dumpbuffer.c @@ -47,22 +47,6 @@ * Pre-processor definitions ****************************************************************************/ -/* Select the lowest level debug interface available */ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_ARCH_LOWPUTC -# define message(format, ...) lowsyslog(format, ##__VA_ARGS__) -# else -# define message(format, ...) syslog(format, ##__VA_ARGS__) -# endif -#else -# ifdef CONFIG_ARCH_LOWPUTC -# define message lowsyslog -# else -# define message syslog -# endif -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -75,58 +59,59 @@ * ****************************************************************************/ -void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen) +void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, + unsigned int buflen) { unsigned int i; unsigned int j; unsigned int k; - message("%s (%p):\n", msg, buffer); + lowsyslog(LOG_INFO, "%s (%p):\n", msg, buffer); for (i = 0; i < buflen; i += 32) { - message("%04x: ", i); + lowsyslog(LOG_INFO, "%04x: ", i); for (j = 0; j < 32; j++) { k = i + j; if (j == 16) { - message(" "); + lowsyslog(LOG_INFO, " "); } if (k < buflen) { - message("%02x", buffer[k]); + lowsyslog(LOG_INFO, "%02x", buffer[k]); } else { - message(" "); + lowsyslog(LOG_INFO, " "); } } - message(" "); + lowsyslog(LOG_INFO, " "); for (j = 0; j < 32; j++) { k = i + j; if (j == 16) { - message(" "); + lowsyslog(LOG_INFO, " "); } if (k < buflen) { if (buffer[k] >= 0x20 && buffer[k] < 0x7f) { - message("%c", buffer[k]); + lowsyslog(LOG_INFO, "%c", buffer[k]); } else { - message("."); + lowsyslog(LOG_INFO, "."); } } } - message("\n"); + lowsyslog(LOG_INFO, "\n"); } } diff --git a/libc/stdio/lib_lowsyslog.c b/libc/stdio/lib_lowsyslog.c index 3ada77bf54..e35db0fae1 100644 --- a/libc/stdio/lib_lowsyslog.c +++ b/libc/stdio/lib_lowsyslog.c @@ -49,7 +49,7 @@ #if !defined(CONFIG_BUILD_PROTECTED) || defined(__KERNEL__) /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** @@ -90,7 +90,7 @@ #if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG) -int lowvsyslog(FAR const char *fmt, va_list ap) +int lowvsyslog(int priority, FAR const char *fmt, va_list ap) { struct lib_outstream_s stream; @@ -108,7 +108,7 @@ int lowvsyslog(FAR const char *fmt, va_list ap) * Name: lowsyslog ****************************************************************************/ -int lowsyslog(FAR const char *fmt, ...) +int lowsyslog(int priority, FAR const char *fmt, ...) { va_list ap; int ret; diff --git a/libc/stdio/lib_printf.c b/libc/stdio/lib_printf.c index a4530daada..f9446ed716 100644 --- a/libc/stdio/lib_printf.c +++ b/libc/stdio/lib_printf.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_printf.c * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2008, 2011-2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -95,9 +95,9 @@ int printf(FAR const char *fmt, ...) #if CONFIG_NFILE_STREAMS > 0 ret = vfprintf(stdout, fmt, ap); #elif CONFIG_NFILE_DESCRIPTORS > 0 - ret = vsyslog(fmt, ap); + ret = vsyslog(LOG_INFO, fmt, ap); #elif defined(CONFIG_ARCH_LOWPUTC) - ret = lowvsyslog(fmt, ap); + ret = lowvsyslog(LOG_INFO, fmt, ap); #else # ifdef CONFIG_CPP_HAVE_WARNING # warning "printf has no data sink" diff --git a/libc/stdio/lib_syslog.c b/libc/stdio/lib_syslog.c index 5f09582626..97465d51b9 100644 --- a/libc/stdio/lib_syslog.c +++ b/libc/stdio/lib_syslog.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_syslog.c * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -91,7 +91,7 @@ * Name: vsyslog ****************************************************************************/ -int vsyslog(FAR const char *fmt, va_list ap) +int vsyslog(int priority, FAR const char *fmt, va_list ap) { #if defined(CONFIG_SYSLOG) @@ -135,7 +135,7 @@ int vsyslog(FAR const char *fmt, va_list ap) * Name: syslog ****************************************************************************/ -int syslog(FAR const char *fmt, ...) +int syslog(int priority, FAR const char *fmt, ...) { va_list ap; int ret;