diff --git a/NEWS.adoc b/NEWS.adoc
index 94d2db1340..ea0e64c5ef 100644
--- a/NEWS.adoc
+++ b/NEWS.adoc
@@ -40,12 +40,6 @@ https://github.com/networkupstools/nut/milestone/12
to patterns defined in link:docs/nut-names.txt[]
- common code:
- * Generally improved shell script portability (including `Makefile.am`
- embedded recipes) when mixing back-quotes and double-quotes. Namely,
- the classic Solaris `ksh` implementation (also used in current versions
- of Solaris and illumos based distributions) was strict about following
- (an older revision of) the POSIX standard here, and some use-cases
- misbehaved with our older script spelling. [issue #3196]
* Introduced `setproctag()` and `getproctag()` (see examples in `upsmon`)
to help track the log messages from massively-forking NUT daemons. [#3084]
* Extended with plural `checkprocnames()` and `compareprocnames()`,
@@ -85,12 +79,27 @@ https://github.com/networkupstools/nut/milestone/12
not-requested (e.g. do not start `upsd` in `MODE=netclient`), even though
the unit is nominally enabled; this should make packaging and providing
service pre-sets more simple. [issue #837, PR #3233]
- * Revised detection of (relative) paths to program and configuration files
- near the currently running program in NUT for Windows builds. [issues #3207,
- #3063, #3065, #3219]
* Fixed thread-safety of IP address printout in `libupsclient` method
- `upscli_tryconnect()` (practical bug seen in `nut-scanner` parallel scans).
- [issue #3234]
+ `upscli_tryconnect()` (practical bug seen in `nut-scanner` parallel scans).
+ [issue #3234]
+
+ - NUT for Windows specific updates:
+ * Revised detection of (relative) paths to program and configuration files
+ near the currently running program in NUT for Windows builds, including
+ limited support for UNC paths (ignoring a localhost `\\?\` prefix).
+ [issues #3207, #3063, #3065, #3219]
+ * Augmented WIN32 `nut.exe` launcher with `status` and `restart` actions,
+ and general ability to debug-log the activities during service management
+ operations. (Re-)registration of the "Network UPS Tools" service should
+ now populate a nice description of it. The `-U` (uninstall) action should
+ now also try to stop the service first. [PR #3235]
+ * Revised WIN32 `WSAStartup()` and registration of `atexit(WSACleanup)` to
+ only be done once per program (and cleanups to be always registered); this
+ impacts the C `libupsclient` and C++ `libnutclient` libraries (and so most
+ NUT clients and tools which use the former, and `nutconf` which uses the
+ latter), the `apcupsd` driver, `upsd` data server, and `nut-scanner` tool.
+ [PR #3237]
+ * Documented setup of Microsoft IIS to host the NUT CGI programs. [#3207]
- `asem`, `bestfortress`, `bestuferrups`, `bicker_ser`, `everups`, `metasys`,
`masterguard`, `mge-utalk`, `oneac`, `phoenixcontact_modbus`, `pijuice`,
@@ -201,12 +210,20 @@ https://github.com/networkupstools/nut/milestone/12
* `openups-hid` had `nobattery` definition inverted, causing alarms -- now
fixed to use the same mapping helper as other subdrivers. [issue #3246]
+ - `nut-scanner` tool updates:
+ * Fixed `nut-scanner` search for "simulation devices" to not use only the
+ built-in NUT configuration path on all platforms, but to also consider
+ `NUT_CONFPATH` and other fallback locations, like other code does.
+ [PR #3249]
+
- `upsd` data server updates:
* Sometimes "Data for UPS [X] is stale" and "UPS [X] data is no longer
stale" messages were logged in the same second, especially no busy
systems. Now we allow one more second on top of `MAXAGE` setting to
declare the device dead, just in case fractional/whole second rounding
comes into play and breaks things. [issue #661]
+ * Fixed `LISTEN *` handling for `upsd.exe` in NUT for Windows builds.
+ [PR #3237]
- `upsdrvctl` tool updates:
* Make use of `setproctag()` and `getproctag()` to report parent/child
@@ -243,10 +260,14 @@ several `FSD` notifications into one executed action. [PR #3097]
- `upsset` should now recognize `RANGE NUMBER` and `NUMBER` types. [#3164]
- `upsstats` tool updates:
- * Now has JSON output mode via `?json` (or `&json`) CGI query
- parameter. [issue #2524, PR #3171]
+ * Now has JSON output mode via `?json` (or `&json`) CGI query parameter.
+ New `@TREELINK_JSON@` keyword added and HTML templates updated to expose
+ these JSON documents when browsing. [issue #2524, PRs #3171, #3249]
* Handle `device.model` in addition to `ups.model` in upsstats HTML
templates. [#3180]
+ * Introduced a `@NUT_UPSSTATS_TEMPLATE@` command which the HTML template
+ files now MUST start with (safety check that we are reading a template).
+ [issue #3252, PR #3249]
- `upssched` tool updates:
* Previously in PR #2896 (NUT releases v2.8.3 and v2.8.4) the `UPSNAME` and
@@ -275,7 +296,7 @@ several `FSD` notifications into one executed action. [PR #3097]
* Revised info/error/warning/debug message emission so they go to `stderr`
and have a consistent look. Revised some typos along the way. [issue #3194]
- - `configure` script options:
+ - `configure` script updates:
* For ages, most recipes for building NUT had customized the `sysconfdir` to
be `/etc/nut`, which is not exactly the *system* configuration directory.
This is finally deprecated, with new `--with-confdir` configuration option
@@ -289,6 +310,18 @@ several `FSD` notifications into one executed action. [PR #3097]
most cases. A `--with-confdir-examples` option was also introduced, to
help distributions that place `*.conf.sample` files into docs or other
locations. [#3131]
+ * The `configure` script would now probe (if it can) the operating systems
+ for more user and group account names, such as `upsmon`, `nutmon`, `ups`,
+ `nut` (last hit wins, separately for user and groups accounts) settling
+ on one of those if detected instead of `nobody` (and optionally `nogroup`).
+ It would also warn if `nobody` or `nogroup` end up being used for a build.
+ [#3173]
+ * Default `PIDPATH` is now more strictly `/var/run`, unless building on a
+ system conforming to FHS-3.0 standard where that location is absent or
+ is a symlink, while `/run` exists and is a true directory. [#3099]
+ * Made default NUT CGI URI (used in HTML templates, which may be edited
+ later on a NUT deployment to customize for specific web server setup)
+ configurable `--with-cgi-uri`. [#3207]
* Introduced `--with-python{,2,3}-modules-dir` to specify PyNUT(Client)
module installation location (for module-named dir to be created under
it), if not bundling with NUT-Monitor UI app. By default the respective
@@ -303,6 +336,8 @@ several `FSD` notifications into one executed action. [PR #3097]
Default settings were changed from plain `auto` (allowing for multiple
`python*` interpreters and `site-package` locations to be used), to
prefer a `python3` if available, else `python2`, else `python`. [#1792]
+ * The `configure` script should now try harder to report specifically
+ the "purelib" location as `PYTHON*_SITE_PACKAGES`. [#1209]
* Streamlined handling of `--with-*` and `--enable-*` options using NUT 'm4'
macros; fixed reporting help for options whose defaults are evaluated.
[issue #3049, PR #3140]
@@ -315,25 +350,74 @@ several `FSD` notifications into one executed action. [PR #3097]
updated many help messages. The `configure` script logs should now clarify
where CFLAGS/LIBS/LDFLAGS values come from ('pkg-config', 'default', user
provided 'confargs' etc.) [#3140]
- * Added configure script options for 'libregex' tuning, just so it is on par
- with our other optional dependencies. [#3140]
+ * Added `configure` script options for 'libregex' tuning, just so that one
+ is on par with our other optional dependencies. [#3140]
* Changed `--enable-extapi-enphase` to not default to `auto` and then get
installed on every system capable of using it; this is a niche capability
for users of specific devices via a cloud portal. [follow-up to PR #2813
for issue #2807]
- - Fixed CI recipes for PyPI publication of PyNUT(Client) module to also
- include the source distribution (was posted for NUT v2.8.1 and v2.8.2
- tagged releases, but absent for v2.8.3 and v2.8.4). [#3056]
-
- - The `configure` script would now probe (if it can) the operating systems for
- more user and group account names, such as `upsmon`, `nutmon`, `ups`, `nut`
- (last hit wins, separately for user and groups accounts) settling on one of
- those if detected instead of `nobody` (and optionally `nogroup`). It would
- also warn if `nobody` or `nogroup` end up being used for a build. [#3173]
+ - Recipes, CI and helper script updates not classified above:
+ * Fixed CI recipes for PyPI publication of PyNUT(Client) module to also
+ include the source distribution (was posted for NUT v2.8.1 and v2.8.2
+ tagged releases, but absent for v2.8.3 and v2.8.4). [#3056]
+ * Updated `make spellcheck` to help avoid asciidoc admonition blocks with
+ visually invalid sentences (after rendering as a box in HTML or PDF). [#3077]
+ * Added a `make dist-docs` goal to generate, collect and tarball all document
+ types (`man`, `html-single`, `html-chunked`, `pdf`) that we may have enabled
+ for the current build configuration and available tooling. [#1400]
+ * Further developer workflow speedup with `make spellcheck-interactive-quick`
+ which should now not re-check source texts that were okay with the previous
+ dictionary contents, in case some new terms have to be added. [PRs #3186,
+ #2871]
+ * Introduced `make distcheck-completeness` goal to verify that our distribution
+ archives can exactly reproduce themselves. [#2829]
+ * Added a GitHub Actions CI job to generate, upload and recycle `make dist`
+ and `make dist-docs` tarballs so they are easier to obtain for people and
+ other CI systems (which might not want to follow a Git repository). Links
+ to these artifacts can be seen in workflow page (or its logs), and added
+ as a line in GitHub Checks list associated with a commit. Note that the
+ GitHub Action storage keeps artifacts for at most 90 days. [#1400, #2829]
+ * Revised CI and deliverable scripts, and Makefile recipes, to not use
+ the verbatim `grep -E` (loudly preferred by newer systems, but may be
+ absent on older ones) after all, nor use `egrep` (loudly disliked by
+ newer systems). Instead, use what `configure` script detected for the
+ generated files (or ones made from templates), and use a similar
+ detection in standalone scripts. Also revised the use of `grep -q`,
+ `id -u`, `diff -u`, etc. which are not ubiquitous, and of `test -e`
+ which is not only absent in some older shells, but can cause them to
+ abort processing the script immediately. Also the `if ! condition`
+ syntax is not supported everywhere (or the `!` operator generally).
+ [#3099, #1660]
+ * Generally improved shell script portability (including `Makefile.am`
+ embedded recipes) when mixing back-quotes and double-quotes. Namely,
+ the classic Solaris `ksh` implementation (also used in current versions
+ of Solaris and illumos based distributions) was strict about following
+ (an older revision of) the POSIX standard here, and some use-cases
+ misbehaved with our older script spelling. [issue #3196]
+ * Revised `tools/gitlog2version.sh` helper script (logic added into
+ a new `tools/semver-compare.sh`) with a mode to expand NUT SEMVER
+ components into wide zero-padded numbers, so it is easier to
+ alphanumerically compare different releases regardless of version
+ component lengths in digits (and differences in their amounts). You can
+ request an inverse operation with `NUT_VERSION_STRIP_LEADING_ZEROES=true`.
+ Added tests to cover different shell interpreter platforms (piggy-back
+ on the `tests/nut-driver-enumerator-test.sh` script), and made sure
+ that outputs of legacy-mode processing (with `NUT_VERSION_DEFAULT`
+ string provided by caller or saved in a tarball) are consistent with
+ git-mode. The new `tools/semver-compare.sh` helper can be used directly
+ to expand and strip version strings, sort and compare multiple versions
+ as one simple operation. [issue #3055, PRs #3213, #3217]
+ * Dropped the `compile` script from Git sources. It originates from automake
+ and is added to work area (if missing) during `autogen.sh` rituals anyway.
+ It is still distributed as part of `make dist` tarball. [#1209]
- - Updated `make spellcheck` to help avoid asciidoc admonition blocks with
- visually invalid sentences (after rendering as a box in HTML or PDF). [#3077]
+ - Upstreamed reference packaging recipes (DEB, RPM) from the 42ITy project
+ which can be used with OBS (Open Build Service by SUSE), both to support
+ end-user testing of NUT development, and to have a yet another NUT CI farm
+ player with a distinct opinion on code quality. Many of the changes listed
+ above happened thanks to this effort, and due to concerns raised by OBS
+ build agents with various Linux distributions. [#1209, #1316, #3144]
- Updated `docs/*.txt`: add asciidoc comments with links to nut-website
rendered contents of most interesting pages. [#3095]
@@ -341,74 +425,15 @@ several `FSD` notifications into one executed action. [PR #3097]
- HTML renditions of NUT man pages and books (or chunked chapters thereof)
now include the AnchorJS script to provide permalinks to sections. [#3185]
- - Added a `make dist-docs` goal to generate, collect and tarball all document
- types (man, html-single, html-chunked, pdf) that we may have enabled for the
- current build configuration and available tooling. [#1400]
-
- - Further developer workflow speedup with `make spellcheck-interactive-quick`
- which should now not re-check source texts that were okay with the previous
- dictionary contents, in case some new terms have to be added. [PRs #3186, #2871]
-
- - Added a GitHub Actions CI job to generate, upload and recycle `make dist`
- and `make dist-docs` tarballs so they are easier to obtain for people and
- other CI systems (which might not want to follow a Git repository). Links
- to these artifacts can be seen in workflow page (or its logs), and added
- as a line in GitHub Checks list associated with a commit. Note that the
- GitHub Action storage keeps artifacts for at most 90 days. [#1400, #2829]
-
- Source directory `data/html` was renamed to `data/htmlcgi` in order to
better reflect its contents and purpose, compared to documentation-oriented
- `html*` directories (and recipe variable names). This may impact some
- packaging recipes which do not rely on `make install` alone. [#3049]
-
- - Dropped the `compile` script from Git sources. It originates from automake
- and is added to work area (if missing) during `autogen.sh` rituals anyway.
- It is still distributed as part of `make dist` tarball. [#1209]
-
- - Default `PIDPATH` is now more strictly `/var/run`, unless building on a
- system conforming to FHS-3.0 standard where that location is absent or
- is a symlink, while `/run` exists and is a true directory. [#3099]
-
- - Augmented `nut.exe` launcher with `status` and `restart` actions, and
- general ability to debug-log the activities during service management
- operations. (Re-)registration of the "Network UPS Tools" service should
- now populate a nice description of it. The `-U` (uninstall) action should
- now also try to stop the service first. [PR #3235]
-
- - Fixed `LISTEN *` handling for `upsd.exe` in NUT for Windows builds. [PR #3237]
-
- - Revised WIN32 `WSAStartup()` and registration of `atexit(WSACleanup)` to
- only be done once per program (and cleanups to be always registered); this
- impacts the C `libupsclient` and C++ `libnutclient` libraries (and so most
- NUT clients and tools which use the former, and `nutconf` which uses the
- latter), the `apcupsd` driver, `upsd` data server, and `nut-scanner` tool.
- [PR #3237]
-
- - Revised CI and deliverable scripts, and Makefile recipes, to not use
- the verbatim `grep -E` (loudly preferred by newer systems, but may be
- absent on older ones) after all, nor use `egrep` (loudly disliked by
- newer systems). Instead, use what `configure` script detected for the
- generated files (or ones made from templates), and use a similar
- detection in standalone scripts. Also revised the use of `grep -q`,
- `id -u`, `diff -u`, etc. which are not ubiquitous, and of `test -e`
- which is not only absent in some older shells, but can cause them to
- abort processing the script immediately. Also the `if ! condition`
- syntax is not supported everywhere (or the `!` operator generally).
- [#3099, #1660]
-
- - Revised `tools/gitlog2version.sh` helper script (logic added into
- a new `tools/semver-compare.sh`) with a mode to expand NUT SEMVER
- components into wide zero-padded numbers, so it is easier to
- alphanumerically compare different releases regardless of version
- component lengths in digits (and differences in their amounts). You can
- request an inverse operation with `NUT_VERSION_STRIP_LEADING_ZEROES=true`.
- Added tests to cover different shell interpreter platforms (piggy-back
- on the `tests/nut-driver-enumerator-test.sh` script), and made sure
- that outputs of legacy-mode processing (with `NUT_VERSION_DEFAULT`
- string provided by caller or saved in a tarball) are consistent with
- git-mode. The new `tools/semver-compare.sh` helper can be used directly
- to expand and strip version strings, sort and compare multiple versions
- as one simple operation. [issue #3055, PRs #3213, #3217]
+ `html*` directories (and recipe variable names). The static HTML pages now
+ also suggest a NUT icon (installed from `docs/images`). This may impact some
+ packaging recipes which do not rely on `make install` alone. [#3049, #3249]
+
+ - Fixed man page naming for `nutdrv_siemens-sitop(.8)` (dash vs. underscore)
+ to match the driver program name. Follow-up from slightly botched renaming
+ in original contribution. [PR #545]
- The NUT Integration Testing suite (NIT) script, if started as `root`,
can now consult its run-time situation vs. `BUILTIN_RUN_AS_USER` and
@@ -416,23 +441,6 @@ several `FSD` notifications into one executed action. [PR #3097]
do not exist (e.g. running in a packaging build root), a different
value like "nobody" or "nogroup" would be defaulted for tests. [#1209]
- - Fixed man page naming for `nutdrv_siemens-sitop(.8)` (dash vs. underscore)
- to match the driver program name. Follow-up from slightly botched renaming
- in original contribution. [PR #545]
-
- - The `configure` script should now try harder to report specifically
- the "purelib" location as `PYTHON*_SITE_PACKAGES`. [#1209]
-
- - Introduce `make distcheck-completeness` goal to verify that our distribution
- archives can exactly reproduce themselves. [#2829]
-
- - Upstreamed reference packaging recipes (DEB, RPM) from the 42ITy project
- which can be used with OBS (Open Build Service by SUSE), both to support
- end-user testing of NUT development, and to have a yet another NUT CI farm
- player with a distinct opinion on code quality. Many of the changes listed
- above happened thanks to this effort, and due to concerns raised by OBS
- build agents with various Linux distributions. [#1209, #1316, #3144]
-
- Revised use of NUT macros for USB Vendor IDs listed in different drivers,
so the names would be better exposed in generated `udev.rules` and similar
files. [PR #3139]
diff --git a/UPGRADING.adoc b/UPGRADING.adoc
index 9ca1e7b572..fb5cfabfdb 100644
--- a/UPGRADING.adoc
+++ b/UPGRADING.adoc
@@ -50,6 +50,12 @@ Changes from 2.8.4 to 2.8.5
installed (and possibly customized) with the `*.html.sample` files delivered
by the new build. [PR #3180]
+- Introduced a `@NUT_UPSSTATS_TEMPLATE@` command which the NUT CGI template
+ files now MUST start with (safety check that we are reading a template).
+ While the delivered `upsstats*.html.sample` files would include the change,
+ ultimate `upsstats*.html` templates deployed for end-users MUST be updated.
+ [issue #3252, PR #3249]
+
- Dropped the `compile` script from Git sources. It originates from automake
and is added to work area (if missing) during `autogen.sh` rituals anyway
(as `make` says, `'automake --add-missing' can install 'compile'` when you
diff --git a/appveyor.yml b/appveyor.yml
index 2c3672b8ee..15aef8f564 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -106,6 +106,15 @@ build_script:
set MSYSTEM=MINGW64
REM Note: currently we save job time and do not install asciidoc/a2x
REM # --with-docs="man=auto html-single=auto html-chunked=no pdf=no"
+ REM The resulting configuration defaults to --prefix=/mingw{32,64}
+ REM as appropriate for the platform, which ends up as a subdirectory
+ REM under DESTDIR when we `make install` later, and in our 7z archive.
+ REM The builds are relocatable however, so end-users can extract to
+ REM e.g. "C:\Program Files\NUT" and forfeit "mingwXX" part, probably,
+ REM but this can complicate automatic relative directory resolution
+ REM to find "nearby" program or configuration files (see common.c
+ REM for current implementation). Hard-coded fallback strings may
+ REM end up getting used in those cases.
C:\msys64\usr\bin\bash -lc 'date -u; PATH="/mingw64/bin:$PATH" CI_SKIP_CHECK=true CANBUILD_WITH_LIBMODBUS_USB=yes ./ci_build.sh --with-docs=no'
diff --git a/clients/cgilib.c b/clients/cgilib.c
index 6591a11686..687eed8c5b 100644
--- a/clients/cgilib.c
+++ b/clients/cgilib.c
@@ -116,42 +116,120 @@ void extractcgiargs(void)
void extractpostargs(void)
{
- char buf[SMALLBUF], *ptr, *cleanval;
- int ch;
+ char buf[SMALLBUF], *ptr, *cleanval, *server_software = NULL;
+ int ch, content_length = -1, bytes_seen = 0;
+ size_t buflen;
+
+ /* First, see if there's anything waiting...
+ * the server may not close STDIN properly
+ * or somehow delay opening/populating it. */
+#ifndef WIN32
+ int selret;
+ fd_set fds;
+ struct timeval tv;
+
+ FD_ZERO(&fds);
+ FD_SET(STDIN_FILENO, &fds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 250000; /* wait for up to 250ms for a POST query to come */
+
+ selret = select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
+ if (selret <= 0) {
+#else
+ HANDLE hSTDIN = GetStdHandle(STD_INPUT_HANDLE);
+ DWORD selret = WaitForSingleObject(hSTDIN, 250);
+ if (selret != WAIT_OBJECT_0) { /* or == WAIT_TIMEOUT ? */
+#endif /* WIN32 */
+ upsdebug_with_errno(1, "%s: no stdin is waiting (%" PRIiMAX ")
", __func__, (intmax_t)selret);
+ return;
+ }
- ch = fgetc(stdin);
buf[0] = '\0';
- while (ch != EOF) {
- if (ch == '&') {
+ /* Does the web server tell us how much it sent
+ * (and might keep the channel open... indefinitely)? */
+ ptr = getenv("CONTENT_LENGTH");
+ if (ptr) {
+ content_length = atoi(ptr);
+ }
+
+ ptr = getenv("SERVER_SOFTWARE");
+ if (ptr) {
+ server_software = ptr;
+ } else {
+ server_software = "";
+ }
+
+ if (content_length > 0 && strstr(server_software, "IIS")) {
+ /* Our POSTs end with a newline, and that one never arrives
+ * (reads hang), possibly buffered output from IIS?
+ * Our own setmode() in e.g. upsset.c does not help.
+ * So upsset.c ends each FORM with do_hidden_sentinel()
+ * to sacrifice a few bytes we would not use.
+ */
+ upsdebugx(3, "%s: truncating expected content length on IIS
", __func__);
+ content_length--;
+ }
+ upsdebugx(3, "%s: starting to read %d POSTed bytes on server '%s'
", __func__, content_length, server_software);
+
+ ch = fgetc(stdin);
+ upsdebugx(6, "%s: got char: '%c' (%d, 0x%02X)
", __func__, ch, ch, (unsigned int)ch);
+
+ if (ch == EOF) {
+ bytes_seen++;
+ upsdebugx(3, "%s: got immediate EOF in stdin
", __func__);
+ } else while(1) {
+ bytes_seen++;
+ if (ch == '&' || ch == EOF || (content_length >= 0 && bytes_seen >= content_length)) {
+ buflen = strlen(buf);
+ upsdebugx(1, "%s: collected a chunk of %" PRIuSIZE " bytes on stdin: %s
",
+ __func__, buflen, buf);
ptr = strchr(buf, '=');
- if (!ptr)
+ if (!ptr) {
+ upsdebugx(3, "%s: parsearg('%s', '')
", __func__, buf);
parsearg(buf, "");
- else {
+ } else {
*ptr++ = '\0';
cleanval = unescape(ptr);
+ upsdebugx(3, "%s: parsearg('%s', '%s')
", __func__, buf, cleanval);
parsearg(buf, cleanval);
free(cleanval);
}
buf[0] = '\0';
+
+ if (ch == EOF || (content_length >= 0 && bytes_seen >= content_length))
+ break; /* end the loop */
}
else
snprintfcat(buf, sizeof(buf), "%c", ch);
+#ifndef WIN32
+ /* Must re-init every time when looping (array is changed by select method) */
+ FD_ZERO(&fds);
+ FD_SET(STDIN_FILENO, &fds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 250000; /* wait for up to 250ms for a POST response */
+
+ selret = select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
+ if (selret <= 0) {
+#else
+ selret = WaitForSingleObject(hSTDIN, 250);
+ if (selret != WAIT_OBJECT_0) { /* or == WAIT_TIMEOUT ? */
+#endif
+ /* We do not always get EOF, so assume the input stream stopped */
+ upsdebug_with_errno(1, "%s: timed out waiting for an stdin byte (%" PRIiMAX ")
", __func__, (intmax_t)selret);
+ break;
+ }
+
+ fflush(stderr);
ch = fgetc(stdin);
- }
+ upsdebugx(6, "%s: got char: '%c' (%d, 0x%02X)
", __func__, ch, ch, (unsigned int)ch);
+ if (ch == EOF)
+ upsdebugx(3, "%s: got proper stdin EOF
", __func__);
+ upsdebugx(6, "%s: processed %d bytes with %d expected incoming content length on server '%s'
", __func__, bytes_seen, content_length, server_software);
+ } /* end of infinite loop */
- if (strlen(buf) != 0) {
- ptr = strchr(buf, '=');
- if (!ptr)
- parsearg(buf, "");
- else {
- *ptr++ = '\0';
- cleanval = unescape(ptr);
- parsearg(buf, cleanval);
- free(cleanval);
- }
- }
+ upsdebugx(3, "%s: processed %d bytes with %d incoming content length
", __func__, bytes_seen, content_length);
}
/* called for fatal errors in parseconf like malloc failures */
diff --git a/clients/upsimage.c b/clients/upsimage.c
index a74b8f4d0c..909841704f 100644
--- a/clients/upsimage.c
+++ b/clients/upsimage.c
@@ -614,12 +614,38 @@ static int get_var(const char *var, char *buf, size_t buflen)
int main(int argc, char **argv)
{
- char str[SMALLBUF];
+ char str[SMALLBUF], *s;
int i, min, nom, max;
double var = 0;
+
+#ifdef WIN32
+ /* Required ritual before calling any socket functions */
+ static WSADATA WSAdata;
+ static int WSA_Started = 0;
+ if (!WSA_Started) {
+ WSAStartup(2, &WSAdata);
+ atexit((void(*)(void))WSACleanup);
+ WSA_Started = 1;
+ }
+
+ /* Avoid binary output conversions, e.g.
+ * mangling what looks like CRLF on WIN32 */
+ setmode(STDOUT_FILENO, O_BINARY);
+#endif
+
NUT_UNUSED_VARIABLE(argc);
NUT_UNUSED_VARIABLE(argv);
+ /* NOTE: Caller must `export NUT_DEBUG_LEVEL` to see debugs for upsc
+ * and NUT methods called from it. This line aims to just initialize
+ * the subsystem, and set initial timestamp. Debugging the client is
+ * primarily of use to developers, so is not exposed via `-D` args.
+ */
+ s = getenv("NUT_DEBUG_LEVEL");
+ if (s && str_to_int(s, &i, 10) && i > 0) {
+ nut_debug_level = i;
+ }
+
extractcgiargs();
upscli_init_default_connect_timeout(NULL, NULL, UPSCLI_DEFAULT_CONNECT_TIMEOUT);
diff --git a/clients/upsset.c b/clients/upsset.c
index ebfb2a5e91..03e10b504f 100644
--- a/clients/upsset.c
+++ b/clients/upsset.c
@@ -170,6 +170,14 @@ static void do_hidden(const char *next)
next);
}
+static void do_hidden_sentinel(void)
+{
+ /* MS IIS tends to not close CGI STDIN and not serve the last byte(s)
+ * but just hangs at fgets(), so we truncate the inputs in cgilib,
+ * and add a dummy entry here that we can afford to lose in the end */
+ printf("\n");
+}
+
/* generate SELECT chooser from hosts.conf entries */
static void upslist_arg(size_t numargs, char **arg)
{
@@ -202,7 +210,7 @@ static void do_pickups(const char *currfunc)
snprintf(hostfn, sizeof(hostfn), "%s/hosts.conf", confpath());
- printf("