1/* 2 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 2000, 2001 Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18/* $Id: named-journalprint.c,v 1.2 2009/12/04 21:59:23 marka Exp $ */ 19 20/*! \file */ 21#include <config.h> 22 23#include <isc/log.h> 24#include <isc/mem.h> 25#include <isc/util.h> 26 27#include <dns/journal.h> 28#include <dns/log.h> 29#include <dns/result.h> 30#include <dns/types.h> 31 32#include <stdlib.h> 33 34/* 35 * Setup logging to use stderr. 36 */ 37static isc_result_t 38setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) { 39 isc_logdestination_t destination; 40 isc_logconfig_t *logconfig = NULL; 41 isc_log_t *log = NULL; 42 43 RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS); 44 isc_log_setcontext(log); 45 dns_log_init(log); 46 dns_log_setcontext(log); 47 48 destination.file.stream = errout; 49 destination.file.name = NULL; 50 destination.file.versions = ISC_LOG_ROLLNEVER; 51 destination.file.maximum_size = 0; 52 RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr", 53 ISC_LOG_TOFILEDESC, 54 ISC_LOG_DYNAMIC, 55 &destination, 0) == ISC_R_SUCCESS); 56 RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", 57 NULL, NULL) == ISC_R_SUCCESS); 58 59 *logp = log; 60 return (ISC_R_SUCCESS); 61} 62 63int 64main(int argc, char **argv) { 65 char *file; 66 isc_mem_t *mctx = NULL; 67 isc_result_t result; 68 isc_log_t *lctx = NULL; 69 70 if (argc != 2) { 71 printf("usage: %s journal\n", argv[0]); 72 return(1); 73 } 74 75 file = argv[1]; 76 77 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); 78 RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS); 79 80 result = dns_journal_print(mctx, file, stdout); 81 if (result == DNS_R_NOJOURNAL) 82 fprintf(stderr, "%s\n", dns_result_totext(result)); 83 isc_log_destroy(&lctx); 84 isc_mem_detach(&mctx); 85 return(result != ISC_R_SUCCESS ? 1 : 0); 86} 87