Skip to content

Commit

Permalink
Merge pull request #2756 from jimklimov/issue-1803
Browse files Browse the repository at this point in the history
Feature improvements for `upslog`
  • Loading branch information
jimklimov authored Jan 8, 2025
2 parents 1a0da2c + e8fbedf commit b372400
Show file tree
Hide file tree
Showing 72 changed files with 847 additions and 435 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ install-bin:
install-man: install-data-recursive
@echo $(WARN)
@echo "Warning: 'make install-man' is deprecated."
@echo "Use 'cd man; make install' instead."
@echo "Use 'cd docs/man; make install' instead."
@echo $(WARN)
+cd man; $(MAKE) $(AM_MAKEFLAGS) install
+cd docs/man; $(MAKE) $(AM_MAKEFLAGS) install
install-conf:
@echo $(WARN)
@echo "Warning: 'make install-conf' is deprecated."
Expand Down
24 changes: 24 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ https://github.com/networkupstools/nut/milestone/11
- upslog:
* Added support for limiting the loop count. Using in NIT (NUT Integration
Test) suite for double profit (checking the tool and fallback in NIT).
* If you use the legacy CLI options for single-system logging (`-s <system>`
and `-l <logfile>`) along with newer tuple(s) for multiple-system logging
(repeatable `-m <system,logfile>`), previously the single-system options
were overridden by the tuple(s); now they become part of the list.
* The `upsname` in the `system=upsname[@hostname[:port]]` parameter may
be an asterisk `*` to query for devices currently served by the hostname.
* Same log file may safely be used in different logging tuples (it is
then recommended to use `%UPSHOST%` in a custom formatting string).
* Fixed printing of `%UPSHOST%` when multiple systems are being logged.
* A `%t` for a TAB character can now be used in the formatting string.
* Added `-D` for debugging (and foregrounding by default), like with
other NUT daemons.
* Added systemd and SMF service integration. [#1803]
- More systemd integration:
Expand Down Expand Up @@ -406,6 +418,8 @@ logic that was previously the content of `upsdrv_shutdown()` methods was often
relocated into new `shutdown.default` INSTCMD definitions. [#2670]
- common code:
* `upscli_splitname()` should now recognize `upsname:port` typos (missing
the `@hostname` part) and error out gracefully.
* introduced a `NUT_DEBUG_SYSLOG` environment variable to tweak activation
of syslog message emission (and related detachment of `stderr` when
backgrounding), primarily useful for NIT and perhaps systemd. Most
Expand Down Expand Up @@ -447,6 +461,16 @@ relocated into new `shutdown.default` INSTCMD definitions. [#2670]
`gcc-13`+ whose static analyzers on NUT CI farm complained about some
imperfections after adding newer OS revisions to the population of
build agents. [#2585, #2588]
* New checks in `clang-19` brought new findings about mismatched formatting
strings and `int`-ish parameters of respective methods.
Overall, had to change formatting strings in some cases, variable types
in others (e.g. flags or notification types do not make sense as signed)
and added casting in a few places that remained, because:
- `%x` style formatting requires an `unsigned int` variable
- numeric literals and macros are `int` by default
- results of math with unsigned types like `uint16_t`, done in some
cases, are up-scaled into `int` by default
- `char`'s, `unsigned` or not, seem to be also up-scaled into `int`
- updated `docs/nut-names.txt` with items defined by 42ITy NUT fork. [#2339]
Expand Down
28 changes: 18 additions & 10 deletions clients/upsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C)
2002 Russell Kroll <[email protected]>
2008 Arjen de Korte <[email protected]>
2020 - 2024 Jim Klimov <[email protected]>
2020 - 2025 Jim Klimov <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1622,7 +1622,7 @@ ssize_t upscli_readline(UPSCONN_t *ups, char *buf, size_t buflen)
/* split upsname[@hostname[:port]] into separate components */
int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t *port)
{
char *s, tmp[SMALLBUF], *last = NULL;
char *sat, *ssc, tmp[SMALLBUF], *last = NULL;

/* paranoia */
if ((!buf) || (!upsname) || (!hostname) || (!port)) {
Expand All @@ -1634,10 +1634,11 @@ int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t
return -1;
}

s = strchr(tmp, '@');
sat = strchr(tmp, '@');
ssc = strchr(tmp, ':');

/* someone passed a "@hostname" string? */
if (s == tmp) {
if (sat == tmp) {
fprintf(stderr, "upscli_splitname: got empty upsname string\n");
return -1;
}
Expand All @@ -1653,13 +1654,20 @@ int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t
return -1;
}

/*
/*
fprintf(stderr, "upscli_splitname3: got buf='%s', tmp='%s', upsname='%s', possible hostname:port='%s'\n",
NUT_STRARG(buf), NUT_STRARG(tmp), NUT_STRARG(*upsname), NUT_STRARG((s ? s+1 : s)));
*/
NUT_STRARG(buf), NUT_STRARG(tmp), NUT_STRARG(*upsname), NUT_STRARG((sat ? sat+1 : sat)));
*/

/* only a upsname is specified, fill in defaults */
if (s == NULL) {
if (sat == NULL) {
if (ssc) {
/* TOTHINK: Consult isdigit(ssc+1) to shortcut
* `upsname:port` into `upsname@localhost:port`? */
fprintf(stderr, "upscli_splitname: port specified, but not a hostname\n");
return -1;
}

if ((*hostname = xstrdup("localhost")) == NULL) {
fprintf(stderr, "upscli_splitname: xstrdup failed\n");
return -1;
Expand All @@ -1670,12 +1678,12 @@ int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t
}

/* someone passed a "upsname@" string? */
if (!(*(s+1))) {
if (!(*(sat+1))) {
fprintf(stderr, "upscli_splitname: got the @ separator and then an empty hostname[:port] string\n");
return -1;
}

return upscli_splitaddr(s+1, hostname, port);
return upscli_splitaddr(sat+1, hostname, port);
}

/* split hostname[:port] into separate components */
Expand Down
2 changes: 1 addition & 1 deletion clients/upscmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void usage(const char *prog)
printf(" -p <password> set password for command authentication\n");
printf(" -w wait for the completion of command by the driver\n");
printf(" and return its actual result from the device\n");
printf(" -t <timeout> set a timeout when using -w (in seconds, default: %u)\n", DEFAULT_TRACKING_TIMEOUT);
printf(" -t <timeout> set a timeout when using -w (in seconds, default: %d)\n", DEFAULT_TRACKING_TIMEOUT);
printf("\n");
printf(" <ups> UPS identifier - <upsname>[@<hostname>[:<port>]]\n");
printf(" <command> Valid instant command - test.panel.start, etc.\n");
Expand Down
Loading

0 comments on commit b372400

Please sign in to comment.