/contrib/bind9/bin/tools/named-journalprint.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 86 lines · 51 code · 14 blank · 21 comment · 10 complexity · 452cabe411d21520b5732c3382c42ff2 MD5 · raw file

  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. /* $Id: named-journalprint.c,v 1.2 2009/12/04 21:59:23 marka Exp $ */
  18. /*! \file */
  19. #include <config.h>
  20. #include <isc/log.h>
  21. #include <isc/mem.h>
  22. #include <isc/util.h>
  23. #include <dns/journal.h>
  24. #include <dns/log.h>
  25. #include <dns/result.h>
  26. #include <dns/types.h>
  27. #include <stdlib.h>
  28. /*
  29. * Setup logging to use stderr.
  30. */
  31. static isc_result_t
  32. setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
  33. isc_logdestination_t destination;
  34. isc_logconfig_t *logconfig = NULL;
  35. isc_log_t *log = NULL;
  36. RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS);
  37. isc_log_setcontext(log);
  38. dns_log_init(log);
  39. dns_log_setcontext(log);
  40. destination.file.stream = errout;
  41. destination.file.name = NULL;
  42. destination.file.versions = ISC_LOG_ROLLNEVER;
  43. destination.file.maximum_size = 0;
  44. RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr",
  45. ISC_LOG_TOFILEDESC,
  46. ISC_LOG_DYNAMIC,
  47. &destination, 0) == ISC_R_SUCCESS);
  48. RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
  49. NULL, NULL) == ISC_R_SUCCESS);
  50. *logp = log;
  51. return (ISC_R_SUCCESS);
  52. }
  53. int
  54. main(int argc, char **argv) {
  55. char *file;
  56. isc_mem_t *mctx = NULL;
  57. isc_result_t result;
  58. isc_log_t *lctx = NULL;
  59. if (argc != 2) {
  60. printf("usage: %s journal\n", argv[0]);
  61. return(1);
  62. }
  63. file = argv[1];
  64. RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
  65. RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS);
  66. result = dns_journal_print(mctx, file, stdout);
  67. if (result == DNS_R_NOJOURNAL)
  68. fprintf(stderr, "%s\n", dns_result_totext(result));
  69. isc_log_destroy(&lctx);
  70. isc_mem_detach(&mctx);
  71. return(result != ISC_R_SUCCESS ? 1 : 0);
  72. }