From 32189f6a593f224354f17d8032357ec84388ac5d Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Tue, 14 Feb 2023 17:28:55 -0800 Subject: [PATCH] send delv +ns output to stdout normally, the only output of delv that is sent to stdout is the final answer to the query; all other output is sent to stderr. this seems undesirable for delv +ns, which will only be used to see the process of finding the answer. so, for that case, we now send all the logging to stdout. --- bin/delv/delv.c | 12 ++++++++---- bin/delv/delv.rst | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 485b193d11..ad747368d5 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -88,7 +88,7 @@ #define MAXNAME (DNS_NAME_MAXTEXT + 1) /* Variables used internally by delv. */ -char *progname; +char *progname = NULL; static isc_mem_t *mctx = NULL; static isc_log_t *lctx = NULL; static dns_view_t *view = NULL; @@ -98,6 +98,7 @@ static dns_dispatch_t *dispatch = NULL; static dns_db_t *roothints = NULL; static isc_stats_t *resstats = NULL; static dns_stats_t *resquerystats = NULL; +static FILE *logfp = NULL; /* Managers */ static isc_nm_t *netmgr = NULL; @@ -1185,6 +1186,7 @@ plus_option(char *option) { if (state) { message_trace = state; resolve_trace = state; + logfp = stdout; } break; default: @@ -1889,7 +1891,6 @@ recvresponse(void *arg) { dns_request_t *request = (dns_request_t *)arg; dns_message_t *query = dns_request_getarg(request); isc_result_t result = dns_request_getresult(request); - ; dns_message_t *response = NULL; if (result != ISC_R_SUCCESS) { @@ -1967,7 +1968,7 @@ cleanup: dns_message_detach(&response); dns_request_destroy(&request); - view = NULL; + dns_view_detach(&view); shutdown_server(); } @@ -2018,6 +2019,7 @@ sendquery(void *arg) { CHECK(dns_requestmgr_create(mctx, dispatchmgr, NULL, NULL, &requestmgr)); + dns_view_attach(view, &(dns_view_t *){ NULL }); CHECK(dns_request_create(requestmgr, message, NULL, &peer, NULL, NULL, DNS_REQUESTOPT_TCP, NULL, 1, 0, 0, isc_loop_current(loopmgr), recvresponse, @@ -2119,6 +2121,8 @@ main(int argc, char *argv[]) { isc_loop_t *loop = NULL; progname = argv[0]; + logfp = stderr; + preparse_args(argc, argv); argc--; @@ -2136,7 +2140,7 @@ main(int argc, char *argv[]) { CHECK(setup_style()); - setup_logging(stderr); + setup_logging(logfp); if (fulltrace && server != NULL) { delv_log(ISC_LOG_WARNING, diff --git a/bin/delv/delv.rst b/bin/delv/delv.rst index 8b52f9f858..5d91fe75fb 100644 --- a/bin/delv/delv.rst +++ b/bin/delv/delv.rst @@ -237,12 +237,14 @@ assign values to options like the timeout interval. They have the form that to look up the requested query name and type. Turning on this option also activates ``+mtrace`` and ``+rtrace``, so that every iterative query will be logged, including the full response messages - from each authoritatve server. + from each authoritatve server. These logged messages will be written + to ``stdout`` rather than ``stderr`` as usual, so that the full trace + can be captured more easily. This is intended to be similar to the behavior of ``dig +trace``, but because it uses the same code as ``named``, it much more accurately replicates the behavior of a recursive name server with a cold cache - processing a recursive query. + that is processing a recursive query. .. option:: +ttl, +nottl