From d361816fd58af8280943ac984d5962d0030aae26 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 28 Feb 2023 13:58:10 +0100 Subject: [PATCH 1/2] common/str.c: str_ends_with(): update origin attribution --- common/str.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/str.c b/common/str.c index 295f450804..b6fe24e84e 100644 --- a/common/str.c +++ b/common/str.c @@ -615,6 +615,8 @@ int str_to_double_strict(const char *string, double *number, const int base) return 1; } +/* Probably derived from https://stackoverflow.com/a/68816055/4715872 + * or a similar suggestion */ int str_ends_with(const char *s, const char *suff) { size_t slen; size_t sufflen; From e6d3bbeb46e02b2d8c7a1159dc239e011367d937 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 28 Feb 2023 14:03:37 +0100 Subject: [PATCH 2/2] clients/upssched.c: let UPSNAME@localhost specs copied from upsmon config "just work" [#1858] --- NEWS | 4 ++++ clients/upssched.c | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/NEWS b/NEWS index f5b85d8bbd..736288e7d1 100644 --- a/NEWS +++ b/NEWS @@ -243,6 +243,10 @@ https://github.com/networkupstools/nut/milestone/8 - Clarified documentation in codebase according to end-user feedback [#1721, #1750 and others over time] + - upssched: let `UPSNAME@localhost` specification strings copied from + upsmon config "just work" (previously only exact UPSNAME matches were + supported) [#1858] + - Several fixes for `upsmon` behavior [#1761, #1680...], including new ability to configure default POWERDOWNFLAG location -- packagers are encouraged to pick optimal location for their distributions (which diff --git a/clients/upssched.c b/clients/upssched.c index b38b84f0a2..75e32d2fc5 100644 --- a/clients/upssched.c +++ b/clients/upssched.c @@ -1264,6 +1264,13 @@ static int conf_arg(size_t numargs, char **arg) /* AT [] */ if (!strcmp(arg[0], "AT")) { + if (str_ends_with(arg[2], "@localhost")) { + /* Truncate: */ + arg[2][strlen(arg[2]) - strlen("@localhost")] = '\0'; + /* Make a little noise, but do not trash syslog about this: */ + upsdebugx(1, "WARNING: The @localhost in UPS identifier is redundant for upssched"); + } + /* don't use arg[5] unless we have it... */ if (numargs > 5) parse_at(arg[1], arg[2], arg[3], arg[4], arg[5]);