Files
bind9/bin/tools/named-journalprint.c
Mark Andrews 0b793166d0 Refactor the isc_log API so it cannot fail on memory failures
The isc_mem API now crashes on memory allocation failure, and this is
the next commit in series to cleanup the code that could fail before,
but cannot fail now, e.g. isc_result_t return type has been changed to
void for the isc_log API functions that could only return ISC_R_SUCCESS.
2020-03-18 09:05:59 +01:00

79 lines
1.8 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <stdlib.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/util.h>
#include <dns/journal.h>
#include <dns/log.h>
#include <dns/result.h>
#include <dns/types.h>
/*
* Setup logging to use stderr.
*/
static isc_result_t
setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
isc_log_t *log = NULL;
isc_log_create(mctx, &log, &logconfig);
isc_log_setcontext(log);
dns_log_init(log);
dns_log_setcontext(log);
destination.file.stream = errout;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
ISC_R_SUCCESS);
*logp = log;
return (ISC_R_SUCCESS);
}
int
main(int argc, char **argv) {
char *file;
isc_mem_t *mctx = NULL;
isc_result_t result;
isc_log_t *lctx = NULL;
if (argc != 2) {
printf("usage: %s journal\n", argv[0]);
return (1);
}
file = argv[1];
isc_mem_create(&mctx);
RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS);
result = dns_journal_print(mctx, file, stdout);
if (result == DNS_R_NOJOURNAL) {
fprintf(stderr, "%s\n", dns_result_totext(result));
}
isc_log_destroy(&lctx);
isc_mem_detach(&mctx);
return (result != ISC_R_SUCCESS ? 1 : 0);
}