Commit b8257bd2 authored by Bob Halley's avatar Bob Halley
Browse files

logging tweaks and fixes

parent 8f6a8ce9
......@@ -77,6 +77,11 @@ EXTERN unsigned int ns_g_debuglevel INIT(0);
EXTERN dns_c_ctx_t * ns_g_confctx INIT(NULL);
EXTERN const char * ns_g_conffile INIT("/etc/named.conf");
/*
* Misc.
*/
EXTERN isc_boolean_t ns_g_coreok INIT(ISC_TRUE);
#undef EXTERN
#undef INIT
......
......@@ -19,7 +19,13 @@
#define NS_SERVER_H 1
#include <isc/types.h>
#include <isc/log.h>
isc_result_t ns_server_init(void);
isc_result_t
ns_server_init(void);
void
ns_server_fatal(isc_logmodule_t *module, isc_boolean_t want_core,
const char *format, ...);
#endif /* NS_SERVER_H */
......@@ -341,7 +341,7 @@ do_ipv4(ns_interfacemgr_t *mgr, isc_boolean_t udp_only) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_NETWORK,
NS_LOGMODULE_INTERFACEMGR,
ISC_LOG_INFO,
"IPv4: listening on %s (%s port %u)",
"listening on IPv4 interface %s, %s port %u",
interface.name, addrstr,
ntohs(listen_addr.type.sin.sin_port));
......@@ -349,7 +349,7 @@ do_ipv4(ns_interfacemgr_t *mgr, isc_boolean_t udp_only) {
udp_only, &ifp);
if (result != DNS_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"IPv4: listening on interface %s"
"listening on IPv4 interface %s"
" failed; interface ignored",
interface.name);
}
......@@ -380,12 +380,13 @@ do_ipv6(ns_interfacemgr_t *mgr) {
} else {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_NETWORK,
NS_LOGMODULE_INTERFACEMGR, ISC_LOG_INFO,
"IPv6: listening (port %u)", ns_g_port);
"listening on IPv6 interfaces, port %u",
ns_g_port);
result = ns_interface_create(mgr, &listen_addr, ISC_FALSE,
&ifp);
if (result != DNS_R_SUCCESS)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"IPv6: listening failed");
"listening on IPv6 interfaces failed");
}
}
......@@ -403,13 +404,13 @@ ns_interfacemgr_scan(ns_interfacemgr_t *mgr) {
} else
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_NETWORK,
NS_LOGMODULE_INTERFACEMGR, ISC_LOG_INFO,
"IPv6: not available");
"no IPv6 interfaces found");
if (isc_net_probeipv4() == ISC_R_SUCCESS)
do_ipv4(mgr, udp_only);
else
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_NETWORK,
NS_LOGMODULE_INTERFACEMGR, ISC_LOG_INFO,
"IPv4: not available");
"no IPv4 interfaces found");
/*
* Now go through the interface list and delete anything that
......@@ -420,9 +421,12 @@ ns_interfacemgr_scan(ns_interfacemgr_t *mgr) {
purge_old_interfaces(mgr);
if (ISC_LIST_EMPTY(mgr->interfaces)) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"warning: not listening on any interfaces");
/* Continue anyway. */
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_NETWORK,
NS_LOGMODULE_INTERFACEMGR, ISC_LOG_WARNING,
"not listening on any interfaces");
/*
* Continue anyway.
*/
}
}
......
......@@ -103,6 +103,9 @@ early_fatal(char *format, ...) {
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
format, args);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
"exiting (due to early fatal error)");
} else {
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
......@@ -124,12 +127,16 @@ static void
parse_command_line(int argc, char *argv[]) {
int ch;
while ((ch = isc_commandline_parse(argc, argv, "b:c:N:p:sz:")) != -1) {
while ((ch = isc_commandline_parse(argc, argv, "b:c:d:N:p:sz:")) !=
-1) {
switch (ch) {
case 'b':
case 'c':
ns_g_conffile = isc_commandline_argument;
break;
case 'd':
ns_g_debuglevel = atoi(isc_commandline_argument);
break;
case 'N':
ns_g_cpus = atoi(isc_commandline_argument);
if (ns_g_cpus == 0)
......@@ -236,7 +243,7 @@ setup() {
isc_result_totext(result));
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "Starting BIND %s", ns_g_version);
ISC_LOG_NOTICE, "starting BIND %s", ns_g_version);
ISC_LIST_INIT(ns_g_viewlist);
result = isc_rwlock_init(&ns_g_viewlock, 0, 0);
......@@ -266,7 +273,7 @@ cleanup() {
dns_tsig_destroy();
isc_rwlock_destroy(&ns_g_viewlock);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "Exiting");
ISC_LOG_NOTICE, "exiting");
ns_log_shutdown();
}
......
......@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <isc/assertions.h>
#include <isc/error.h>
......@@ -265,7 +266,7 @@ load_zone(dns_c_ctx_t *ctx, dns_c_zone_t *czone, dns_c_view_t *cview,
return (result);
}
static isc_result_t
static void
load_configuration(const char *filename) {
isc_result_t result;
ns_load_t lctx;
......@@ -283,18 +284,18 @@ load_configuration(const char *filename) {
callbacks.optscbkuap = NULL;
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "Loading '%s'", ns_g_conffile);
ISC_LOG_INFO, "loading '%s'", filename);
configctx = NULL;
result = dns_c_parse_namedconf(ns_g_lctx,
filename, ns_g_mctx, &configctx,
&callbacks);
if (result != ISC_R_SUCCESS) {
return (result);
}
if (result != ISC_R_SUCCESS)
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
"load of '%s' failed", filename);
/*
* Create default view, if required.
* XXXRTH Create default view, if required.
*/
/*
......@@ -343,33 +344,22 @@ load_configuration(const char *filename) {
}
if (oconfigctx != NULL)
dns_c_ctx_delete(NULL /* XXX isc_log_t */, &oconfigctx);
return (ISC_R_SUCCESS);
dns_c_ctx_delete(ns_g_lctx, &oconfigctx);
}
static void
run_server(isc_task_t *task, isc_event_t *event) {
isc_result_t result;
(void)task;
isc_event_free(&event);
result = load_configuration(ns_g_conffile);
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_CRITICAL,
"Load of '%s' failed: %s", ns_g_conffile,
isc_result_totext(result));
isc_app_shutdown();
return;
}
load_configuration(ns_g_conffile);
ns_interfacemgr_scan(ns_g_interfacemgr);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "Running");
ISC_LOG_INFO, "running");
}
static isc_result_t
......@@ -459,7 +449,7 @@ shutdown_server(isc_task_t *task, isc_event_t *event) {
(void)task;
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "Shutting down");
ISC_LOG_INFO, "shutting down");
RWLOCK(&ns_g_viewlock, isc_rwlocktype_write);
......@@ -474,7 +464,7 @@ shutdown_server(isc_task_t *task, isc_event_t *event) {
/*
* XXXRTH Is this the right place to do this?
*/
dns_c_ctx_delete(NULL /* XXX isc_log_t */, &ns_g_confctx);
dns_c_ctx_delete(ns_g_lctx, &ns_g_confctx);
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_write);
......@@ -535,3 +525,21 @@ ns_server_init(void) {
return (result);
}
void
ns_server_fatal(isc_logmodule_t *module, isc_boolean_t want_core,
const char *format, ...)
{
va_list args;
va_start(args, format);
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, module,
ISC_LOG_CRITICAL, format, args);
va_end(args);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
if (want_core && ns_g_coreok)
abort();
exit(1);
}
......@@ -24,7 +24,7 @@
#endif
#if !defined(lint) && !defined(SABER)
static char rcsid[] = "$Id: confparser.y,v 1.11 1999/10/13 23:19:45 marka Exp $";
static char rcsid[] = "$Id: confparser.y,v 1.12 1999/10/23 00:02:07 halley Exp $";
#endif /* not lint */
#include <config.h>
......@@ -41,6 +41,7 @@ static char rcsid[] = "$Id: confparser.y,v 1.11 1999/10/13 23:19:45 marka Exp $"
#include <syslog.h>
#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/mutex.h>
#include <isc/lex.h>
#include <isc/symtab.h>
......@@ -347,7 +348,7 @@ statement: include_stmt
include_stmt: L_INCLUDE L_QSTRING L_EOS
{
if (isc_lex_openfile(mylexer, $2) != ISC_R_SUCCESS) {
parser_error(ISC_FALSE ,"Can't open file %s\n",
parser_error(ISC_FALSE ,"Can't open file %s",
$2);
YYABORT;
}
......@@ -1363,7 +1364,7 @@ channel_stmt:
$2, &newc);
if (tmpres == ISC_R_EXISTS) {
parser_warning(ISC_FALSE,
"Redefing channel %s\n", $2);
"Redefing channel %s", $2);
} else if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE,
"Failed to add new file channel.");
......@@ -2033,7 +2034,7 @@ address_match_simple: ip_address
case ISC_R_NOMEMORY:
parser_error(ISC_FALSE,
"Insufficient memory available.\n");
"Insufficient memory available.");
YYABORT;
break;
......@@ -2068,7 +2069,7 @@ address_match_simple: ip_address
case ISC_R_NOMEMORY:
parser_error(ISC_FALSE,
"Insufficient memory "
"available.\n");
"available.");
YYABORT;
break;
......@@ -2118,7 +2119,7 @@ address_match_simple: ip_address
case ISC_R_NOMEMORY:
parser_error(ISC_FALSE,
"Insufficient memory "
"available.\n");
"available.");
YYABORT;
break;
......@@ -2146,7 +2147,7 @@ address_match_simple: ip_address
case ISC_R_NOMEMORY:
parser_error(ISC_FALSE,
"Insufficient memory "
"available.\n");
"available.");
YYABORT;
break;
}
......@@ -2175,7 +2176,7 @@ address_name: any_string
currcfg->mem, &elem, $1);
if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE,
"Failed to create IPE-ACL\n");
"Failed to create IPE-ACL");
YYABORT;
}
}
......@@ -2213,7 +2214,7 @@ key_list_element: key_ref
currserver->keys, $1, &keyid);
if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE,
"Failed to create keyid\n");
"Failed to create keyid");
YYABORT;
}
}
......@@ -3447,6 +3448,11 @@ dns_c_parse_namedconf(isc_log_t *logctx, const char *filename, isc_mem_t *mem,
specials['*'] = 1;
#endif
/*
* Use the logging context specified by the caller.
*/
logcontext = logctx;
/*
* This memory context is only used by the lexer routines (and must
* stay that way). Any memory that must live past the return of
......@@ -3471,7 +3477,7 @@ dns_c_parse_namedconf(isc_log_t *logctx, const char *filename, isc_mem_t *mem,
goto done;
}
res = dns_c_ctx_new(logctx, mem, &currcfg);
res = dns_c_ctx_new(logcontext, mem, &currcfg);
if (res != ISC_R_SUCCESS) {
isc_log_write(logcontext, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, ISC_LOG_CRITICAL,
......@@ -3514,7 +3520,7 @@ dns_c_parse_namedconf(isc_log_t *logctx, const char *filename, isc_mem_t *mem,
*/
isc_mem_destroy_check(memctx, ISC_FALSE);
dns_c_ctx_delete(logctx, &currcfg);
dns_c_ctx_delete(logcontext, &currcfg);
currcfg = NULL;
} else {
res = ISC_R_SUCCESS;
......@@ -3535,6 +3541,7 @@ dns_c_parse_namedconf(isc_log_t *logctx, const char *filename, isc_mem_t *mem,
currcfg = NULL;
memctx = NULL;
mylexer = NULL;
logcontext = NULL;
RUNTIME_CHECK(isc_mutex_unlock(&yacc_mutex) == ISC_R_SUCCESS);
......@@ -3737,26 +3744,26 @@ parser_complain(isc_boolean_t is_warning, isc_boolean_t print_last_token,
level = ISC_LOG_WARNING;
}
sprintf(where, "%s:%d ", filename, lineno);
if ((unsigned int)vsprintf(message, format, args) >= sizeof message) {
abort();
}
sprintf(where, "%s:%d: ", filename, lineno);
if ((unsigned int)vsprintf(message, format, args) >= sizeof message)
FATAL_ERROR(__FILE__, __LINE__,
"error message would overflow");
if (print_last_token) {
if (logcontext != NULL) {
isc_log_write(logcontext, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, level,
"%s%s near ``%s''\n", where, message,
"%s%s near `%s'", where, message,
token_to_text(lasttoken, lastyylval));
} else {
fprintf(stderr, "%s%s near ``%s''\n", where, message,
fprintf(stderr, "%s%s near `%s'\n", where, message,
token_to_text(lasttoken, lastyylval));
}
} else {
if (logcontext != NULL) {
isc_log_write(logcontext, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, level,
"%s%s\n", where, message);
"%s%s", where, message);
} else {
fprintf(stderr, "%s%s\n", where, message);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment