From 171eb409c14c1f2c801ae5098241cb0565611c9a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 5 Aug 2024 13:43:28 +0200 Subject: [PATCH] common/common.c: nut_report_config_flags(): refactor with describe_NUT_VERSION_once() copy of the code [#2573] Signed-off-by: Jim Klimov --- common/common.c | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/common/common.c b/common/common.c index 5eb7b4895e..6b62d66736 100644 --- a/common/common.c +++ b/common/common.c @@ -2261,28 +2261,11 @@ void nut_report_config_flags(void) now.tv_sec -= 1; } -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif - /* NOTE: Some compilers deduce that macro-based decisions about - * NUT_VERSION_IS_RELEASE make one of codepaths unreachable in - * a particular build. So we pragmatically handwave this away. - */ if (xbit_test(upslog_flags, UPSLOG_STDERR)) { - fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s%s%s%s %s%s\n", + fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s %s%s\n", difftime(now.tv_sec, upslog_start.tv_sec), (long)(now.tv_usec - upslog_start.tv_usec), - UPS_VERSION, - NUT_VERSION_IS_RELEASE ? " release" : " (development iteration after ", - NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, - NUT_VERSION_IS_RELEASE ? "" : ")", + describe_NUT_VERSION_once(), (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), @@ -2297,11 +2280,8 @@ void nut_report_config_flags(void) /* NOTE: May be ignored or truncated by receiver if that syslog server * (and/or OS sender) does not accept messages of such length */ if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) { - syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s%s%s%s %s%s", - UPS_VERSION, - NUT_VERSION_IS_RELEASE ? " release" : " (development iteration after ", - NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, - NUT_VERSION_IS_RELEASE ? "" : ")", + syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s %s%s", + describe_NUT_VERSION_once(), (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), @@ -2309,12 +2289,6 @@ void nut_report_config_flags(void) (config_flags && *config_flags != '\0' ? config_flags : "") ); } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif } static void vupslog(int priority, const char *fmt, va_list va, int use_strerror)