From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Thu, 23 Sep 2021 14:16:51 -0500 Subject: [PATCH] libmulitpath: add section name to invalid keyword output If users forget the closing brace for a section in multipath.conf, multipath has no way to detect that. When it sees the keyword at the start of the next section, it will complain that there is an invalid keyword, because that keyword doesn't belong in previous section (which was never ended with a closing brace). This can confuse users. To make this easier to understand, when multipath prints and invalid keyword message, it now also prints the current section name, which can give users a hint that they didn't end the previous section. Signed-off-by: Benjamin Marzinski --- libmultipath/parser.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index 48b54e87..96b95936 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -507,7 +507,8 @@ validate_config_strvec(vector strvec, char *file) } static int -process_stream(struct config *conf, FILE *stream, vector keywords, char *file) +process_stream(struct config *conf, FILE *stream, vector keywords, + const char *section, char *file) { int i; int r = 0, t; @@ -571,16 +572,22 @@ process_stream(struct config *conf, FILE *stream, vector keywords, char *file) if (keyword->sub) { kw_level++; r += process_stream(conf, stream, - keyword->sub, file); + keyword->sub, + keyword->string, + file); kw_level--; } break; } } - if (i >= VECTOR_SIZE(keywords)) - condlog(1, "%s line %d, invalid keyword: %s", - file, line_nr, str); - + if (i >= VECTOR_SIZE(keywords)) { + if (section) + condlog(1, "%s line %d, invalid keyword in the %s section: %s", + file, line_nr, section, str); + else + condlog(1, "%s line %d, invalid keyword: %s", + file, line_nr, str); + } free_strvec(strvec); } if (kw_level == 1) @@ -611,7 +618,7 @@ process_file(struct config *conf, char *file) /* Stream handling */ line_nr = 0; - r = process_stream(conf, stream, conf->keywords, file); + r = process_stream(conf, stream, conf->keywords, NULL, file); fclose(stream); //free_keywords(keywords);