From d83f5aea789f896c90208567a9e56599a439e90a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 17 Dec 2024 19:17:44 -0800 Subject: [PATCH] syslog: test for existence Some POSIX emulations may lack a reasonable syslog function (although syslog is required per the Open Group). For now we just check for it, and don't use it if it isn't present. --- src/core/CMakeLists.txt | 1 + src/core/log.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 81f8d1ee5..ba8b1ca80 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -15,6 +15,7 @@ nng_check_sym(strnlen string.h NNG_HAVE_STRNLEN) nng_check_sym(strcasecmp string.h NNG_HAVE_STRCASECMP) nng_check_sym(strncasecmp string.h NNG_HAVE_STRNCASECMP) nng_check_sym(localtime_r time.h NNG_HAVE_LOCALTIME_R) +nng_check_sym(syslog syslog.h NNG_HAVE_SYSLOG) nng_sources( defs.h diff --git a/src/core/log.c b/src/core/log.c index 0084b06e1..bbdac0631 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -16,7 +16,7 @@ #ifdef NNG_PLATFORM_WINDOWS #include #endif -#ifdef NNG_PLATFORM_POSIX +#ifdef NNG_HAVE_SYSLOG #include #include #endif @@ -90,7 +90,7 @@ stderr_logger(nng_log_level level, nng_log_facility facility, #ifdef NNG_PLATFORM_WINDOWS // NB: We are blithely assuming the user has a modern console. colors = _isatty(_fileno(stderr)); -#elif defined(NNG_PLATFORM_POSIX) +#elif defined(NNG_HAVE_SYSLOG) // Only assuming we can use colors (and attributes) if stderr is a tty // and $TERM is reasonable. We assume the terminal supports ECMA-48, // which is true on every reasonable system these days. @@ -186,7 +186,7 @@ void nng_system_logger(nng_log_level level, nng_log_facility facility, const char *msgid, const char *msg) { -#ifdef NNG_PLATFORM_POSIX +#ifdef NNG_HAVE_SYSLOG int pri; switch (level) { case NNG_LOG_ERR: