2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

log master file loading errors through the logging subsystem

by default
This commit is contained in:
Andreas Gustafsson
2000-01-22 01:38:58 +00:00
parent 036df8a12d
commit 2680c1bb61
4 changed files with 79 additions and 33 deletions

View File

@@ -105,7 +105,7 @@ test_master(char *testfile, char *origin, char *class,
return(T_UNRESOLVED);
}
dns_rdatacallbacks_init(&callbacks);
dns_rdatacallbacks_init_stdio(&callbacks);
callbacks.add = t1_add_callback;
textregion.base = class;

View File

@@ -86,7 +86,7 @@ main(int argc, char *argv[]) {
exit(1);
}
dns_rdatacallbacks_init(&callbacks);
dns_rdatacallbacks_init_stdio(&callbacks);
callbacks.add = print_dataset;
result = dns_master_loadfile(argv[1], &origin, &origin, 1,

View File

@@ -15,16 +15,74 @@
* SOFTWARE.
*/
/* $Id: callbacks.c,v 1.3 1999/07/30 23:32:51 halley Exp $ */
/* $Id: callbacks.c,v 1.4 2000/01/22 01:38:57 gson Exp $ */
#include <config.h>
#include <stdarg.h>
#include <isc/assertions.h>
#include <dns/callbacks.h>
#include <isc/util.h>
static void default_error_warn_callback(dns_rdatacallbacks_t *, char *, ...);
#include <dns/callbacks.h>
#include <dns/log.h>
static void stdio_error_warn_callback(dns_rdatacallbacks_t *, char *, ...);
/*
* Private
*/
static void
stdio_error_warn_callback(dns_rdatacallbacks_t *callbacks, char *fmt, ...) {
va_list ap;
UNUSED(callbacks);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
}
static void
isclog_error_callback(dns_rdatacallbacks_t *callbacks, char *fmt, ...) {
va_list ap;
UNUSED(callbacks);
va_start(ap, fmt);
isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, /* XXX */
ISC_LOG_ERROR, fmt, ap);
va_end(ap);
}
static void
isclog_warn_callback(dns_rdatacallbacks_t *callbacks, char *fmt, ...) {
va_list ap;
UNUSED(callbacks);
va_start(ap, fmt);
isc_log_vwrite(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_MASTER, /* XXX */
ISC_LOG_WARNING, fmt, ap);
va_end(ap);
}
static void
dns_rdatacallbacks_initcommon(dns_rdatacallbacks_t *callbacks)
{
REQUIRE(callbacks != NULL);
callbacks->add = NULL;
callbacks->add_private = NULL;
callbacks->error_private = NULL;
callbacks->warn_private = NULL;
}
/*
* Public.
@@ -32,28 +90,15 @@ static void default_error_warn_callback(dns_rdatacallbacks_t *, char *, ...);
void
dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks) {
REQUIRE(callbacks != NULL);
callbacks->add = NULL;
callbacks->error = default_error_warn_callback;
callbacks->warn = default_error_warn_callback;
callbacks->add_private = NULL;
callbacks->error_private = NULL;
callbacks->warn_private = NULL;
dns_rdatacallbacks_initcommon(callbacks);
callbacks->error = isclog_error_callback;
callbacks->warn = isclog_warn_callback;
}
/*
* Private
*/
static void
default_error_warn_callback(dns_rdatacallbacks_t *callbacks, char *fmt, ...) {
va_list ap;
callbacks = callbacks; /*unused*/
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
void
dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks) {
dns_rdatacallbacks_initcommon(callbacks);
callbacks->error = stdio_error_warn_callback;
callbacks->warn = stdio_error_warn_callback;
}

View File

@@ -35,10 +35,6 @@ ISC_LANG_BEGINDECLS
*** Types
***/
/*
* XXXRTH These are likely to change once we've got a logging system.
*/
typedef struct dns_rdatacallbacks {
/* dns_load_master calls this when it has rdatasets to commit */
dns_addrdatasetfunc_t add;
@@ -57,17 +53,22 @@ typedef struct dns_rdatacallbacks {
***/
void dns_rdatacallbacks_init(dns_rdatacallbacks_t *callbacks);
/*
* Initalise 'callbacks'.
* 'error' and 'warn' are set to default callbacks that print the
* error message to stderr.
* error message through the DNS library log context.
*
* All other elements are initalised to NULL.
*
* Requires:
* 'callbacks' is a valid dns_rdatacallbacks_t,
*/
void dns_rdatacallbacks_init_stdio(dns_rdatacallbacks_t *callbacks);
/*
* Like dns_rdatacallbacks_init, but logs to stdio.
*/
ISC_LANG_ENDDECLS
#endif /* DNS_CALLBACKS_H */