From: Brian Wellington Date: Tue, 22 Aug 2000 01:45:28 +0000 (+0000) Subject: pullup: X-Git-Tag: v9.0.0rc4~8 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=317a9d35897bc69405af44289620f93b9f84c3ff;p=thirdparty%2Fbind9.git pullup: 330. [func] New function isc_log_wouldlog(). (note: #330 is out of place in CHANGES, because it's new in rc4, but if it was in the place that 330 is supposed to go, no one would see it. So, leave it at the top) --- diff --git a/CHANGES b/CHANGES index cba351c87cc..01dc1987e59 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ + 330. [func] New function isc_log_wouldlog(). + 402. [bug] Treat undefined acls as errors, rather than warning and then later throwing an assertion. [RT #252] diff --git a/bin/named/client.c b/bin/named/client.c index 003db2023e3..82d53f1e777 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: client.c,v 1.98.2.3 2000/07/26 23:51:31 bwelling Exp $ */ +/* $Id: client.c,v 1.98.2.4 2000/08/22 01:45:08 bwelling Exp $ */ #include @@ -270,7 +270,7 @@ set_timeout(ns_client_t *client, unsigned int seconds) { if (result != ISC_R_SUCCESS) { ns_client_log(client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_CLIENT, ISC_LOG_ERROR, - "setting timouet: %s", + "setting timeout: %s", isc_result_totext(result)); /* Continue anyway. */ } @@ -1694,6 +1694,9 @@ ns_client_log(ns_client_t *client, isc_logcategory_t *category, { va_list ap; + if (isc_log_wouldlog(ns_g_lctx, level) == ISC_FALSE) + return; + va_start(ap, fmt); ns_client_logv(client, category, module, level, fmt, ap); va_end(ap); diff --git a/bin/named/query.c b/bin/named/query.c index 4bd1cedb46e..8606bef8e18 100644 --- a/bin/named/query.c +++ b/bin/named/query.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: query.c,v 1.109.2.10 2000/08/08 19:30:13 bwelling Exp $ */ +/* $Id: query.c,v 1.109.2.11 2000/08/22 01:45:09 bwelling Exp $ */ #include @@ -2881,6 +2881,10 @@ log_query(ns_client_t *client) { char text[256]; isc_region_t r; dns_rdataset_t *rdataset; + int level = ISC_LOG_DEBUG(1); + + if (! isc_log_wouldlog(ns_g_lctx, level)) + return; /* XXXRTH Allow this to be turned off! */ @@ -2900,7 +2904,7 @@ log_query(ns_client_t *client) { } isc_buffer_usedregion(&b, &r); ns_client_log(client, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_QUERY, - ISC_LOG_DEBUG(1), "query: %s%.*s", namebuf, + level, "query: %s%.*s", namebuf, (int)r.length, (char *)r.base); } diff --git a/bin/named/xfrout.c b/bin/named/xfrout.c index 6a4ab8649da..1aa9a3d5256 100644 --- a/bin/named/xfrout.c +++ b/bin/named/xfrout.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: xfrout.c,v 1.68.2.1 2000/08/07 22:04:31 gson Exp $ */ +/* $Id: xfrout.c,v 1.68.2.2 2000/08/22 01:45:11 bwelling Exp $ */ #include @@ -1315,7 +1315,8 @@ sendstream(xfrout_ctx_t *xfr) { break; } - log_rr(name, rdata, ttl); /* XXX */ + if (isc_log_wouldlog(ns_g_lctx, XFROUT_RR_LOGLEVEL)) + log_rr(name, rdata, ttl); /* XXX */ dns_message_gettempname(msg, &msgname); dns_name_init(msgname, NULL); diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index b163ae6e4c7..4d27d69aa9c 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: dispatch.c,v 1.57 2000/06/22 21:54:23 tale Exp $ */ +/* $Id: dispatch.c,v 1.57.2.1 2000/08/22 01:45:14 bwelling Exp $ */ #include @@ -175,6 +175,9 @@ mgr_log(dns_dispatchmgr_t *mgr, int level, const char *fmt, ...) { char msgbuf[2048]; va_list ap; + if (! isc_log_wouldlog(dns_lctx, level)) + return; + va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); va_end(ap); @@ -189,6 +192,9 @@ dispatch_log(dns_dispatch_t *disp, int level, const char *fmt, ...) { char msgbuf[2048]; va_list ap; + if (! isc_log_wouldlog(dns_lctx, level)) + return; + va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); va_end(ap); @@ -206,6 +212,9 @@ request_log(dns_dispatch_t *disp, dns_dispentry_t *resp, char peerbuf[256]; va_list ap; + if (! isc_log_wouldlog(dns_lctx, level)) + return; + va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); va_end(ap); diff --git a/lib/dns/validator.c b/lib/dns/validator.c index b7274b4c134..96605ae1a64 100644 --- a/lib/dns/validator.c +++ b/lib/dns/validator.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: validator.c,v 1.63.2.3 2000/07/27 22:50:02 gson Exp $ */ +/* $Id: validator.c,v 1.63.2.4 2000/08/22 01:45:16 bwelling Exp $ */ #include @@ -1545,6 +1545,9 @@ validator_log(dns_validator_t *val, int level, const char *fmt, ...) { va_list ap; + if (! isc_log_wouldlog(dns_lctx, level)) + return; + va_start(ap, fmt); validator_logv(val, DNS_LOGCATEGORY_DNSSEC, DNS_LOGMODULE_VALIDATOR, level, fmt, ap); diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 10c2516d02a..48086fe4516 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: xfrin.c,v 1.79.2.4 2000/07/27 22:56:38 gson Exp $ */ +/* $Id: xfrin.c,v 1.79.2.5 2000/08/22 01:45:18 bwelling Exp $ */ #include @@ -1226,6 +1226,9 @@ xfrin_log1(int level, dns_name_t *zonename, isc_sockaddr_t *masteraddr, { va_list ap; + if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE) + return; + va_start(ap, fmt); xfrin_logv(level, zonename, masteraddr, fmt, ap); va_end(ap); @@ -1240,6 +1243,9 @@ xfrin_log(dns_xfrin_ctx_t *xfr, unsigned int level, const char *fmt, ...) { va_list ap; + if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE) + return; + va_start(ap, fmt); xfrin_logv(level, &xfr->name, &xfr->masteraddr, fmt, ap); va_end(ap); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index c6dd59e436d..2abc2ffd94d 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: zone.c,v 1.152.2.6 2000/08/21 20:51:47 bwelling Exp $ */ +/* $Id: zone.c,v 1.152.2.7 2000/08/22 01:45:20 bwelling Exp $ */ #include @@ -3378,6 +3378,9 @@ zone_log(dns_zone_t *zone, const char *me, int level, const char *fmt, ...) { int len; isc_result_t result = ISC_R_FAILURE; + if (isc_log_wouldlog(dns_lctx, level) == ISC_FALSE) + return; + isc_buffer_init(&buffer, namebuf, sizeof(namebuf)); if (dns_name_dynamic(&zone->origin)) diff --git a/lib/isc/include/isc/log.h b/lib/isc/include/isc/log.h index 091c7633713..f65e8cc0c9e 100644 --- a/lib/isc/include/isc/log.h +++ b/lib/isc/include/isc/log.h @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: log.h,v 1.25 2000/06/19 21:45:03 explorer Exp $ */ +/* $Id: log.h,v 1.25.2.1 2000/08/22 01:45:26 bwelling Exp $ */ #ifndef ISC_LOG_H #define ISC_LOG_H 1 @@ -627,6 +627,17 @@ isc_log_getdebuglevel(isc_log_t *lctx); * The current logging debugging level is returned. */ +isc_boolean_t +isc_log_wouldlog(isc_log_t *lctx, int level); +/* + * Determine whether logging something to 'lctx' at 'level' would + * actually cause something to be logged somewhere. + * + * If ISC_FALSE is returned, it is guaranteed that nothing would + * be logged, allowing the caller to omit unnecessary + * isc_log_write() calls and possible message preformatting. + */ + void isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval); /* diff --git a/lib/isc/log.c b/lib/isc/log.c index 93df1fe8164..55ee7cf34de 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: log.c,v 1.38 2000/06/23 17:52:20 tale Exp $ */ +/* $Id: log.c,v 1.38.2.1 2000/08/22 01:45:24 bwelling Exp $ */ /* Principal Authors: DCL */ @@ -1197,6 +1197,33 @@ isc_log_open(isc_logchannel_t *channel) { return (ISC_R_SUCCESS); } +isc_boolean_t +isc_log_wouldlog(isc_log_t *lctx, int level) { + /* + * Try to avoid locking the mutex for messages which can't + * possibly be logged to any channels -- primarily debugging + * messages that the debug level is not high enough to print. + * + * If the level is (mathematically) less than or equal to the + * highest_level, or if there is a dynamic channel and the level is + * less than or equal to the debug level, the main loop must be + * entered to see if the message should really be output. + * + * NOTE: this is UNLOCKED access to the logconfig. However, + * the worst thing that can happen is that a bad decision is made + * about returning without logging, and that's not a big concern, + * because that's a risk anyway if the logconfig is being + * dynamically changed. + */ + + if (lctx == NULL) + return (ISC_FALSE); + + return (ISC_TF(level <= lctx->logconfig->highest_level || + (lctx->logconfig->dynamic && + level <= lctx->debug_level))); +} + static void isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, isc_logmodule_t *module, int level, isc_boolean_t write_once, @@ -1232,24 +1259,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, REQUIRE(category->id < lctx->category_count); REQUIRE(module->id < lctx->module_count); - /* - * Try to avoid locking the mutex for messages which can't - * possibly be logged to any channels -- primarily debugging - * messages that the debug level is not high enough to print. - * - * If the level is (mathematically) less than or equal to the - * highest_level, or if there is a dynamic channel and the level is - * less than or equal to the debug level, the main loop must be - * entered to see if the message should really be output. - * - * NOTE: this is UNLOCKED access to the logconfig. However, - * the worst thing that can happen is that a bad decision is made - * about returning without logging, and that's not a big concern, - * because that's a risk anyway if the logconfig is being - * dynamically changed. - */ - if (! (level <= lctx->logconfig->highest_level || - (lctx->logconfig->dynamic && level <= lctx->debug_level))) + if (! isc_log_wouldlog(lctx, level)) return; time_string[0] = '\0'; diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 9f33588cd34..04aa279afd0 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: socket.c,v 1.142.2.3 2000/08/15 01:30:34 gson Exp $ */ +/* $Id: socket.c,v 1.142.2.4 2000/08/22 01:45:28 bwelling Exp $ */ #include @@ -76,11 +76,17 @@ * DLVL(50) -- Event tracing, including receiving/sending completion events. * DLVL(20) -- Socket creation/destruction. */ -#define TRACE DLVL(90) -#define CORRECTNESS DLVL(70) -#define IOEVENT DLVL(60) -#define EVENT DLVL(50) -#define CREATION DLVL(20) +#define TRACE_LEVEL 90 +#define CORRECTNESS_LEVEL 70 +#define IOEVENT_LEVEL 60 +#define EVENT_LEVEL 50 +#define CREATION_LEVEL 20 + +#define TRACE DLVL(TRACE_LEVEL) +#define CORRECTNESS DLVL(CORRECTNESS_LEVEL) +#define IOEVENT DLVL(IOEVENT_LEVEL) +#define EVENT DLVL(EVENT_LEVEL) +#define CREATION DLVL(CREATION_LEVEL) typedef isc_event_t intev_t; @@ -228,6 +234,9 @@ manager_log(isc_socketmgr_t *sockmgr, char msgbuf[2048]; va_list ap; + if (! isc_log_wouldlog(isc_lctx, level)) + return; + va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); va_end(ap); @@ -245,6 +254,9 @@ socket_log(isc_socket_t *sock, isc_sockaddr_t *address, char peerbuf[256]; va_list ap; + if (! isc_log_wouldlog(isc_lctx, level)) + return; + va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); va_end(ap); @@ -741,9 +753,10 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { if (SOFT_ERROR(errno)) return (DOIO_SOFT); - socket_log(sock, NULL, IOEVENT, - "doio_recv: recvmsg(%d) %d bytes, err %d/%s", - sock->fd, cc, errno, strerror(errno)); + if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) + socket_log(sock, NULL, IOEVENT, + "doio_recv: recvmsg(%d) %d bytes, err %d/%s", + sock->fd, cc, errno, strerror(errno)); #define SOFT_OR_HARD(_system, _isc) \ if (errno == _system) { \ @@ -1519,8 +1532,10 @@ internal_accept(isc_task_t *me, isc_event_t *ev) { * If some other error, ignore it as well and hope * for the best, but log it. */ - socket_log(sock, NULL, TRACE, - "accept() returned %d/%s", errno, strerror(errno)); + if (isc_log_wouldlog(isc_lctx, TRACE_LEVEL)) + socket_log(sock, NULL, TRACE, + "accept() returned %d/%s", errno, + strerror(errno)); fd = -1; @@ -1800,9 +1815,6 @@ watcher(void *uap) { UNLOCK(&manager->lock); cc = select(maxfd, &readfds, &writefds, NULL, NULL); - manager_log(manager, IOEVENT, - "select(%d, ...) == %d, errno %d/%s", - maxfd, cc, errno, strerror(errno)); if (cc < 0) { if (!SOFT_ERROR(errno)) FATAL_ERROR(__FILE__, __LINE__,