diff --git a/include/syslog.h b/include/syslog.h index c71d95176f..e57595fe1b 100644 --- a/include/syslog.h +++ b/include/syslog.h @@ -124,7 +124,6 @@ extern "C" #if 0 /* Not supported */ void openlog(FAR const char *ident, int option, int facility); void closelog(void); -int setlogmask(int mask); #endif /* These low-level debug APIs are provided by the NuttX library. These are @@ -162,6 +161,12 @@ int lowvsyslog(int priority, FAR const char *format, va_list ap); # define lowvsyslog(p,f,a) vsyslog(p,f,a) #endif +/* The setlogmask() function sets the logmask and returns the previous + * mask. If the mask argument is 0, the current logmask is not modified. + */ + +int setlogmask(int mask); + /* Enable or disable syslog output */ #ifdef CONFIG_SYSLOG_ENABLE /* Non-standard */ diff --git a/libc/Makefile b/libc/Makefile index 8412f8d884..b1082dd514 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -65,6 +65,7 @@ include stdio/Make.defs include stdlib/Make.defs include unistd/Make.defs include sched/Make.defs +include syslog/Make.defs include string/Make.defs include aio/Make.defs include pthread/Make.defs diff --git a/libc/lib_internal.h b/libc/lib_internal.h index d5d1700edd..b6518da6dd 100644 --- a/libc/lib_internal.h +++ b/libc/lib_internal.h @@ -137,12 +137,6 @@ extern "C" #define EXTERN extern #endif -/* Debug output is initially disabled */ - -#ifdef CONFIG_SYSLOG_ENABLE -EXTERN bool g_syslogenable; -#endif - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/libc/misc/Make.defs b/libc/misc/Make.defs index 6a2bd63e4d..c09e783313 100644 --- a/libc/misc/Make.defs +++ b/libc/misc/Make.defs @@ -59,9 +59,11 @@ endif # Add the miscellaneous C files to the build -CSRCS += lib_match.c -CSRCS += lib_crc32.c lib_crc16.c -CSRCS += lib_dbg.c lib_dumpbuffer.c +CSRCS += lib_match.c lib_crc32.c lib_crc16.c lib_dumpbuffer.c + +ifeq ($(CONFIG_DEBUG),y) +CSRCS += lib_dbg.c +endif # Keyboard driver encoder/decoder diff --git a/libc/misc/lib_dbg.c b/libc/misc/lib_dbg.c index 41d68ef8ce..aa0b857bb1 100644 --- a/libc/misc/lib_dbg.c +++ b/libc/misc/lib_dbg.c @@ -44,35 +44,16 @@ #include "lib_internal.h" -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/* Debug output is initially disabled */ - -#ifdef CONFIG_SYSLOG_ENABLE -bool g_syslogenable; -#endif +#ifndef CONFIG_CPP_HAVE_VARARGS /**************************************************************************** - * Global Functions + * Public Data ****************************************************************************/ /**************************************************************************** - * Name: syslog_enable - * - * Description: - * Enable or disable debug output. - * + * Public Functions ****************************************************************************/ -#ifdef CONFIG_SYSLOG_ENABLE -void syslog_enable(bool enable) -{ - g_syslogenable = enable; -} -#endif - /**************************************************************************** * Name: dbg, lldbg, vdbg * @@ -82,22 +63,15 @@ void syslog_enable(bool enable) * ****************************************************************************/ -#ifndef CONFIG_CPP_HAVE_VARARGS #ifdef CONFIG_DEBUG int dbg(const char *format, ...) { va_list ap; int ret; -#ifdef CONFIG_SYSLOG_ENABLE - ret = 0; - if (g_syslogenable) -#endif - { - va_start(ap, format); - ret = vsyslog(LOG_DEBUG, format, ap); - va_end(ap); - } + va_start(ap, format); + ret = vsyslog(LOG_DEBUG, format, ap); + va_end(ap); return ret; } @@ -108,15 +82,9 @@ int lldbg(const char *format, ...) va_list ap; int ret; -#ifdef CONFIG_SYSLOG_ENABLE - ret = 0; - if (g_syslogenable) -#endif - { - va_start(ap, format); - ret = lowvsyslog(LOG_DEBUG, format, ap); - va_end(ap); - } + va_start(ap, format); + ret = lowvsyslog(LOG_DEBUG, format, ap); + va_end(ap); return ret; } @@ -128,15 +96,9 @@ int vdbg(const char *format, ...) va_list ap; int ret; -#ifdef CONFIG_SYSLOG_ENABLE - ret = 0; - if (g_syslogenable) -#endif - { - va_start(ap, format); - ret = vsyslog(LOG_DEBUG, format, ap); - va_end(ap); - } + va_start(ap, format); + ret = vsyslog(LOG_DEBUG, format, ap); + va_end(ap); return ret; } @@ -147,15 +109,9 @@ int llvdbg(const char *format, ...) va_list ap; int ret; -#ifdef CONFIG_SYSLOG_ENABLE - ret = 0; - if (g_syslogenable) -#endif - { - va_start(ap, format); - ret = lowvsyslog(LOG_DEBUG, format, ap); - va_end(ap); - } + va_start(ap, format); + ret = lowvsyslog(LOG_DEBUG, format, ap); + va_end(ap); return ret; } diff --git a/libc/stdio/Make.defs b/libc/stdio/Make.defs index 484b969ce8..284c725c4b 100644 --- a/libc/stdio/Make.defs +++ b/libc/stdio/Make.defs @@ -37,10 +37,9 @@ # This first group of C files do not depend on having file descriptors or # C streams. -CSRCS += lib_fileno.c lib_printf.c lib_syslog.c lib_lowsyslog.c -CSRCS += lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c -CSRCS += lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c -CSRCS += lib_dprintf.c lib_vdprintf.c +CSRCS += lib_fileno.c lib_printf.c lib_sprintf.c lib_asprintf.c +CSRCS += lib_snprintf.c lib_libsprintf.c lib_vsprintf.c lib_avsprintf.c +CSRCS += lib_vsnprintf.c lib_libvsprintf.c lib_dprintf.c lib_vdprintf.c CSRCS += lib_meminstream.c lib_memoutstream.c lib_memsistream.c CSRCS += lib_memsostream.c lib_lowinstream.c lib_lowoutstream.c CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c @@ -71,10 +70,6 @@ endif # Other support that depends on specific, configured features. -ifeq ($(CONFIG_SYSLOG),y) -CSRCS += lib_syslogstream.c -endif - ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) CSRCS += lib_dtoa.c endif diff --git a/libc/syslog/Make.defs b/libc/syslog/Make.defs new file mode 100644 index 0000000000..fe6e620ed2 --- /dev/null +++ b/libc/syslog/Make.defs @@ -0,0 +1,51 @@ +############################################################################ +# libc/syslog/Make.defs +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Add the internal C files to the build + +CSRCS += lib_syslog.c lib_lowsyslog.c + +ifeq ($(CONFIG_SYSLOG),y) +CSRCS += lib_syslogstream.c +endif + +ifeq ($(CONFIG_SYSLOG_ENABLE),y) +CSRCS += lib_syslogenable.c +endif + +# Add the syslog directory to the build + +DEPPATH += --dep-path syslog +VPATH += :syslog diff --git a/libc/stdio/lib_lowsyslog.c b/libc/syslog/lib_lowsyslog.c similarity index 99% rename from libc/stdio/lib_lowsyslog.c rename to libc/syslog/lib_lowsyslog.c index 6b69191224..f7287c517b 100644 --- a/libc/stdio/lib_lowsyslog.c +++ b/libc/syslog/lib_lowsyslog.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/stdio/lib_lowsyslog.c + * libc/syslog/lib_lowsyslog.c * * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/libc/stdio/lib_syslog.c b/libc/syslog/lib_syslog.c similarity index 99% rename from libc/stdio/lib_syslog.c rename to libc/syslog/lib_syslog.c index 06c4637c39..21993ecc41 100644 --- a/libc/stdio/lib_syslog.c +++ b/libc/syslog/lib_syslog.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/stdio/lib_syslog.c + * libc/syslog/lib_syslog.c * * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -43,6 +43,7 @@ #include #include "lib_internal.h" +#include "syslog/syslog.h" /**************************************************************************** * Pre-processor Definitions diff --git a/libc/syslog/lib_syslogenable.c b/libc/syslog/lib_syslogenable.c new file mode 100644 index 0000000000..adba5b7081 --- /dev/null +++ b/libc/syslog/lib_syslogenable.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * libc/syslog/lib_syslogenable.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "lib_internal.h" + +#ifdef CONFIG_SYSLOG_ENABLE + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Debug output is initially disabled */ + +bool g_syslogenable; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: syslog_enable + * + * Description: + * Enable or disable debug output. + * + ****************************************************************************/ + +void syslog_enable(bool enable) +{ + g_syslogenable = enable; +} + +#endif /* CONFIG_SYSLOG_ENABLE */ diff --git a/libc/stdio/lib_syslogstream.c b/libc/syslog/lib_syslogstream.c similarity index 98% rename from libc/stdio/lib_syslogstream.c rename to libc/syslog/lib_syslogstream.c index 59f79f3f8c..7d485e74c8 100644 --- a/libc/stdio/lib_syslogstream.c +++ b/libc/syslog/lib_syslogstream.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/stdio/lib_syslogstream.c + * libc/syslog/lib_syslogstream.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -46,6 +46,7 @@ #include #include "lib_internal.h" +#include "syslog/syslog.h" #ifdef CONFIG_SYSLOG diff --git a/libc/syslog/syslog.h b/libc/syslog/syslog.h new file mode 100644 index 0000000000..6f9cb5ffa8 --- /dev/null +++ b/libc/syslog/syslog.h @@ -0,0 +1,81 @@ +/**************************************************************************** + * libc/syslog/syslog.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __LIBC_SYSLOG_SYSLOG_H +#define __LIBC_SYSLOG_SYSLOG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/* Debug output is initially disabled */ + +#ifdef CONFIG_SYSLOG_ENABLE +EXTERN bool g_syslogenable; +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __LIBC_SYSLOG_SYSLOG_H */