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.
This commit is contained in:
Colin Vidal 2025-10-23 10:12:38 +02:00 committed by Evan Hunt
parent 0db377da57
commit 6b5246b3d2
2 changed files with 9 additions and 7 deletions

View file

@ -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))

View 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);
}
}