[master] pass source file and line to dyndb load function

4455.	[cleanup]	Allow dyndb modules to correctly log the filename
			and line number when processing configuration text
			from named.conf. [RT #43050]
This commit is contained in:
Evan Hunt
2016-08-25 18:08:26 -07:00
parent 65c09d514e
commit 02fb764681
9 changed files with 115 additions and 13 deletions

View File

@@ -348,7 +348,8 @@ unload_library(dyndb_implementation_t **impp)
isc_result_t
dns_dyndb_load(const char *libname, const char *name, const char *parameters,
isc_mem_t *mctx, const dns_dyndbctx_t *dctx)
const char *file, unsigned long line, isc_mem_t *mctx,
const dns_dyndbctx_t *dctx)
{
isc_result_t result;
dyndb_implementation_t *implementation = NULL;
@@ -365,8 +366,8 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters,
CHECK(ISC_R_EXISTS);
CHECK(load_library(mctx, libname, name, &implementation));
CHECK(implementation->register_func(mctx, name, parameters, dctx,
&implementation->inst));
CHECK(implementation->register_func(mctx, name, parameters, file, line,
dctx, &implementation->inst));
APPEND(dyndb_implementations, implementation, link);
result = ISC_R_SUCCESS;

View File

@@ -57,6 +57,8 @@ struct dns_dyndbctx {
typedef isc_result_t dns_dyndb_register_t(isc_mem_t *mctx,
const char *name,
const char *parameters,
const char *file,
unsigned long line,
const dns_dyndbctx_t *dctx,
void **instp);
/*%
@@ -95,7 +97,8 @@ typedef int dns_dyndb_version_t(unsigned int *flags);
isc_result_t
dns_dyndb_load(const char *libname, const char *name, const char *parameters,
isc_mem_t *mctx, const dns_dyndbctx_t *dctx);
const char *file, unsigned long line, isc_mem_t *mctx,
const dns_dyndbctx_t *dctx);
/*%
* Load a dyndb module.
*
@@ -104,6 +107,10 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters,
* the instance handle to a list of dyndb instances so it can be cleaned
* up later.
*
* 'file' and 'line' can be used to indicate the name of the file and
* the line number from which the parameters were taken, so that logged
* error messages, if any, will display the correct locations.
*
* Returns:
*\li #ISC_R_SUCCESS
*\li #ISC_R_NOMEMORY

View File

@@ -405,6 +405,23 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name);
* \li #ISC_R_NOTFOUND - there are no sources.
*/
isc_result_t
isc_lex_setsourceline(isc_lex_t *lex, unsigned long line);
/*%<
* Assigns a new line number to the input source. This can be used
* when parsing a buffer that's been excerpted from the middle a file,
* allowing logged messages to display the correct line number,
* rather than the line number within the buffer.
*
* Requires:
*
* \li 'lex' is a valid lexer.
*
* Returns:
* \li #ISC_R_SUCCESS
* \li #ISC_R_NOTFOUND - there are no sources.
*/
isc_boolean_t
isc_lex_isfile(isc_lex_t *lex);
/*%<

View File

@@ -973,7 +973,6 @@ isc_lex_getlasttokentext(isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r)
source->ignored;
}
char *
isc_lex_getsourcename(isc_lex_t *lex) {
inputsource *source;
@@ -1000,7 +999,6 @@ isc_lex_getsourceline(isc_lex_t *lex) {
return (source->line);
}
isc_result_t
isc_lex_setsourcename(isc_lex_t *lex, const char *name) {
inputsource *source;
@@ -1010,7 +1008,7 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name) {
source = HEAD(lex->sources);
if (source == NULL)
return(ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
newname = isc_mem_strdup(lex->mctx, name);
if (newname == NULL)
return (ISC_R_NOMEMORY);
@@ -1019,6 +1017,20 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name) {
return (ISC_R_SUCCESS);
}
isc_result_t
isc_lex_setsourceline(isc_lex_t *lex, unsigned long line) {
inputsource *source;
REQUIRE(VALID_LEX(lex));
source = HEAD(lex->sources);
if (source == NULL)
return (ISC_R_NOTFOUND);
source->line = line;
return (ISC_R_SUCCESS);
}
isc_boolean_t
isc_lex_isfile(isc_lex_t *lex) {
inputsource *source;

View File

@@ -20,11 +20,11 @@
#include <isc/mem.h>
#include <isc/util.h>
ATF_TC(lex);
ATF_TC_HEAD(lex, tc) {
ATF_TC(lex_0xff);
ATF_TC_HEAD(lex_0xff, tc) {
atf_tc_set_md_var(tc, "descr", "check handling of 0xff");
}
ATF_TC_BODY(lex, tc) {
ATF_TC_BODY(lex_0xff, tc) {
isc_mem_t *mctx = NULL;
isc_result_t result;
isc_lex_t *lex = NULL;
@@ -51,11 +51,58 @@ ATF_TC_BODY(lex, tc) {
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
}
ATF_TC(lex_setline);
ATF_TC_HEAD(lex_setline, tc) {
atf_tc_set_md_var(tc, "descr", "check setting of source line");
}
ATF_TC_BODY(lex_setline, tc) {
isc_mem_t *mctx = NULL;
isc_result_t result;
isc_lex_t *lex = NULL;
unsigned char text[] = "text\nto\nbe\nprocessed\nby\nlexer";
isc_buffer_t buf;
isc_token_t token;
unsigned long line;
int i;
UNUSED(tc);
result = isc_mem_create(0, 0, &mctx);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = isc_lex_create(mctx, 1024, &lex);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
isc_buffer_init(&buf, &text[0], sizeof(text));
isc_buffer_add(&buf, sizeof(text));
result = isc_lex_openbuffer(lex, &buf);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = isc_lex_setsourceline(lex, 100);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
for (i = 0; i < 6; i++) {
result = isc_lex_gettoken(lex, 0, &token);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
line = isc_lex_getsourceline(lex);
ATF_REQUIRE_EQ(line, 100U + i);
}
result = isc_lex_gettoken(lex, 0, &token);
ATF_REQUIRE_EQ(result, ISC_R_EOF);
line = isc_lex_getsourceline(lex);
ATF_REQUIRE_EQ(line, 105U);
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, lex);
ATF_TP_ADD_TC(tp, lex_0xff);
ATF_TP_ADD_TC(tp, lex_setline);
return (atf_no_error());
}