Skip to content

Commit

Permalink
drivers/dummy-ups.c, docs/man/dummy-ups.txt, NEWS.adoc: introduce rep…
Browse files Browse the repository at this point in the history
…eater_disable_strict_start config option

Signed-off-by: desertwitch <[email protected]>
  • Loading branch information
desertwitch committed Oct 26, 2023
1 parent c92cdc8 commit af2d690
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
6 changes: 6 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ as part of https://github.com/networkupstools/nut/issues/1410 solution.
commits to apcupsd sources were in 2017 (with last release 3.14.14 in
May 2016): https://sourceforge.net/p/apcupsd/svn/HEAD/tree/

- dummy-ups:
* added an `repeater_disable_strict_start` option to disable the driver
exiting upon encountering any kind of error at startup (as repeater).
This option should allow for collective `upsdrvctl` startup despite
individual target UPS to be repeated or `upsd` not having come up yet.

- NUT for Windows:
* Ability to build NUT for Windows, last tackled with a branch based on
NUT v2.6.5 a decade ago, has been revived with the 2.8.x era codebase [#5].
Expand Down
7 changes: 6 additions & 1 deletion docs/man/dummy-ups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ second), independently of (and/or in addition to) any `TIMER` keywords.
Repeater Mode
~~~~~~~~~~~~~

In this context, `port` in the `ups.conf` block is the name of a remote UPS,
In this context, `port` in the `ups.conf` block is the name of the target UPS,
using the NUT format, i.e.:

<upsname>@<hostname>[:<port>]
Expand All @@ -195,6 +195,11 @@ bit between data-requesting cycles (currently this delay is hardcoded to one
second), so propagation of data updates available to a remote `upsd` may lag
by this much.

Beware that any error encountered at repeater mode startup (e.g. when not all
target UPS to be repeated or `upsd` instances are connectable yet) will cause
*dummy-ups* driver to terminate prematurely. This behaviour can be changed by
setting the `repeater_disable_strict_start` flag, making such errors non-fatal.

INTERACTION
-----------

Expand Down
35 changes: 32 additions & 3 deletions drivers/dummy-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "dummy-ups.h"

#define DRIVER_NAME "Device simulation and repeater driver"
#define DRIVER_VERSION "0.17"
#define DRIVER_VERSION "0.18"

/* driver description structure */
upsdrv_info_t upsdrv_info =
Expand Down Expand Up @@ -111,6 +111,9 @@ static char *client_upsname = NULL, *hostname = NULL;
static UPSCONN_t *ups = NULL;
static uint16_t port;

/* repeater mode parameters */
static int repeater_disable_strict_start = 0;

/* Driver functions */

void upsdrv_initinfo(void)
Expand Down Expand Up @@ -156,7 +159,17 @@ void upsdrv_initinfo(void)
ups = xmalloc(sizeof(*ups));
if (upscli_connect(ups, hostname, port, UPSCLI_CONN_TRYSSL) < 0)
{
upslogx(LOG_ERR, "Error: %s", upscli_strerror(ups));
if(repeater_disable_strict_start == 1)
{
upslogx(LOG_WARNING, "Warning: %s", upscli_strerror(ups));
}
else
{
fatalx(EXIT_FAILURE, "Error: %s. "
"Any errors encountered starting the repeater mode result in driver termination, "
"perhaps you want to set the 'repeater_disable_strict_start' option?"
, upscli_strerror(ups));
}
}
else
{
Expand All @@ -169,7 +182,18 @@ void upsdrv_initinfo(void)
{
fatalx(EXIT_FAILURE, "Error: upsd is too old to support this query");
}
upslogx(LOG_ERR, "Error: %s", upscli_strerror(ups));

if(repeater_disable_strict_start == 1)
{
upslogx(LOG_WARNING, "Warning: %s", upscli_strerror(ups));
}
else
{
fatalx(EXIT_FAILURE, "Error: %s. "
"Any errors encountered starting the repeater mode result in driver termination, "
"perhaps you want to set the 'repeater_disable_strict_start' option?"
, upscli_strerror(ups));
}
}
/* FIXME: commands and settable variable! */
break;
Expand Down Expand Up @@ -387,6 +411,7 @@ void upsdrv_help(void)
void upsdrv_makevartable(void)
{
addvar(VAR_VALUE, "mode", "Specify mode instead of guessing it from port value (dummy = dummy-loop, dummy-once, repeater)"); /* meta */
addvar(VAR_FLAG, "repeater_disable_strict_start", "Do not terminate the driver encountering errors when starting the repeater mode");
}

void upsdrv_initups(void)
Expand Down Expand Up @@ -521,6 +546,10 @@ void upsdrv_initups(void)
upsdebugx(2, "Located %s for device simulation data: %s", device_path, fn);
}
}
if (testvar("repeater_disable_strict_start"))
{
repeater_disable_strict_start = 1;
}
}

void upsdrv_cleanup(void)
Expand Down

0 comments on commit af2d690

Please sign in to comment.