Skip to content

Commit

Permalink
server/netmisc.c: net_ver(): refer to PACKAGE_URL (and hard-coded "ht…
Browse files Browse the repository at this point in the history
…tps://www.networkupstools.org/" if PACKAGE_URL points completely elsewhere) [networkupstools#1949]

Tested with "VER" command

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 30, 2024
1 parent 30748bd commit 1aaea1f
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions server/netmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1aaea1f

Please sign in to comment.