2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 01:59:26 +00:00

Unify handling of the program name in all the utilities

There were several methods how we used 'argv[0]'.  Some programs had a
static value, some programs did use isc_file_progname(), some programs
stripped 'lt-' from the beginning of the name.  And some used argv[0]
directly.

Unify the handling and all the variables into isc_commandline_progname
that gets populated by the new isc_commandline_init(argc, argv) call.
This commit is contained in:
Ondřej Surý 2025-05-28 22:43:38 +02:00
parent ccf7a7dd7e
commit a676551395
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
36 changed files with 271 additions and 279 deletions

View File

@ -43,8 +43,6 @@
#include "check-tool.h"
static const char *program = "named-checkconf";
#define CHECK(r) \
do { \
result = (r); \
@ -61,7 +59,7 @@ usage(void) {
fprintf(stderr,
"usage: %s [-achijlvz] [-p [-x]] [-t directory] "
"[named.conf]\n",
program);
isc_commandline_progname);
exit(EXIT_SUCCESS);
}
@ -591,6 +589,8 @@ main(int argc, char **argv) {
unsigned int flags = 0;
unsigned int checkflags = BIND_CHECK_PLUGINS | BIND_CHECK_ALGORITHMS;
isc_commandline_init(argc, argv);
isc_commandline_errprint = false;
/*
@ -619,7 +619,7 @@ main(int argc, char **argv) {
}
isc_commandline_reset = true;
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) {
switch (c) {
@ -686,7 +686,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -694,18 +695,21 @@ main(int argc, char **argv) {
usage();
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
CHECK(ISC_R_FAILURE);
}
}
if (((flags & CFG_PRINTER_XKEY) != 0) && !print) {
fprintf(stderr, "%s: -x cannot be used without -p\n", program);
fprintf(stderr, "%s: -x cannot be used without -p\n",
isc_commandline_progname);
CHECK(ISC_R_FAILURE);
}
if (print && list_zones) {
fprintf(stderr, "%s: -l cannot be used with -p\n", program);
fprintf(stderr, "%s: -l cannot be used with -p\n",
isc_commandline_progname);
CHECK(ISC_R_FAILURE);
}

View File

@ -20,7 +20,6 @@
#include <isc/attributes.h>
#include <isc/commandline.h>
#include <isc/dir.h>
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/lib.h>
#include <isc/log.h>
@ -49,7 +48,6 @@ dns_zone_t *zone = NULL;
dns_zonetype_t zonetype = dns_zone_primary;
static int dumpzone = 0;
static const char *output_filename;
static const char *prog_name = NULL;
static const dns_master_style_t *outputstyle = NULL;
static enum { progmode_check, progmode_compile } progmode;
@ -78,7 +76,7 @@ usage(void) {
"[-M (ignore|warn|fail)] [-S (ignore|warn|fail)] "
"[-W (ignore|warn)] "
"%s zonename [ (filename|-) ]\n",
prog_name,
isc_commandline_progname,
progmode == progmode_check ? "[-o filename]" : "-o filename");
exit(EXIT_FAILURE);
}
@ -119,29 +117,13 @@ main(int argc, char **argv) {
outputstyle = &dns_master_style_full;
prog_name = strrchr(argv[0], '/');
if (prog_name == NULL) {
prog_name = strrchr(argv[0], '\\');
}
if (prog_name != NULL) {
prog_name++;
} else {
prog_name = argv[0];
}
/*
* Libtool doesn't preserve the program name prior to final
* installation. Remove the libtool prefix ("lt-").
*/
if (strncmp(prog_name, "lt-", 3) == 0) {
prog_name += 3;
}
isc_commandline_init(argc, argv);
#define PROGCMP(X) \
(strcasecmp(prog_name, X) == 0 || strcasecmp(prog_name, X ".exe") == 0)
if (PROGCMP("named-checkzone")) {
if (strcasecmp(isc_commandline_progname, "named-checkzone") == 0) {
progmode = progmode_check;
} else if (PROGCMP("named-compilezone")) {
} else if (strcasecmp(isc_commandline_progname, "named-compilezone") ==
0)
{
progmode = progmode_compile;
} else {
UNREACHABLE();
@ -441,14 +423,16 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
prog_name, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
usage();
default:
fprintf(stderr, "%s: unhandled option -%c\n", prog_name,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -535,7 +519,7 @@ main(int argc, char **argv) {
usage();
}
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
if (!quiet) {
RUNTIME_CHECK(setup_logging(errout) == ISC_R_SUCCESS);
}

View File

@ -31,7 +31,6 @@
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/file.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/net.h>
@ -55,9 +54,6 @@
#define DEFAULT_SERVER "127.0.0.1"
#define DEFAULT_PORT 953
static char program[256];
const char *progname;
bool verbose = false;
const char *keyfile, *keydef;
@ -81,7 +77,7 @@ Usage:\n\
-s addr: the address to which rndc should connect\n\
-t chrootdir: write a keyfile in chrootdir as well (requires -a)\n\
-u user: set the keyfile owner to \"user\" (requires -a)\n",
progname, keydef);
isc_commandline_progname, keydef);
exit(status);
}
@ -92,7 +88,6 @@ main(int argc, char **argv) {
isc_buffer_t key_txtbuffer;
char key_txtsecret[256];
isc_mem_t *mctx = NULL;
isc_result_t result = ISC_R_SUCCESS;
const char *keyname = NULL;
const char *serveraddr = NULL;
dns_secalg_t alg;
@ -108,15 +103,10 @@ main(int argc, char **argv) {
bool keyonly = false;
bool quiet = false;
int len;
const char *name = argv[0];
keydef = keyfile = RNDC_KEYFILE;
result = isc_file_progname(*argv, program, sizeof(program));
if (result != ISC_R_SUCCESS) {
memmove(program, "rndc-confgen", 13);
}
progname = program;
isc_commandline_init(argc, argv);
keyname = DEFAULT_KEYNAME;
alg = DST_ALG_HMACSHA256;
@ -195,14 +185,16 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
usage(EXIT_FAILURE);
} else {
usage(EXIT_SUCCESS);
}
break;
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -227,7 +219,7 @@ main(int argc, char **argv) {
}
algname = dst_hmac_algorithm_totext(alg);
isc_mem_create(name, &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret));
generate_key(mctx, alg, keysize, &key_txtbuffer);

View File

@ -27,7 +27,6 @@
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/file.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/net.h>
@ -50,8 +49,6 @@
#define KEYGEN_DEFAULT "tsig-key"
#define CONFGEN_DEFAULT "ddns-key"
static char program[256];
const char *progname;
static enum { progmode_keygen, progmode_confgen } progmode;
bool verbose = false; /* needed by util.c but not used here */
@ -69,13 +66,13 @@ Usage:\n\
-s name: domain name to be updated using the created key\n\
-z zone: name of the zone as it will be used in named.conf\n\
-q: quiet mode: print the key, with no explanatory text\n",
progname);
isc_commandline_progname);
} else {
fprintf(stderr, "\
Usage:\n\
%s [-a alg] [keyname]\n\
-a alg: algorithm (default hmac-sha256)\n\n",
progname);
isc_commandline_progname);
}
exit(status);
@ -83,7 +80,6 @@ Usage:\n\
int
main(int argc, char **argv) {
isc_result_t result = ISC_R_SUCCESS;
bool show_final_mem = false;
bool quiet = false;
isc_buffer_t key_txtbuffer;
@ -99,27 +95,12 @@ main(int argc, char **argv) {
int len = 0;
int ch;
result = isc_file_progname(*argv, program, sizeof(program));
if (result != ISC_R_SUCCESS) {
memmove(program, "tsig-keygen", 11);
}
progname = program;
isc_commandline_init(argc, argv);
/*
* Libtool doesn't preserve the program name prior to final
* installation. Remove the libtool prefix ("lt-").
*/
if (strncmp(progname, "lt-", 3) == 0) {
progname += 3;
}
#define PROGCMP(X) \
(strcasecmp(progname, X) == 0 || strcasecmp(progname, X ".exe") == 0)
if (PROGCMP("tsig-keygen")) {
if (strcasecmp(isc_commandline_progname, "tsig-keygen") == 0) {
progmode = progmode_keygen;
quiet = true;
} else if (PROGCMP("ddns-confgen")) {
} else if (strcasecmp(isc_commandline_progname, "ddns-confgen") == 0) {
progmode = progmode_confgen;
} else {
UNREACHABLE();
@ -182,14 +163,16 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
usage(EXIT_FAILURE);
} else {
usage(EXIT_SUCCESS);
}
break;
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -212,7 +195,7 @@ main(int argc, char **argv) {
/* Use canonical algorithm name */
algname = dst_hmac_algorithm_totext(alg);
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
if (keyname == NULL) {
const char *suffix = NULL;

View File

@ -21,10 +21,10 @@
#include <isc/tls.h>
#include "isc/commandline.h"
#include "util.h"
extern bool verbose;
extern const char *progname;
void
notify(const char *fmt, ...) {
@ -42,7 +42,7 @@ void
fatal(const char *format, ...) {
va_list args;
fprintf(stderr, "%s: ", progname);
fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);

View File

@ -31,6 +31,7 @@
#include <isc/attributes.h>
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/crypto.h>
#include <isc/hex.h>
#include <isc/lib.h>
@ -96,7 +97,6 @@
#define MAX_RESTARTS 11
/* Variables used internally by delv. */
char *progname = NULL;
static isc_mem_t *mctx = NULL;
static dns_view_t *view = NULL;
static ns_server_t *sctx = NULL;
@ -267,7 +267,7 @@ fatal(const char *format, ...) {
va_list args;
fflush(stdout);
fprintf(stderr, "%s: ", progname);
fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
@ -283,7 +283,7 @@ warn(const char *format, ...) {
va_list args;
fflush(stdout);
fprintf(stderr, "%s: warning: ", progname);
fprintf(stderr, "%s: warning: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
@ -2200,7 +2200,8 @@ main(int argc, char *argv[]) {
isc_result_t result;
isc_loop_t *loop = NULL;
progname = argv[0];
isc_commandline_init(argc, argv);
logfp = stderr;
preparse_args(argc, argv);

View File

@ -3405,10 +3405,9 @@ dig_setup(int argc, char **argv) {
dighost_warning = dig_warning;
dighost_comments = dig_comments;
progname = argv[0];
preparse_args(argc, argv);
setup_libs();
setup_libs(argc, argv);
setup_system(ipv4only, ipv6only);
}

View File

@ -36,6 +36,7 @@
#endif /* HAVE_LIBIDN2 */
#include <isc/base64.h>
#include <isc/commandline.h>
#include <isc/crypto.h>
#include <isc/file.h>
#include <isc/getaddresses.h>
@ -145,7 +146,6 @@ bool validated = true;
bool debugging = false;
bool debugtiming = false;
bool memdebugging = false;
char *progname = NULL;
dig_lookup_t *current_lookup = NULL;
#define DIG_MAX_ADDRESSES 20
@ -375,7 +375,7 @@ warn(const char *format, ...) {
va_list args;
fflush(stdout);
fprintf(stderr, "%s: ", progname);
fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
@ -399,7 +399,7 @@ fatal(const char *format, ...) {
va_list args;
fflush(stdout);
fprintf(stderr, "%s: ", progname);
fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
@ -1324,12 +1324,14 @@ set_search_domain(char *domain) {
* Setup the ISC and DNS libraries for use by the system.
*/
void
setup_libs(void) {
setup_libs(int argc, char **argv) {
isc_result_t result;
isc_logconfig_t *logconfig = NULL;
debug("setup_libs()");
isc_commandline_init(argc, argv);
result = isc_net_probeipv4();
if (result == ISC_R_SUCCESS) {
have_ipv4 = true;

View File

@ -271,7 +271,6 @@ extern bool free_now;
extern bool debugging, debugtiming, memdebugging;
extern bool keep_open;
extern char *progname;
extern int tries;
extern int fatalexit;
extern bool verbose;
@ -324,11 +323,8 @@ onrun_callback(void *arg);
void
run_loop(void *arg);
int
dhmain(int argc, char **argv);
void
setup_libs(void);
setup_libs(int argc, char **argv);
void
setup_system(bool ipv4only, bool ipv6only);

View File

@ -888,9 +888,8 @@ main(int argc, char **argv) {
dighost_shutdown = host_shutdown;
debug("main()");
progname = argv[0];
pre_parse_args(argc, argv);
setup_libs();
setup_libs(argc, argv);
setup_system(ipv4only, ipv6only);
parse_args(false, argc, argv);
if (keyfile[0] != 0) {

View File

@ -898,8 +898,7 @@ main(int argc, char **argv) {
dighost_trying = trying;
dighost_shutdown = start_next_command;
setup_libs();
progname = argv[0];
setup_libs(argc, argv);
setup_system(false, false);
parse_args(argc, argv);

View File

@ -60,8 +60,6 @@
#include "dnssectool.h"
const char *program = "dnssec-cds";
/*
* Infrastructure
*/
@ -1025,7 +1023,7 @@ usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr,
" %s options [options] -f <file> -d <path> <domain>\n",
program);
isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Options:\n"
" -a <algorithm> digest algorithm (SHA-1 / "
@ -1080,7 +1078,9 @@ main(int argc, char *argv[]) {
setfatalcallback(cleanup);
isc_mem_create(argv[0], &mctx);
isc_commandline_init(argc, argv);
isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
@ -1131,7 +1131,7 @@ main(int argc, char *argv[]) {
break;
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
break;
case 'v':
verbose = strtoul(isc_commandline_argument, &endp, 0);

View File

@ -48,8 +48,6 @@
#include "dnssectool.h"
const char *program = "dnssec-dsfromkey";
static dns_rdataclass_t rdclass;
static dns_fixedname_t fixed;
static dns_name_t *name = NULL;
@ -201,7 +199,7 @@ loadkey(char *filename, unsigned char *key_buf, unsigned int key_buf_size,
char keystr[DST_KEY_FORMATSIZE];
dst_key_format(key, keystr, sizeof(keystr));
fprintf(stderr, "%s: %s\n", program, keystr);
fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
result = dst_key_todns(key, &keyb);
@ -236,7 +234,7 @@ logkey(dns_rdata_t *rdata) {
}
dst_key_format(key, keystr, sizeof(keystr));
fprintf(stderr, "%s: %s\n", program, keystr);
fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
dst_key_free(&key);
}
@ -332,10 +330,13 @@ usage(void);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [options] keyfile\n\n", program);
fprintf(stderr, " %s [options] -f zonefile [zonename]\n\n", program);
fprintf(stderr, " %s [options] -s dnsname\n\n", program);
fprintf(stderr, " %s [-h|-V]\n\n", program);
fprintf(stderr, " %s [options] keyfile\n\n",
isc_commandline_progname);
fprintf(stderr, " %s [options] -f zonefile [zonename]\n\n",
isc_commandline_progname);
fprintf(stderr, " %s [options] -s dnsname\n\n",
isc_commandline_progname);
fprintf(stderr, " %s [-h|-V]\n\n", isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Options:\n"
" -1: digest algorithm SHA-1\n"
@ -376,7 +377,9 @@ main(int argc, char **argv) {
usage();
}
isc_mem_create(argv[0], &mctx);
isc_commandline_init(argc, argv);
isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
@ -405,7 +408,7 @@ main(int argc, char **argv) {
fprintf(stderr,
"%s: the -d option is deprecated; "
"use -K\n",
program);
isc_commandline_progname);
/* fall through */
case 'K':
dir = isc_commandline_argument;
@ -438,7 +441,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -447,10 +451,11 @@ main(int argc, char **argv) {
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}

View File

@ -46,8 +46,6 @@
#include "dnssectool.h"
const char *program = "dnssec-importkey";
static dns_rdataclass_t rdclass;
static dns_fixedname_t fixed;
static dns_name_t *name = NULL;
@ -169,7 +167,7 @@ loadkey(char *filename, unsigned char *key_buf, unsigned int key_buf_size,
char keystr[DST_KEY_FORMATSIZE];
dst_key_format(key, keystr, sizeof(keystr));
fprintf(stderr, "%s: %s\n", program, keystr);
fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
result = dst_key_todns(key, &keyb);
@ -270,8 +268,10 @@ usage(void);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s options [-K dir] keyfile\n\n", program);
fprintf(stderr, " %s options -f file [keyname]\n\n", program);
fprintf(stderr, " %s options [-K dir] keyfile\n\n",
isc_commandline_progname);
fprintf(stderr, " %s options -f file [keyname]\n\n",
isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -f file: read key from zone file\n");
@ -308,7 +308,9 @@ main(int argc, char **argv) {
usage();
}
isc_mem_create(argv[0], &mctx);
isc_commandline_init(argc, argv);
isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
@ -379,7 +381,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -388,10 +391,11 @@ main(int argc, char **argv) {
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}

View File

@ -43,8 +43,6 @@
#define MAX_RSA 4096 /* should be long enough... */
const char *program = "dnssec-keyfromlabel";
static uint16_t tag_min = 0, tag_max = 0xffff;
ISC_NORETURN static void
@ -53,7 +51,8 @@ usage(void);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s -l label [options] name\n\n", program);
fprintf(stderr, " %s -l label [options] name\n\n",
isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Required options:\n");
fprintf(stderr, " -l label: label of the key pair\n");
@ -149,7 +148,9 @@ main(int argc, char **argv) {
usage();
}
isc_mem_create(argv[0], &mctx);
isc_commandline_init(argc, argv);
isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
@ -320,7 +321,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -329,10 +331,11 @@ main(int argc, char **argv) {
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -515,7 +518,7 @@ main(int argc, char **argv) {
"indefinitely after rollover.\n\t "
"You can use dnssec-settime -D to "
"change this.\n",
program, keystr);
isc_commandline_progname, keystr);
}
setpub = setact = true;
@ -586,7 +589,7 @@ main(int argc, char **argv) {
"not flagged as a KSK, but -R "
"was used. Revoking a ZSK is "
"legal, but undefined.\n",
program);
isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_REVOKE, revoke);
}
@ -638,13 +641,14 @@ main(int argc, char **argv) {
isc_result_totext(ret));
}
if (exact) {
fatal("%s: %s already exists\n", program, filename);
fatal("%s: %s already exists\n",
isc_commandline_progname, filename);
}
if (avoid_collisions) {
fatal("%s: %s could collide with another key upon "
"revokation\n",
program, filename);
isc_commandline_progname, filename);
}
fprintf(stderr,
@ -652,7 +656,7 @@ main(int argc, char **argv) {
"another key upon revokation. If you plan "
"to revoke keys, destroy this key and "
"generate a different one.\n",
program, filename);
isc_commandline_progname, filename);
}
ret = dst_key_tofile(key, options, directory);

View File

@ -60,8 +60,6 @@
#include "dnssectool.h"
const char *program = "dnssec-keygen";
/*
* These are are set here for backwards compatibility. They are
* raised to 2048 in FIPS mode.
@ -132,7 +130,7 @@ typedef struct keygen_ctx keygen_ctx_t;
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [options] name\n\n", program);
fprintf(stderr, " %s [options] name\n\n", isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, " name: owner of the key\n");
fprintf(stderr, "Options:\n");
@ -449,7 +447,7 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv) {
"indefinitely after rollover.\n\t "
"You can use dnssec-settime -D to "
"change this.\n",
program, keystr);
isc_commandline_progname, keystr);
}
ctx->setpub = ctx->setact = true;
@ -612,7 +610,7 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv) {
"not flagged as a KSK, but -R "
"was used. Revoking a ZSK is "
"legal, but undefined.\n",
program);
isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_REVOKE,
ctx->revokekey);
@ -632,7 +630,7 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv) {
"scheduled to be deleted "
"before it is scheduled to be "
"made inactive.\n",
program);
isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_DELETE,
ctx->deltime);
@ -700,7 +698,8 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv) {
"might collide with another "
"key upon revokation. "
"Generating a new key\n",
program, filename);
isc_commandline_progname,
filename);
}
}
@ -782,6 +781,8 @@ main(int argc, char **argv) {
usage();
}
isc_commandline_init(argc, argv);
isc_commandline_errprint = false;
/*
@ -812,7 +813,7 @@ main(int argc, char **argv) {
}
isc_commandline_reset = true;
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) {
@ -1016,7 +1017,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -1025,10 +1027,11 @@ main(int argc, char **argv) {
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}

View File

@ -37,8 +37,6 @@
#include "dnssectool.h"
const char *program = "dnssec-ksr";
/*
* Infrastructure
*/
@ -121,7 +119,8 @@ isc_bufferlist_t cleanup_list = ISC_LIST_INITIALIZER;
static void
usage(int ret) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s options [options] <command> <zone>\n", program);
fprintf(stderr, " %s options [options] <command> <zone>\n",
isc_commandline_progname);
fprintf(stderr, "\n");
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "\n");
@ -464,7 +463,8 @@ create_key(ksr_ctx_t *ksr, dns_kasp_t *kasp, dns_kasp_key_t *kaspkey,
"might collide with another "
"key upon revokation. "
"Generating a new key\n",
program, filename);
isc_commandline_progname,
filename);
}
}
dst_key_free(&key);
@ -1326,7 +1326,9 @@ main(int argc, char *argv[]) {
.now = isc_stdtime_now(),
};
isc_mem_create(argv[0], &mctx);
isc_commandline_init(argc, argv);
isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
@ -1373,7 +1375,7 @@ main(int argc, char *argv[]) {
ksr.ksk = true;
break;
case 'V':
version(program);
version(isc_commandline_progname);
break;
case 'v':
verbose = strtoul(isc_commandline_argument, &endp, 0);

View File

@ -36,8 +36,6 @@
#include "dnssectool.h"
const char *program = "dnssec-revoke";
static isc_mem_t *mctx = NULL;
ISC_NORETURN static void
@ -46,7 +44,8 @@ usage(void);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [options] keyfile\n\n", program);
fprintf(stderr, " %s [options] keyfile\n\n",
isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, " -f: force overwrite\n");
fprintf(stderr, " -h: help\n");
@ -78,11 +77,13 @@ main(int argc, char **argv) {
bool removefile = false;
bool id = false;
isc_commandline_init(argc, argv);
if (argc == 1) {
usage();
}
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
@ -116,7 +117,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -125,10 +127,11 @@ main(int argc, char **argv) {
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -172,7 +175,7 @@ main(int argc, char **argv) {
dst_key_format(key, keystr, sizeof(keystr));
if (verbose > 2) {
fprintf(stderr, "%s: %s\n", program, keystr);
fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
if (force) {
@ -190,7 +193,7 @@ main(int argc, char **argv) {
"%s: warning: Key is not flagged "
"as a KSK. Revoking a ZSK is "
"legal, but undefined.\n",
program);
isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_REVOKE, now);

View File

@ -40,8 +40,6 @@
#include "dnssectool.h"
const char *program = "dnssec-settime";
static isc_mem_t *mctx = NULL;
ISC_NORETURN static void
@ -50,7 +48,8 @@ usage(void);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [options] keyfile\n\n", program);
fprintf(stderr, " %s [options] keyfile\n\n",
isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "General options:\n");
fprintf(stderr, " -f: force update of old-style "
@ -238,13 +237,15 @@ main(int argc, char **argv) {
bool printdsadd = false, printdsdel = false;
isc_stdtime_t now = isc_stdtime_now();
isc_commandline_init(argc, argv);
options = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_STATE;
if (argc == 1) {
usage();
}
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
setup_logging();
@ -336,7 +337,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -513,7 +515,7 @@ main(int argc, char **argv) {
break;
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
case 'v':
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0') {
@ -533,7 +535,8 @@ main(int argc, char **argv) {
break;
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -626,14 +629,14 @@ main(int argc, char **argv) {
"removal date;\n\t"
"it will remain in the zone "
"indefinitely after rollover.\n",
program);
isc_commandline_progname);
} else if (prevdel < previnact) {
fprintf(stderr,
"%s: warning: Predecessor is "
"scheduled to be deleted\n\t"
"before it is scheduled to be "
"inactive.\n",
program);
isc_commandline_progname);
}
changed = setpub = setact = true;
@ -718,7 +721,7 @@ main(int argc, char **argv) {
"%s: warning: Key is scheduled to "
"be deleted before it is\n\t"
"scheduled to be inactive.\n",
program);
isc_commandline_progname);
}
if (force) {
@ -728,7 +731,7 @@ main(int argc, char **argv) {
}
if (verbose > 2) {
fprintf(stderr, "%s: %s\n", program, keystr);
fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
/*
@ -752,14 +755,14 @@ main(int argc, char **argv) {
"%s: warning: Key %s is already "
"revoked; changing the revocation date "
"will not affect this.\n",
program, keystr);
isc_commandline_progname, keystr);
}
if ((dst_key_flags(key) & DNS_KEYFLAG_KSK) == 0) {
fprintf(stderr,
"%s: warning: Key %s is not flagged as "
"a KSK, but -R was used. Revoking a "
"ZSK is legal, but undefined.\n",
program, keystr);
isc_commandline_progname, keystr);
}
dst_key_settime(key, DST_TIME_REVOKE, rev);
} else if (unsetrev) {
@ -768,7 +771,7 @@ main(int argc, char **argv) {
"%s: warning: Key %s is already "
"revoked; removing the revocation date "
"will not affect this.\n",
program, keystr);
isc_commandline_progname, keystr);
}
dst_key_unsettime(key, DST_TIME_REVOKE);
}

View File

@ -92,8 +92,6 @@
#include "dnssectool.h"
const char *program = "dnssec-signzone";
typedef struct hashlist hashlist_t;
static int nsec_datatype = dns_rdatatype_nsec;
@ -1417,7 +1415,7 @@ setsoaserial(uint32_t serial, dns_updatemethod_t method) {
fprintf(stderr,
"%s: warning: Serial number would not advance, "
"using increment method instead\n",
program);
isc_commandline_progname);
}
/* If the new serial is not likely to cause a zone transfer
@ -1432,7 +1430,7 @@ setsoaserial(uint32_t serial, dns_updatemethod_t method) {
fprintf(stderr,
"%s: warning: Serial number not advanced, "
"zone may not transfer\n",
program);
isc_commandline_progname);
}
dns_soa_setserial(new_serial, &rdata);
@ -2862,7 +2860,7 @@ warnifallksk(dns_db_t *db) {
fprintf(stderr,
"%s: warning: No non-KSK DNSKEY found; "
"supply a ZSK or use '-z'.\n",
program);
isc_commandline_progname);
} else {
fatal("No non-KSK DNSKEY found; "
"supply a ZSK or use '-z'.");
@ -3109,7 +3107,8 @@ print_version(FILE *fp) {
return;
}
fprintf(fp, "; %s version %s\n", program, PACKAGE_VERSION);
fprintf(fp, "; %s version %s\n", isc_commandline_progname,
PACKAGE_VERSION);
}
ISC_NORETURN static void
@ -3118,7 +3117,8 @@ usage(void);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\t%s [options] zonefile [keys]\n", program);
fprintf(stderr, "\t%s [options] zonefile [keys]\n",
isc_commandline_progname);
fprintf(stderr, "\n");
@ -3276,6 +3276,8 @@ main(int argc, char *argv[]) {
atomic_init(&shuttingdown, false);
atomic_init(&finished, false);
isc_commandline_init(argc, argv);
/*
* Unused letters: Bb G J l q Yy (and F is reserved).
* l was previously used for DLV lookaside.
@ -3568,7 +3570,8 @@ main(int argc, char *argv[]) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
case 'h':
@ -3577,7 +3580,7 @@ main(int argc, char *argv[]) {
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
case 'Z': /* Undocumented test options */
if (!strcmp(isc_commandline_argument, "nonsecify")) {
@ -3586,7 +3589,8 @@ main(int argc, char *argv[]) {
break;
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -3743,7 +3747,7 @@ main(int argc, char *argv[]) {
fprintf(stderr,
"%s: warning: Specified key TTL %u "
"exceeds maximum zone TTL; reducing to %u\n",
program, keyttl, maxttl);
isc_commandline_progname, keyttl, maxttl);
keyttl = maxttl;
}
@ -3805,7 +3809,7 @@ main(int argc, char *argv[]) {
fprintf(stderr,
"%s: warning: No keys specified "
"or found\n",
program);
isc_commandline_progname);
} else {
fatal("No signing keys specified or found.");
}
@ -3826,7 +3830,7 @@ main(int argc, char *argv[]) {
fprintf(stderr,
"%s: warning: NSEC3 generation "
"requested with no DNSKEY; ignoring\n",
program);
isc_commandline_progname);
} else if (result != ISC_R_SUCCESS) {
check_result(result, "dns_nsec_nseconly");
} else if (answer) {

View File

@ -20,7 +20,6 @@
#include <isc/attributes.h>
#include <isc/base32.h>
#include <isc/commandline.h>
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/hex.h>
#include <isc/lib.h>
@ -64,8 +63,6 @@
#include "dnssectool.h"
const char *program = "dnssec-verify";
static isc_stdtime_t now;
static isc_mem_t *mctx = NULL;
static dns_masterformat_t inputformat = dns_masterformat_text;
@ -144,7 +141,8 @@ usage(void);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\t%s [options] zonefile [keys]\n", program);
fprintf(stderr, "\t%s [options] zonefile [keys]\n",
isc_commandline_progname);
fprintf(stderr, "\n");
@ -175,6 +173,8 @@ main(int argc, char *argv[]) {
char *endp;
int ch;
isc_commandline_init(argc, argv);
#define CMDLINE_FLAGS "c:E:hJ:m:o:I:qv:Vxz"
/*
@ -202,7 +202,7 @@ main(int argc, char *argv[]) {
}
isc_commandline_reset = true;
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
@ -254,7 +254,8 @@ main(int argc, char *argv[]) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
}
FALLTHROUGH;
@ -264,10 +265,11 @@ main(int argc, char *argv[]) {
case 'V':
/* Does not return. */
version(program);
version(isc_commandline_progname);
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}

View File

@ -26,7 +26,6 @@
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/dir.h>
#include <isc/file.h>
#include <isc/heap.h>
#include <isc/list.h>
#include <isc/log.h>
@ -76,7 +75,7 @@ void
fatal(const char *format, ...) {
va_list args;
fprintf(stderr, "%s: fatal: ", program);
fprintf(stderr, "%s: fatal: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
@ -106,7 +105,7 @@ vbprintf(int level, const char *fmt, ...) {
return;
}
va_start(ap, fmt);
fprintf(stderr, "%s: ", program);
fprintf(stderr, "%s: ", isc_commandline_progname);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
@ -153,7 +152,7 @@ setup_logging(void) {
logconfig = isc_logconfig_get();
isc_log_settag(logconfig, program);
isc_log_settag(logconfig, isc_commandline_progname);
/*
* Set up a channel similar to default_stderr except:
@ -537,7 +536,8 @@ isoptarg(const char *arg, char **argv, void (*usage)(void)) {
if (!strcasecmp(isc_commandline_argument, arg)) {
if (argv[isc_commandline_index] == NULL) {
fprintf(stderr, "%s: missing argument -%c %s\n",
program, isc_commandline_option,
isc_commandline_progname,
isc_commandline_option,
isc_commandline_argument);
usage();
}
@ -556,8 +556,8 @@ loadjournal(isc_mem_t *mctx, dns_db_t *db, const char *file) {
result = dns_journal_open(mctx, file, DNS_JOURNAL_READ, &jnl);
if (result == ISC_R_NOTFOUND) {
fprintf(stderr, "%s: journal file %s not found\n", program,
file);
fprintf(stderr, "%s: journal file %s not found\n",
isc_commandline_progname, file);
goto cleanup;
} else if (result != ISC_R_SUCCESS) {
fatal("unable to open journal %s: %s\n", file,

View File

@ -37,9 +37,6 @@
extern int verbose;
extern bool quiet;
/*! program name, statically initialized in each program */
extern const char *program;
/*! journal file */
extern const char *journal;

View File

@ -119,7 +119,6 @@ extern unsigned int dns_zone_mkey_day;
extern unsigned int dns_zone_mkey_month;
static bool want_stats = false;
static char program_name[NAME_MAX] = "named";
static char absolute_conffile[PATH_MAX];
static char saved_command_line[4096] = { 0 };
static char ellipsis[5] = { 0 };
@ -1050,8 +1049,8 @@ setup(void) {
ISC_LOG_NOTICE, "built with %s", PACKAGE_CONFIGARGS);
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "running as: %s%s%s", program_name,
saved_command_line, ellipsis);
ISC_LOG_NOTICE, "running as: %s%s%s",
isc_commandline_progname, saved_command_line, ellipsis);
#ifdef __clang__
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "compiled by CLANG %s", __VERSION__);
@ -1412,16 +1411,14 @@ main(int argc, char *argv[]) {
"> (" __DATE__ ")",
#endif
sizeof(version));
result = isc_file_progname(*argv, program_name, sizeof(program_name));
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("program name too long");
}
isc_commandline_init(argc, argv);
isc_assertion_setcallback(assertion_failed);
isc_error_setfatal(library_fatal_error);
isc_error_setunexpected(library_unexpected_error);
named_os_init(program_name);
named_os_init(isc_commandline_progname);
parse_command_line(argc, argv);

View File

@ -15,7 +15,6 @@
#include <stdbool.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/result.h>

View File

@ -55,7 +55,6 @@
#define SERVERADDRS 10
#define RNDC_TIMEOUT 60 * 1000
const char *progname = NULL;
bool verbose;
static isc_nm_t *netmgr = NULL;
@ -80,7 +79,6 @@ static bool c_flag = false;
static isc_mem_t *rndc_mctx = NULL;
static char *command = NULL;
static char *args = NULL;
static char program[256];
static uint32_t serial;
static bool quiet = false;
static bool showresult = false;
@ -234,7 +232,7 @@ command is one of the following:\n\
Display the current status of a zone.\n\
\n\
Version: %s\n",
progname, version);
isc_commandline_progname, version);
exit(status);
}
@ -333,11 +331,11 @@ rndc_recvdone(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
result = isccc_cc_lookupstring(data, "err", &errormsg);
if (result == ISC_R_SUCCESS) {
failed = true;
fprintf(stderr, "%s: '%s' failed: %s\n", progname, command,
errormsg);
fprintf(stderr, "%s: '%s' failed: %s\n",
isc_commandline_progname, command, errormsg);
} else if (result != ISC_R_NOTFOUND) {
fprintf(stderr, "%s: parsing response failed: %s\n", progname,
isc_result_totext(result));
fprintf(stderr, "%s: parsing response failed: %s\n",
isc_commandline_progname, isc_result_totext(result));
}
result = isccc_cc_lookupstring(data, "text", &textmsg);
@ -346,8 +344,8 @@ rndc_recvdone(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
fprintf(failed ? stderr : stdout, "%s\n", textmsg);
}
} else if (result != ISC_R_NOTFOUND) {
fprintf(stderr, "%s: parsing response failed: %s\n", progname,
isc_result_totext(result));
fprintf(stderr, "%s: parsing response failed: %s\n",
isc_commandline_progname, isc_result_totext(result));
}
if (showresult) {
@ -814,7 +812,6 @@ parse_config(isc_mem_t *mctx, const char *keyname, cfg_parser_t **pctxp,
int
main(int argc, char **argv) {
isc_result_t result = ISC_R_SUCCESS;
bool show_final_mem = false;
isc_logconfig_t *logconfig = NULL;
cfg_parser_t *pctx = NULL;
@ -827,11 +824,7 @@ main(int argc, char **argv) {
int ch;
int i;
result = isc_file_progname(*argv, program, sizeof(program));
if (result != ISC_R_SUCCESS) {
memmove(program, "rndc", 5);
}
progname = program;
isc_commandline_init(argc, argv);
admin_conffile = RNDC_CONFFILE;
admin_keyfile = RNDC_KEYFILE;
@ -928,7 +921,8 @@ main(int argc, char **argv) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
isc_commandline_progname,
isc_commandline_option);
usage(1);
}
FALLTHROUGH;
@ -936,7 +930,8 @@ main(int argc, char **argv) {
usage(0);
break;
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
fprintf(stderr, "%s: unhandled option -%c\n",
isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
@ -966,7 +961,7 @@ main(int argc, char **argv) {
isc_nm_setkeepalivetimeout(netmgr, timeout);
logconfig = isc_logconfig_get();
isc_log_settag(logconfig, progname);
isc_log_settag(logconfig, isc_commandline_progname);
isc_log_createandusechannel(
logconfig, "default_stderr", ISC_LOG_TOFILEDESC, ISC_LOG_INFO,
ISC_LOGDESTINATION_STDERR,

View File

@ -20,10 +20,10 @@
#include <stdlib.h>
#include <unistd.h>
#include <isc/commandline.h>
#include <isc/tls.h>
extern bool verbose;
extern const char *progname;
void
notify(const char *fmt, ...) {
@ -41,7 +41,7 @@ void
fatal(const char *format, ...) {
va_list args;
fprintf(stderr, "%s: ", progname);
fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);

View File

@ -16,6 +16,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <isc/commandline.h>
#include <isc/hash.h>
#include <isc/lib.h>
#include <isc/log.h>
@ -65,6 +66,8 @@ main(int argc, char **argv) {
dns_db_t *olddb = NULL, *newdb = NULL;
isc_logconfig_t *logconfig = NULL;
isc_commandline_init(argc, argv);
if (argc != 5) {
printf("usage: %s origin file1 file2 journal\n", argv[0]);
return 1;
@ -76,7 +79,7 @@ main(int argc, char **argv) {
journal = argv[4];
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
logconfig = isc_logconfig_get();
isc_log_createandusechannel(

View File

@ -17,7 +17,6 @@
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/file.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/result.h>

View File

@ -62,13 +62,12 @@ bool hexmessage = false;
bool yaml = false;
bool timestampmillis = false;
const char *program = "dnstap-read";
#define CHECKM(op, msg) \
do { \
result = (op); \
if (result != ISC_R_SUCCESS) { \
fprintf(stderr, "%s: %s: %s\n", program, msg, \
fprintf(stderr, "%s: %s: %s\n", \
isc_commandline_progname, msg, \
isc_result_totext(result)); \
goto cleanup; \
} \
@ -81,7 +80,7 @@ static void
fatal(const char *format, ...) {
va_list args;
fprintf(stderr, "%s: fatal: ", program);
fprintf(stderr, "%s: fatal: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
@ -344,6 +343,8 @@ main(int argc, char *argv[]) {
dns_dthandle_t *handle = NULL;
int rv = 0, ch;
isc_commandline_init(argc, argv);
while ((ch = isc_commandline_parse(argc, argv, "mptxy")) != -1) {
switch (ch) {
case 'm':
@ -375,7 +376,7 @@ main(int argc, char *argv[]) {
fatal("no file specified");
}
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
CHECKM(dns_dt_open(argv[0], dns_dtmode_file, mctx, &handle),
"dns_dt_openfile");

View File

@ -26,11 +26,9 @@
#include <dns/lib.h>
#include <dns/types.h>
const char *progname = NULL;
static void
usage(void) {
fprintf(stderr, "Usage: %s [-dux] journal\n", progname);
fprintf(stderr, "Usage: %s [-dux] journal\n", isc_commandline_progname);
exit(EXIT_FAILURE);
}
@ -59,7 +57,8 @@ main(int argc, char **argv) {
unsigned int serial = 0;
char *endp = NULL;
progname = argv[0];
isc_commandline_init(argc, argv);
while ((ch = isc_commandline_parse(argc, argv, "c:dux")) != -1) {
switch (ch) {
case 'c':
@ -93,7 +92,7 @@ main(int argc, char **argv) {
}
file = argv[0];
isc_mem_create(argv[0], &mctx);
isc_mem_create(isc_commandline_progname, &mctx);
setup_logging(stderr);
if (upgrade) {

View File

@ -20,7 +20,6 @@
#include <isc/base32.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/file.h>
#include <isc/hex.h>
#include <isc/iterated_hash.h>
#include <isc/lib.h>
@ -36,8 +35,6 @@
#include <dns/nsec3.h>
#include <dns/types.h>
const char *program = "nsec3hash";
ISC_NORETURN static void
fatal(const char *format, ...);
@ -45,7 +42,7 @@ static void
fatal(const char *format, ...) {
va_list args;
fprintf(stderr, "%s: ", program);
fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
@ -63,9 +60,9 @@ check_result(isc_result_t result, const char *message) {
static void
usage(void) {
fprintf(stderr, "Usage: %s salt algorithm iterations domain\n",
program);
isc_commandline_progname);
fprintf(stderr, " %s -r algorithm flags iterations salt domain\n",
program);
isc_commandline_progname);
exit(EXIT_FAILURE);
}
@ -163,6 +160,8 @@ main(int argc, char *argv[]) {
bool rdata_format = false;
int ch;
isc_commandline_init(argc, argv);
while ((ch = isc_commandline_parse(argc, argv, "-r")) != -1) {
switch (ch) {
case 'r':

View File

@ -49,8 +49,10 @@
#include <stdbool.h>
#include <stdio.h>
#include <zconf.h>
#include <isc/commandline.h>
#include <isc/file.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/util.h>
@ -62,12 +64,18 @@ int isc_commandline_option;
/*% Argument associated with option. */
char *isc_commandline_argument;
/*% For printing error messages. */
char *isc_commandline_progname;
char isc_commandline_progname[NAME_MAX];
/*% Print error messages. */
bool isc_commandline_errprint = true;
/*% Reset processing. */
bool isc_commandline_reset = true;
void
isc_commandline_init(int argc ISC_ATTR_UNUSED, char *const *argv) {
isc_file_progname(argv[0], isc_commandline_progname,
sizeof(isc_commandline_progname));
}
static char endopt = '\0';
#define BADOPT '?'
@ -95,10 +103,6 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) {
isc_commandline_reset = false;
}
if (isc_commandline_progname == NULL) {
isc_commandline_progname = argv[0];
}
if (isc_commandline_index >= argc ||
*(place = argv[isc_commandline_index]) != '-')
{

View File

@ -516,7 +516,7 @@ isc_file_basename(const char *filename) {
return s + 1;
}
isc_result_t
void
isc_file_progname(const char *filename, char *buf, size_t buflen) {
const char *base;
size_t len;
@ -525,14 +525,20 @@ isc_file_progname(const char *filename, char *buf, size_t buflen) {
REQUIRE(buf != NULL);
base = isc_file_basename(filename);
/*
* Libtool doesn't preserve the program name prior to final
* installation. Remove the libtool prefix ("lt-").
*/
if (strncmp(base, "lt-", 3) == 0) {
base += 3;
}
len = strlen(base) + 1;
if (len > buflen) {
return ISC_R_NOSPACE;
}
memmove(buf, base, len);
RUNTIME_CHECK(len <= buflen);
return ISC_R_SUCCESS;
memmove(buf, base, len);
}
/*

View File

@ -16,6 +16,7 @@
/*! \file isc/commandline.h */
#include <stdbool.h>
#include <zconf.h>
#include <isc/result.h>
#include <isc/types.h>
@ -27,12 +28,19 @@ extern int isc_commandline_option;
/*% Argument associated with option. */
extern char *isc_commandline_argument;
/*% For printing error messages. */
extern char *isc_commandline_progname;
extern char isc_commandline_progname[NAME_MAX];
/*% Print error message. */
extern bool isc_commandline_errprint;
/*% Reset getopt. */
extern bool isc_commandline_reset;
void
isc_commandline_init(int argc, char *const *argv);
/*%<
* Initialize isc_commandline unit internal and external variables.
* Currently, this only initializes isc_commandline_progname.
*/
int
isc_commandline_parse(int argc, char *const *argv, const char *options);
/*%<

View File

@ -239,7 +239,7 @@ isc_file_basename(const char *filename);
* Return the final component of the path in the file name.
*/
isc_result_t
void
isc_file_progname(const char *filename, char *buf, size_t buflen);
/*!<
* \brief Given an operating system specific file name "filename"
@ -250,10 +250,6 @@ isc_file_progname(const char *filename, char *buf, size_t buflen);
* names are case insensitive, the name is canonicalized to all
* lower case. The name is written to 'buf', an array of 'buflen'
* chars, and null terminated.
*
* Returns:
*\li #ISC_R_SUCCESS
*\li #ISC_R_NOSPACE The name did not fit in 'buf'.
*/
isc_result_t