From 87c1738284ad9062cf344d038df2f3953030c1dd Mon Sep 17 00:00:00 2001 From: Kartik Naik Date: Wed, 19 Aug 2026 21:56:32 +0530 Subject: provide a vsyslog fallback in syslog_r instead of the header AIX has syslog but not vsyslog; the fallback lived in syslog.h as non-static function definitions, so it multiply-defined vsyslog_r (also defined in syslog_r.c) and pulled vasprintf in without stdio.h. Detect vsyslog and, when absent, format with vasprintf and call syslog directly from the shim. --- CMakeLists.txt | 5 +++++ crypto/compat/syslog_r.c | 11 +++++++++++ include/compat/syslog.h | 20 -------------------- m4/check-libc.m4 | 2 +- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a59ddc..a9d2f3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -422,6 +422,11 @@ if(HAVE_SYSLOG) add_definitions(-DHAVE_SYSLOG) endif() +check_function_exists(vsyslog HAVE_VSYSLOG) +if(HAVE_VSYSLOG) + add_definitions(-DHAVE_VSYSLOG) +endif() + check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB) if(HAVE_TIMESPECSUB) add_definitions(-DHAVE_TIMESPECSUB) diff --git a/crypto/compat/syslog_r.c b/crypto/compat/syslog_r.c index d68169d..30841c1 100644 --- a/crypto/compat/syslog_r.c +++ b/crypto/compat/syslog_r.c @@ -1,3 +1,5 @@ +#include +#include #include void @@ -14,6 +16,15 @@ void vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap) { #ifdef HAVE_SYSLOG +#ifdef HAVE_VSYSLOG vsyslog(pri, fmt, ap); +#else + char *msg = NULL; + + if (vasprintf(&msg, fmt, ap) == -1) + return; + syslog(pri, "%s", msg); + free(msg); +#endif #endif } diff --git a/include/compat/syslog.h b/include/compat/syslog.h index 3528eb3..c7a2608 100644 --- a/include/compat/syslog.h +++ b/include/compat/syslog.h @@ -36,23 +36,3 @@ void vsyslog_r(int, struct syslog_data *, const char *, va_list); #endif #endif - -#ifdef _AIX -#ifdef HAVE_SYSLOG -#include -void vsyslog(int facility_priority, const char *format, va_list arglist) { - char *msg = NULL; - vasprintf(&msg, format, arglist); - - if (!msg) - return; - - syslog(facility_priority, "%s", msg); - free(msg); -} -#endif /* HAVE_SYSLOG */ - -void vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap) { - vsyslog(pri, fmt, ap); -} -#endif /* AIX */ diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 8ecc89a..7ac1a10 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 @@ -26,7 +26,7 @@ AC_CHECK_FUNCS([asprintf freezero ftruncate getdelim getline memmem]) AC_CHECK_FUNCS([readpassphrase reallocarray recallocarray]) AC_CHECK_FUNCS([strcasecmp strlcat strlcpy strndup strnlen strsep strtonum]) AC_CHECK_FUNCS([timegm _mkgmtime timespecsub]) -AC_CHECK_FUNCS([getopt getprogname syslog syslog_r]) +AC_CHECK_FUNCS([getopt getprogname syslog syslog_r vsyslog]) AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include -- cgit v1.2.3-55-g6feb