Skip to content

Commit

Permalink
common/common.c: nut_report_config_flags(): refactor with describe_NU…
Browse files Browse the repository at this point in the history
…T_VERSION_once() copy of the code [networkupstools#2573]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Aug 5, 2024
1 parent 73f4d25 commit 171eb40
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" : ""),
Expand All @@ -2297,24 +2280,15 @@ 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" : ""),
(config_flags && *config_flags != '\0' ? "configured with flags: " : "configured all by default guesswork"),
(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)
Expand Down

0 comments on commit 171eb40

Please sign in to comment.