Files
bind9/bin/tools/named-journalprint.c
Ondřej Surý 7a8193efba Use int type to store result from isc_commandline_parse()
The C standard actually doesn't define char as signed or unsigned, and
it could be either according to underlying architecture.  It turns out
that while it's usually signed type, it isn't on arm64 where it's
unsigned.

isc_commandline_parse() return int, just use that instead of the char.

(cherry picked from commit 8153729d3a)
2021-03-04 11:21:26 +01:00

118 lines
2.6 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <stdlib.h>
#include <isc/commandline.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/util.h>
#include <dns/journal.h>
#include <dns/log.h>
#include <dns/result.h>
#include <dns/types.h>
const char *progname = NULL;
static void
usage(void) {
fprintf(stderr, "Usage: %s [-dux] journal\n", progname);
exit(1);
}
/*
* Setup logging to use stderr.
*/
static isc_result_t
setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
isc_log_t *log = NULL;
isc_log_create(mctx, &log, &logconfig);
isc_log_setcontext(log);
dns_log_init(log);
dns_log_setcontext(log);
destination.file.stream = errout;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
ISC_R_SUCCESS);
*logp = log;
return (ISC_R_SUCCESS);
}
int
main(int argc, char **argv) {
char *file;
isc_mem_t *mctx = NULL;
isc_result_t result;
isc_log_t *lctx = NULL;
uint32_t flags = 0U;
int ch;
bool downgrade = false;
bool upgrade = false;
progname = argv[0];
while ((ch = isc_commandline_parse(argc, argv, "dux")) != -1) {
switch (ch) {
case 'd':
downgrade = true;
break;
case 'u':
upgrade = true;
break;
case 'x':
flags |= DNS_JOURNAL_PRINTXHDR;
break;
default:
usage();
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc != 1) {
usage();
}
file = argv[0];
isc_mem_create(&mctx);
RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS);
if (upgrade) {
flags = DNS_JOURNAL_COMPACTALL;
result = dns_journal_compact(mctx, file, 0, flags, 0);
} else if (downgrade) {
flags = DNS_JOURNAL_COMPACTALL | DNS_JOURNAL_VERSION1;
result = dns_journal_compact(mctx, file, 0, flags, 0);
} else {
result = dns_journal_print(mctx, flags, file, stdout);
if (result == DNS_R_NOJOURNAL) {
fprintf(stderr, "%s\n", dns_result_totext(result));
}
}
isc_log_destroy(&lctx);
isc_mem_detach(&mctx);
return (result != ISC_R_SUCCESS ? 1 : 0);
}