Skip to content

Commit

Permalink
server/conf.c, drivers/snmp-ups.c, clients/upsmon.c, clients/upssched…
Browse files Browse the repository at this point in the history
….c: report if config errors were seen and we ignored them (went on)

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
  • Loading branch information
jimklimov committed Nov 14, 2023
1 parent 963c101 commit c259a0a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clients/upsmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,7 @@ static void upsmon_err(const char *errmsg)
static void loadconfig(void)
{
PCONF_CTX_t ctx;
int numerrors = 0;

pconf_init(&ctx, upsmon_err);

Expand All @@ -1872,6 +1873,7 @@ static void loadconfig(void)
if (pconf_parse_error(&ctx)) {
upslogx(LOG_ERR, "Parse error: %s:%d: %s",
configfile, ctx.linenum, ctx.errmsg);
numerrors++;
continue;
}

Expand All @@ -1890,6 +1892,7 @@ static void loadconfig(void)
snprintfcat(errmsg, sizeof(errmsg), " %s",
ctx.arglist[i]);

numerrors++;
upslogx(LOG_WARNING, "%s", errmsg);
}
}
Expand All @@ -1916,6 +1919,13 @@ static void loadconfig(void)
}
}

/* FIXME: Per legacy behavior, we silently went on.
* Maybe should abort on unusable configs?
*/
if (numerrors) {
upslogx(LOG_ERR, "Encountered %d config errors, those entries were ignored", numerrors);
}

pconf_finish(&ctx);
}

Expand Down
11 changes: 11 additions & 0 deletions clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@ static void checkconf(void)
{
char fn[SMALLBUF];
PCONF_CTX_t ctx;
int numerrors = 0;

snprintf(fn, sizeof(fn), "%s/upssched.conf", confpath());

Expand All @@ -1454,6 +1455,7 @@ static void checkconf(void)
if (pconf_parse_error(&ctx)) {
upslogx(LOG_ERR, "Parse error: %s:%d: %s",
fn, ctx.linenum, ctx.errmsg);
numerrors++;
continue;
}

Expand All @@ -1471,10 +1473,19 @@ static void checkconf(void)
snprintfcat(errmsg, sizeof(errmsg), " %s",
ctx.arglist[i]);

numerrors++;
upslogx(LOG_WARNING, "%s", errmsg);
}
}


/* FIXME: Per legacy behavior, we silently went on.
* Maybe should abort on unusable configs?
*/
if (numerrors) {
upslogx(LOG_ERR, "Encountered %d config errors, those entries were ignored", numerrors);
}

pconf_finish(&ctx);
}

Expand Down
11 changes: 11 additions & 0 deletions drivers/snmp-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -4176,6 +4176,7 @@ void read_mibconf(char *mib)
{
char fn[SMALLBUF];
PCONF_CTX_t ctx;
int numerrors = 0;

upsdebugx(2, "SNMP UPS driver: entering %s(%s)", __func__, mib);

Expand All @@ -4190,6 +4191,7 @@ void read_mibconf(char *mib)
if (pconf_parse_error(&ctx)) {
upslogx(LOG_ERR, "Parse error: %s:%d: %s",
fn, ctx.linenum, ctx.errmsg);
numerrors++;
continue;
}

Expand All @@ -4207,8 +4209,17 @@ void read_mibconf(char *mib)
snprintfcat(errmsg, sizeof(errmsg), " %s",
ctx.arglist[i]);

numerrors++;
upslogx(LOG_WARNING, "%s", errmsg);
}
}

/* FIXME: Per legacy behavior, we silently went on.
* Maybe should abort on unusable configs?
*/
if (numerrors) {
upslogx(LOG_ERR, "Encountered %d MIB config errors, those entries were ignored", numerrors);
}

pconf_finish(&ctx);
}
10 changes: 10 additions & 0 deletions server/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ void load_upsdconf(int reloading)
{
char fn[SMALLBUF];
PCONF_CTX_t ctx;
int numerrors = 0;

snprintf(fn, sizeof(fn), "%s/upsd.conf", confpath());

Expand Down Expand Up @@ -387,6 +388,7 @@ void load_upsdconf(int reloading)
if (pconf_parse_error(&ctx)) {
upslogx(LOG_ERR, "Parse error: %s:%d: %s",
fn, ctx.linenum, ctx.errmsg);
numerrors++;
continue;
}

Expand All @@ -404,6 +406,7 @@ void load_upsdconf(int reloading)
snprintfcat(errmsg, sizeof(errmsg), " %s",
ctx.arglist[i]);

numerrors++;
upslogx(LOG_WARNING, "%s", errmsg);
}

Expand All @@ -425,6 +428,13 @@ void load_upsdconf(int reloading)
}
}

/* FIXME: Per legacy behavior, we silently went on.
* Maybe should abort on unusable configs?
*/
if (numerrors) {
upslogx(LOG_ERR, "Encountered %d config errors, those entries were ignored", numerrors);
}

pconf_finish(&ctx);
}

Expand Down

0 comments on commit c259a0a

Please sign in to comment.