Skip to content

Commit 322a430

Browse files
authored
Merge pull request #3240 from jimklimov/FTY-remerge-20251231
Merge remote-tracking branch 'upstream/master' into FTY as of 20251231
2 parents 78177d5 + 3a5802b commit 322a430

File tree

27 files changed

+1908
-290
lines changed

27 files changed

+1908
-290
lines changed

Makefile.am

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,29 +1623,34 @@ install-win-bundle-thirdparty:
16231623
if test -n "$$ARCH" ; then export ARCH ; fi ; \
16241624
DESTDIR='$(DESTDIR)' ; export DESTDIR ; \
16251625
( cd '$(DESTDIR)' || exit ; \
1626-
GREP=$(GREP)' EGREP='$(EGREP)' \
1626+
GREP='$(GREP)' EGREP='$(EGREP)' \
16271627
DESTDIR="" '$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
16281628
| while read D ; do \
1629+
BD="`basename \"$$D\"`" ; \
1630+
if test -e './$(bindir)/'"$$BD" && diff './$(bindir)/'"$$BD" "$$D" 2>/dev/null >/dev/null ; then \
1631+
echo " DLL->bin $$D : skip (already installed there)" 2>&1 ; \
1632+
continue ; \
1633+
fi ; \
16291634
echo " DLL->bin $$D" 2>&1 ; \
16301635
cp -pf "$$D" './$(bindir)/' ; \
16311636
done ; \
16321637
) || exit ; \
16331638
( if test x"$(bindir)" = x"$(sbindir)" ; then exit 0 ; fi ; \
16341639
cd '$(DESTDIR)/$(sbindir)' || exit ; \
1635-
GREP=$(GREP)' EGREP='$(EGREP)' \
1640+
GREP='$(GREP)' EGREP='$(EGREP)' \
16361641
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
16371642
| while read D ; do \
1638-
echo " DLL->sbin $$D" 2>&1 ; \
1643+
echo " DLL->sbin $$D (symlink from bindir)" 2>&1 ; \
16391644
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
16401645
done ; \
16411646
) || exit ; \
16421647
( if test x"$(driverexecdir)" = x"$(bindir)" ; then exit 0 ; fi ; \
16431648
if test x"$(driverexecdir)" = x"$(sbindir)" ; then exit 0 ; fi ; \
16441649
cd '$(DESTDIR)/$(driverexecdir)' || exit ; \
1645-
GREP=$(GREP)' EGREP='$(EGREP)' \
1650+
GREP='$(GREP)' EGREP='$(EGREP)' \
16461651
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
16471652
| while read D ; do \
1648-
echo " DLL->drv $$D" 2>&1 ; \
1653+
echo " DLL->drv $$D (symlink from bindir)" 2>&1 ; \
16491654
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
16501655
done ; \
16511656
) || exit ; \
@@ -1654,10 +1659,10 @@ install-win-bundle-thirdparty:
16541659
if test x"$(cgiexecdir)" = x"$(sbindir)" ; then exit 0 ; fi ; \
16551660
if test x"$(driverexecdir)" = x"$(cgiexecdir)" ; then exit 0 ; fi ; \
16561661
cd '$(DESTDIR)/$(cgiexecdir)' || exit ; \
1657-
GREP=$(GREP)' EGREP='$(EGREP)' \
1662+
GREP='$(GREP)' EGREP='$(EGREP)' \
16581663
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
16591664
| while read D ; do \
1660-
echo " DLL->cgi $$D" 2>&1 ; \
1665+
echo " DLL->cgi $$D (symlink from bindir)" 2>&1 ; \
16611666
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
16621667
done ; \
16631668
) || exit ; \
@@ -1666,10 +1671,10 @@ install-win-bundle-thirdparty:
16661671
if test x"$(libexecdir)" = x"$(driverexecdir)" ; then exit 0 ; fi ; \
16671672
if test x"$(libexecdir)" = x"$(cgiexecdir)" ; then exit 0 ; fi ; \
16681673
cd '$(DESTDIR)/$(libexecdir)' || exit ; \
1669-
GREP=$(GREP)' EGREP='$(EGREP)' \
1674+
GREP='$(GREP)' EGREP='$(EGREP)' \
16701675
'$(abs_top_srcdir)/scripts/Windows/dllldd.sh' dllldddir . \
16711676
| while read D ; do \
1672-
echo " DLL->libexec $$D" 2>&1 ; \
1677+
echo " DLL->libexec $$D (symlink from bindir)" 2>&1 ; \
16731678
ln -f '$(DESTDIR)/$(bindir)'/"`basename \"$$D\"`" ./ ; \
16741679
done ; \
16751680
) || exit

