Skip to content

Commit 454fc01

Browse files
authored
Merge 3da9664 into b30d183
2 parents b30d183 + 3da9664 commit 454fc01

29 files changed

+683
-70
lines changed

NEWS.adoc

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,31 @@ This requirement compromises usability of `make distcheck` on platforms without
403403
* Updated `upsmon` client with setting to toggle whether an `ALARM`
404404
status can prompt the UPS to become critical in certain situations.
405405
406-
- New `libupsclient` API methods added, `upscli_str_add_unique_token()` and
407-
`upscli_str_contains_token()`, to help C NUT clients process `ups.status` and
408-
similarly structured strings same way as NUT core code base. [#2852, #2859]
406+
- New `libupsclient` API methods added:
407+
* `upscli_str_add_unique_token()` and `upscli_str_contains_token()`,
408+
to help C NUT clients process `ups.status` and similarly structured
409+
strings same way as NUT core code base. [#2852, #2859]
410+
* `upscli_connect()` was previously always blocking; now this is sort of
411+
optional, with new `upscli_set_default_connect_timeout()` able to change
412+
the implicit timeout from default zero (meaning blocking) to a positive
413+
value (or back to 0). Several NUT clients (`upsc`, `upscmd`, `upsrw`,
414+
`upslog`, `upsmon`, `upsimage`, `upsset` and `upsstats`) were updated
415+
to default with a 10-second timeout in case of name resolution lags or
416+
unresponsive hosts (notably a problem with `upsmon` contacting many
417+
remote systems at once). The `NUT_DEFAULT_CONNECT_TIMEOUT` environment
418+
variable can be used to modify this timeout for all clients. Further
419+
new methods here include `upscli_get_default_connect_timeout()` to
420+
retrieve a copy of the last stored timeout, and
421+
`upscli_init_default_connect_timeout()` to initialize the value from
422+
a number of sources with different priorities. [#2847]
423+
* Symbols exported from `libupsclient` now include `nut_debug_level*` so
424+
that NUT clients can be usefully debugged (e.g. using `NUT_DEBUG_LEVEL`
425+
environment variable). [#2847]
426+
427+
- Several NUT clients including `upscmd`, `upsrw`, `upsimage`, `upsset`,
428+
`upsstats`, and `upslog` (during reconnection), did not `UPSCLI_CONN_TRYSSL`
429+
so went plaintext even when secure connections were possible. Fixed to at
430+
least try being secure, same way as `upsc` does for a long time. [#2847]
409431
410432
- upsmon:
411433
* it was realized that the `POWERDOWNFLAG` must be explicitly set in the

UPGRADING.adoc

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,30 @@ Changes from 2.8.2 to 2.8.3
7777
on having those for translations to be found -- this should be reflected
7878
in OS packaging recipes as well. [#2845]
7979
80-
- New `libupsclient` API methods added, `upscli_str_add_unique_token()` and
81-
`upscli_str_contains_token()`, to help C NUT clients process `ups.status` and
82-
similarly structured strings same way as NUT core code base. [#2852, #2859]
80+
- New `libupsclient` API methods added:
81+
* `upscli_str_add_unique_token()` and `upscli_str_contains_token()`,
82+
to help C NUT clients process `ups.status` and similarly structured
83+
strings same way as NUT core code base. [#2852, #2859]
84+
* `upscli_set_default_connect_timeout()` to modify the internal timeout
85+
used by `upscli_connect()` (default 0 still means blocking connections,
86+
positive values should time-limit the connection attempts), and
87+
`upscli_get_default_connect_timeout()` to retrieve its copy. [#2847]
88+
89+
- Standard NUT clients including `upsc`, `upscmd`, `upsrw`, `upslog`, `upsmon`,
90+
`upsimage`, `upsset` and `upsstats`) were updated to default with a 10-second
91+
connection establishment timeout in case of name resolution lags or
92+
unresponsive hosts (notably a problem with `upsmon` contacting many remote
93+
systems at once). This may potentially impact NUT deployments which somehow
94+
relied on the blocking behavior of these clients; you can use the
95+
`NUT_DEFAULT_CONNECT_TIMEOUT` environment variable to fix this. [#2847]
96+
97+
- Several NUT clients including `upscmd`, `upsrw`, `upsimage`, `upsset`,
98+
`upsstats`, and `upslog` (during reconnection), did not `UPSCLI_CONN_TRYSSL`
99+
so went plaintext even when secure connections were possible. Fixed to at
100+
least try being secure, same way as `upsc` does for a long time. This may
101+
cause console or log messages when SSL can not be initialized, you can use
102+
the `NUT_QUIET_INIT_SSL` environment variable to suppress them where the
103+
cryptography is known to be not set up, so the warnings bring no value. [#2847]
83104
84105
- `lib/*.pc.in`: propagate `-R/PATH` (or equivalent -- as detected by the
85106
`configure` script for the currently used compiler and linker toolkits)

clients/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ endif WITH_SSL
113113

114114
# libupsclient version information
115115
libupsclient_la_LDFLAGS = -version-info 6:2:0
116-
libupsclient_la_LDFLAGS += -export-symbols-regex '^(upscli_)'
116+
libupsclient_la_LDFLAGS += -export-symbols-regex '^(upscli_|nut_debug_level)'
117+
#|s_upsdebug|fatalx|fatal_with_errno|xcalloc|xbasename|print_banner_once)'
117118
if HAVE_WINDOWS
118119
# Many versions of MingW seem to fail to build non-static DLL without this
119120
libupsclient_la_LDFLAGS += -no-undefined

clients/upsc.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
44
Copyright (C) 2012 Arnaud Quette <arnaud.quette@free.fr>
5-
Copyright (C) 2020-2024 Jim Klimov <jimklimov+nut@gmail.com>
5+
Copyright (C) 2020-2025 Jim Klimov <jimklimov+nut@gmail.com>
66
77
This program is free software; you can redistribute it and/or modify
88
it under the terms of the GNU General Public License as published by
@@ -31,6 +31,9 @@
3131
#include "nut_stdint.h"
3232
#include "upsclient.h"
3333

34+
/* network timeout for initial connection, in seconds */
35+
#define UPSCLI_DEFAULT_CONNECT_TIMEOUT "10"
36+
3437
static char *upsname = NULL, *hostname = NULL;
3538
static UPSCONN_t *ups = NULL;
3639

@@ -59,6 +62,8 @@ static void usage(const char *prog)
5962

6063
printf("\nCommon arguments:\n");
6164
printf(" -V - display the version of this software\n");
65+
printf(" -W <secs> - network timeout for initial connections (default: %s)\n",
66+
UPSCLI_DEFAULT_CONNECT_TIMEOUT);
6267
printf(" -h - display this help text\n");
6368

6469
nut_report_config_flags();
@@ -223,6 +228,7 @@ int main(int argc, char **argv)
223228
uint16_t port;
224229
int varlist = 0, clientlist = 0, verbose = 0;
225230
const char *prog = xbasename(argv[0]);
231+
const char *net_connect_timeout = NULL;
226232
char *s = NULL;
227233

228234
/* NOTE: Caller must `export NUT_DEBUG_LEVEL` to see debugs for upsc
@@ -236,7 +242,7 @@ int main(int argc, char **argv)
236242
}
237243
upsdebugx(1, "Starting NUT client: %s", prog);
238244

239-
while ((i = getopt(argc, argv, "+hlLcV")) != -1) {
245+
while ((i = getopt(argc, argv, "+hlLcVW:")) != -1) {
240246

241247
switch (i)
242248
{
@@ -247,6 +253,7 @@ int main(int argc, char **argv)
247253
fallthrough_case_l:
248254
varlist = 1;
249255
break;
256+
250257
case 'c':
251258
clientlist = 1;
252259
break;
@@ -258,13 +265,22 @@ int main(int argc, char **argv)
258265
nut_report_config_flags();
259266
exit(EXIT_SUCCESS);
260267

268+
case 'W':
269+
net_connect_timeout = optarg;
270+
break;
271+
261272
case 'h':
262273
default:
263274
usage(prog);
264275
exit(EXIT_SUCCESS);
265276
}
266277
}
267278

279+
if (upscli_init_default_connect_timeout(net_connect_timeout, NULL, UPSCLI_DEFAULT_CONNECT_TIMEOUT) < 0) {
280+
fatalx(EXIT_FAILURE, "Error: invalid network timeout: %s",
281+
net_connect_timeout);
282+
}
283+
268284
argc -= optind;
269285
argv += optind;
270286

0 commit comments

Comments
 (0)