From: Colin Vidal Date: Thu, 23 Oct 2025 08:12:38 +0000 (+0200) Subject: ensure parser/cfg_obj log includes the line number X-Git-Tag: v9.21.15~43^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b5246b3d252773f0e14dd1264eca72ebc9a4936;p=thirdparty%2Fbind9.git ensure parser/cfg_obj log includes the line number Since the `file` property of cfg_obj_t can now be null (instead of "none"), cfg_obj_t would take a fallback flow where the line was not logged. This fixes it. Also, add the log line when parser_complain is called and `file` is null (which might happend when parsing buffer only) to also include the line number. --- diff --git a/bin/tests/system/addzone/tests.sh b/bin/tests/system/addzone/tests.sh index 66c76bca181..ed897b9ba72 100755 --- a/bin/tests/system/addzone/tests.sh +++ b/bin/tests/system/addzone/tests.sh @@ -69,19 +69,19 @@ if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status + ret)) nextpart ns2/named.run >/dev/null -echo_i "checking addzone errors are logged correctly" +echo_i "checking addzone errors are logged correctly ($n)" ret=0 $RNDCCMD 10.53.0.2 addzone bad.example '{ type mister; };' 2>&1 | grep 'unexpected token' >/dev/null 2>&1 || ret=1 -wait_for_log_peek 20 "addzone: 'mister' unexpected" ns2/named.run || ret=1 +wait_for_log_peek 20 "addzone:1: 'mister' unexpected" ns2/named.run || ret=1 n=$((n + 1)) if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status + ret)) nextpart ns2/named.run >/dev/null -echo_i "checking modzone errors are logged correctly" +echo_i "checking modzone errors are logged correctly ($n)" ret=0 $RNDCCMD 10.53.0.2 modzone added.example '{ type mister; };' 2>&1 | grep 'unexpected token' >/dev/null 2>&1 || ret=1 -wait_for_log_peek 20 "modzone: 'mister' unexpected" ns2/named.run || ret=1 +wait_for_log_peek 20 "modzone:1: 'mister' unexpected" ns2/named.run || ret=1 n=$((n + 1)) if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status + ret)) diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index 9582da2e0e1..f0af06a8bb5 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -3648,8 +3648,10 @@ parser_complain(cfg_parser_t *pctx, bool is_warning, unsigned int flags, if (file != NULL) { snprintf(where, sizeof(where), "%s:%u: ", cfg_obj_asstring(file), pctx->line); - } else if (pctx->buf_name != NULL) { - snprintf(where, sizeof(where), "%s: ", pctx->buf_name); + } else { + snprintf(where, sizeof(where), "%s:%u: ", + pctx->buf_name == NULL ? "none" : pctx->buf_name, + pctx->line); } len = vsnprintf(message, sizeof(message), format, args); @@ -3717,7 +3719,7 @@ cfg_obj_log(const cfg_obj_t *obj, int level, const char *fmt, ...) { isc_log_write(CAT, MOD, level, "%s:%u: %s", cfg_obj_asstring(obj->file), obj->line, msgbuf); } else { - isc_log_write(CAT, MOD, level, "%s", msgbuf); + isc_log_write(CAT, MOD, level, "%u: %s", obj->line, msgbuf); } }