Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upssched: let UPSNAME@localhost specs copied from upsmon config "just work" #1861

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,13 @@ static int conf_arg(size_t numargs, char **arg)
/* AT <notifytype> <upsname> <command> <cmdarg1> [<cmdarg2>] */
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]);
Expand Down
2 changes: 2 additions & 0 deletions common/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down