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