Skip to content

Commit

Permalink
server/netget.c, docs/net-protocol.txt: set_var(): report IMMUTABLE f…
Browse files Browse the repository at this point in the history
…lag on values in DEBUG builds [networkupstools#266]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 23, 2024
1 parent 55f016b commit e6f5efb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/net-protocol.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ exponents, and comma for thousands separator are forbidden.
For example: "1200.20" is valid, while "1,200.20" and "1200,20" and "1.2e4"
are invalid.

Also note that internally NUT programs can flag variables as 'IMMUTABLE':
a value of such variable can not be changed after it was initially set
(this is used e.g. for "override" settings where the device is known to
provide bogus readings). The flag is not currently exposed with `GET`
commands, but can be a reason for a `SET` to fail.

This replaces the old "VARTYPE" command.

Expand Down
13 changes: 13 additions & 0 deletions server/netget.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ static void get_type(nut_ctype_t *client, const char *upsname, const char *var)

snprintf(buf, sizeof(buf), "TYPE %s %s", upsname, var);

if (node->flags & ST_FLAG_IMMUTABLE) {
#if DEBUG
/* Properly exposing this needs also an update to
* docs/net-protocol.txt (promote the paragraph
* provided as a note currently) and to the NUT RFC
* https://www.rfc-editor.org/info/rfc9271
*/
snprintfcat(buf, sizeof(buf), " IMMUTABLE");
#endif
upsdebugx(3, "%s: UPS[%s] variable %s is IMMUTABLE",
__func__, upsname, var);
}

if (node->flags & ST_FLAG_RW)
snprintfcat(buf, sizeof(buf), " RW");

Expand Down

0 comments on commit e6f5efb

Please sign in to comment.