NEWS.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ https://github.com/networkupstools/nut/milestone/12
8383
* Revised detection of (relative) paths to program and configuration files
8484
near the currently running program in NUT for Windows builds. [issues #3207,
8585
#3063, #3065, #3219]
86+
* Fixed thread-safety of IP address printout in `libupsclient` method
87+
`upscli_tryconnect()` (practical bug seen in `nut-scanner` parallel scans).
88+
[issue #3234]
8689

8790
- `asem`, `bestfortress`, `bestuferrups`, `bicker_ser`, `everups`, `metasys`,
8891
`masterguard`, `mge-utalk`, `oneac`, `phoenixcontact_modbus`, `pijuice`,
@@ -98,6 +101,10 @@ https://github.com/networkupstools/nut/milestone/12
98101
- Introduced a new NUT driver named `meanwell_ntu` which provides support for
99102
the Mean Well NTU series hybrid inverter and UPS units. [PR #3206]
100103

104+
- Introduced a new NUT driver named `must_ep2000pro` which provides support
105+
for the MUST EP2000Pro compatible, line-interactive UPS models which talk
106+
serial-protocol modbus protocol. [PR #3228]
107+
101108
- `nhs_ser` driver updates:
102109
* Driver source code includes a table to map baud rates (defined by the OS
103110
as C macros) to numbers and strings more useful to the driver program.
@@ -355,6 +362,21 @@ several `FSD` notifications into one executed action. [PR #3097]
355362
system conforming to FHS-3.0 standard where that location is absent or
356363
is a symlink, while `/run` exists and is a true directory. [#3099]
357364

365+
- Augmented `nut.exe` launcher with `status` and `restart` actions, and
366+
general ability to debug-log the activities during service management
367+
operations. (Re-)registration of the "Network UPS Tools" service should
368+
now populate a nice description of it. The `-U` (uninstall) action should
369+
now also try to stop the service first. [PR #3235]
370+
371+
- Fixed `LISTEN *` handling for `upsd.exe` in NUT for Windows builds. [PR #3237]
372+
373+
- Revised WIN32 `WSAStartup()` and registration of `atexit(WSACleanup)` to
374+
only be done once per program (and cleanups to be always registered); this
375+
impacts the C `libupsclient` and C++ `libnutclient` libraries (and so most
376+
NUT clients and tools which use the former, and `nutconf` which uses the
377+
latter), the `apcupsd` driver, `upsd` data server, and `nut-scanner` tool.
378+
[PR #3237]
379+
358380
- Revised CI and deliverable scripts, and Makefile recipes, to not use
359381
the verbatim `grep -E` (loudly preferred by newer systems, but may be
360382
absent on older ones) after all, nor use `egrep` (loudly disliked by

UPGRADING.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Changes from 2.8.4 to 2.8.5
6363
usually override `--with-pidpath` anyway to provide a dedicated location
6464
for NUT `root`-owned daemon PID files. [#3099]
6565
66+
- The autoconf managed macro for `--with-port` option was renamed from plain
67+
`PORT` to less ambiguous `NUT_PORT` to avoid potential conflicts with any
68+
third-party code. If anyone did use this macro in their custom builds or
69+
integrations, some renaming (or stubbed definitions to the effect of
70+
`PORT=NUT_PORT`) may be needed. [#3238]
71+
6672
- In drivers using the common `main.c` and `main.h` framework, introduced
6773
a `void upsdrv_tweak_prognames(void)` required method (may be no-op) to
6874
optionally tweak `prognames[]` entries now that there is certain support

clients/nutclient.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,14 @@ void Socket::connect(const std::string& host, uint16_t port)
285285
HANDLE event = NULL;
286286
unsigned long argp;
287287

288-
WSADATA WSAdata;
289-
WSAStartup(2,&WSAdata);
288+
/* Required ritual before calling any socket functions */
289+
static WSADATA WSAdata;
290+
static int WSA_Started = 0;
291+
if (!WSA_Started) {
292+
WSAStartup(2, &WSAdata);
293+
atexit((void(*)(void))WSACleanup);
294+
WSA_Started = 1;
295+
}
290296
#endif /* WIN32 */
291297

292298
_sock = INVALID_SOCKET;
@@ -794,7 +800,7 @@ bool Client::hasFeature(const Feature& feature)
794800
TcpClient::TcpClient():
795801
Client(),
796802
_host("localhost"),
797-
_port(3493),
803+
_port(NUT_PORT),
798804
_timeout(0),
799805
_socket(new internal::Socket)
800806
{

clients/nutclient.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@
3333

3434
/* See include/common.h for details behind this */
3535
#ifndef NUT_UNUSED_VARIABLE
36-
#define NUT_UNUSED_VARIABLE(x) (void)(x)
36+
# define NUT_UNUSED_VARIABLE(x) (void)(x)
37+
#endif
38+
39+
/* Should be defined via autoconf in include/config.h -
40+
* if that is included earlier by the program code.
41+
* If not - got a fallback here:
42+
*/
43+
#ifndef NUT_PORT
44+
# define NUT_PORT 3493
3745
#endif
3846

3947
namespace nut
@@ -389,15 +397,15 @@ class TcpClient : public Client
389397
* \param host Server host name.
390398
* \param port Server port.
391399
*/
392-
TcpClient(const std::string& host, uint16_t port = 3493);
400+
TcpClient(const std::string& host, uint16_t port = NUT_PORT);
393401
~TcpClient() override;
394402

395403
/**
396404
* Connect it to the specified server.
397405
* \param host Server host name.
398406
* \param port Server port.
399407
*/
400-
void connect(const std::string& host, uint16_t port = 3493);
408+
void connect(const std::string& host, uint16_t port = NUT_PORT);
401409

402410
/**
403411
* Connect to the server.

clients/upsclient.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,16 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, uint16_t port, int flags
10191019
HANDLE event = NULL;
10201020
unsigned long argp;
10211021

1022-
WSADATA WSAdata;
1023-
WSAStartup(2,&WSAdata);
1022+
/* Required ritual before calling any socket functions */
1023+
static WSADATA WSAdata;
1024+
static int WSA_Started = 0;
1025+
if (!WSA_Started) {
1026+
WSAStartup(2, &WSAdata);
1027+
atexit((void(*)(void))WSACleanup);
1028+
WSA_Started = 1;
1029+
}
10241030
#endif /* WIN32 */
1031+
10251032
if (!ups) {
10261033
return -1;
10271034
}
@@ -1164,9 +1171,11 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, uint16_t port, int flags
11641171
ups->upserror == UPSCLI_ERR_CONNFAILURE &&
11651172
ups->syserrno == ETIMEDOUT
11661173
) {
1167-
const char *addrstr = inet_ntopAI(ai);
1174+
const char *addrstr = xinet_ntopAI(ai);
11681175
upslogx(LOG_WARNING, "%s: Connection to host timed out: '%s'",
11691176
__func__, (addrstr && *addrstr) ? addrstr : NUT_STRARG(host));
1177+
if (addrstr)
1178+
free((char*)addrstr);
11701179
break;
11711180
}
11721181
continue;
@@ -1694,7 +1703,7 @@ int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t
16941703
return -1;
16951704
}
16961705

1697-
*port = PORT;
1706+
*port = NUT_PORT;
16981707
return 0;
16991708
}
17001709

@@ -1750,7 +1759,7 @@ int upscli_splitaddr(const char *buf, char **hostname, uint16_t *port)
17501759

17511760
/* no port specified, use default */
17521761
if (((s = strtok_r(NULL, "\0", &last)) == NULL) || (*s != ':')) {
1753-
*port = PORT;
1762+
*port = NUT_PORT;
17541763
return 0;
17551764
}
17561765
} else {
@@ -1763,7 +1772,7 @@ int upscli_splitaddr(const char *buf, char **hostname, uint16_t *port)
17631772

17641773
/* no port specified, use default */
17651774
if (s == NULL) {
1766-
*port = PORT;
1775+
*port = NUT_PORT;
17671776
return 0;
17681777
}
17691778
}

0 commit comments

Comments
 (0)