Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report config parsing errors ("invalid directive") #2179

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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