From 1aaea1f07fa27f0663f057a3055accf050863b10 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 30 Jul 2024 16:06:52 +0200 Subject: [PATCH] server/netmisc.c: net_ver(): refer to PACKAGE_URL (and hard-coded "https://www.networkupstools.org/" if PACKAGE_URL points completely elsewhere) [#1949] Tested with "VER" command Signed-off-by: Jim Klimov --- server/netmisc.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/server/netmisc.c b/server/netmisc.c index ec4e8d28df..199e6d719b 100644 --- a/server/netmisc.c +++ b/server/netmisc.c @@ -31,14 +31,46 @@ void net_ver(nut_ctype_t *client, size_t numarg, const char **arg) { + int pkgurlHasNutOrg = 0; NUT_UNUSED_VARIABLE(arg); + if (numarg != 0) { send_err(client, NUT_ERR_INVALID_ARGUMENT); return; } - sendback(client, "Network UPS Tools upsd %s - https://www.networkupstools.org/\n", - UPS_VERSION); +#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 + if (PACKAGE_URL && strstr(PACKAGE_URL, "networkupstools.org")) { + pkgurlHasNutOrg = 1; + } else { + upsdebugx(1, "%s: WARNING: PACKAGE_URL of this build does not point to networkupstools.org!", __func__); + } + + /* 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. + */ + sendback(client, "Network UPS Tools upsd %s - %s%s%s\n", + UPS_VERSION, + PACKAGE_URL ? PACKAGE_URL : "", + (PACKAGE_URL && !pkgurlHasNutOrg) ? " or " : "", + pkgurlHasNutOrg ? "" : "https://www.networkupstools.org/" + ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic pop +#endif } void net_netver(nut_ctype_t *client, size_t numarg, const char **arg)