1 /* $NetBSD: named-journalprint.c,v 1.6 2014/12/10 04:37:54 christos Exp $ */
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 */
29 #include <dns/journal.h>
31 #include <dns/result.h>
32 #include <dns/types.h>
37 * Setup logging to use stderr.
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
);
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",
57 &destination
, 0) == ISC_R_SUCCESS
);
58 RUNTIME_CHECK(isc_log_usechannel(logconfig
, "stderr",
59 NULL
, NULL
) == ISC_R_SUCCESS
);
62 return (ISC_R_SUCCESS
);
66 main(int argc
, char **argv
) {
68 isc_mem_t
*mctx
= NULL
;
70 isc_log_t
*lctx
= NULL
;
73 printf("usage: %s journal\n", argv
[0]);
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);