"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/bin/tools/named-journalprint.c" (4 Sep 2020, 1880 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "named-journalprint.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /*! \file */
   13 
   14 #include <stdlib.h>
   15 
   16 #include <isc/log.h>
   17 #include <isc/mem.h>
   18 #include <isc/print.h>
   19 #include <isc/util.h>
   20 
   21 #include <dns/journal.h>
   22 #include <dns/log.h>
   23 #include <dns/result.h>
   24 #include <dns/types.h>
   25 
   26 /*
   27  * Setup logging to use stderr.
   28  */
   29 static isc_result_t
   30 setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
   31     isc_logdestination_t destination;
   32     isc_logconfig_t *logconfig = NULL;
   33     isc_log_t *log = NULL;
   34 
   35     isc_log_create(mctx, &log, &logconfig);
   36     isc_log_setcontext(log);
   37     dns_log_init(log);
   38     dns_log_setcontext(log);
   39 
   40     destination.file.stream = errout;
   41     destination.file.name = NULL;
   42     destination.file.versions = ISC_LOG_ROLLNEVER;
   43     destination.file.maximum_size = 0;
   44     isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
   45                   ISC_LOG_DYNAMIC, &destination, 0);
   46 
   47     RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
   48               ISC_R_SUCCESS);
   49 
   50     *logp = log;
   51     return (ISC_R_SUCCESS);
   52 }
   53 
   54 int
   55 main(int argc, char **argv) {
   56     char *file;
   57     isc_mem_t *mctx = NULL;
   58     isc_result_t result;
   59     isc_log_t *lctx = NULL;
   60 
   61     if (argc != 2) {
   62         printf("usage: %s journal\n", argv[0]);
   63         return (1);
   64     }
   65 
   66     file = argv[1];
   67 
   68     isc_mem_create(&mctx);
   69     RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS);
   70 
   71     result = dns_journal_print(mctx, file, stdout);
   72     if (result == DNS_R_NOJOURNAL) {
   73         fprintf(stderr, "%s\n", dns_result_totext(result));
   74     }
   75     isc_log_destroy(&lctx);
   76     isc_mem_detach(&mctx);
   77     return (result != ISC_R_SUCCESS ? 1 : 0);
   78 }