]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
ensure parser/cfg_obj log includes the line number
authorColin Vidal <colin@isc.org>
Thu, 23 Oct 2025 08:12:38 +0000 (10:12 +0200)
committerEvan Hunt <each@isc.org>
Thu, 23 Oct 2025 20:01:11 +0000 (13:01 -0700)
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.

bin/tests/system/addzone/tests.sh
lib/isccfg/parser.c

index 66c76bca181cef0e1a29b7bf44a7e7ebc023b6fe..ed897b9ba72e9820d3afbf9e97c984afcd021a7d 100755 (executable)
@@ -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))
index 9582da2e0e1041fc821111ae4efe3239d07d4ca2..f0af06a8bb5e97cb707b07829ce9753bde164f95 100644 (file)
@@ -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);
        }
 }