]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Unify handling of the program name in all the utilities
authorOndřej Surý <ondrej@isc.org>
Wed, 28 May 2025 20:43:38 +0000 (22:43 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 29 May 2025 04:17:32 +0000 (06:17 +0200)
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.

36 files changed:
bin/check/named-checkconf.c
bin/check/named-checkzone.c
bin/confgen/rndc-confgen.c
bin/confgen/tsig-keygen.c
bin/confgen/util.c
bin/delv/delv.c
bin/dig/dig.c
bin/dig/dighost.c
bin/dig/dighost.h
bin/dig/host.c
bin/dig/nslookup.c
bin/dnssec/dnssec-cds.c
bin/dnssec/dnssec-dsfromkey.c
bin/dnssec/dnssec-importkey.c
bin/dnssec/dnssec-keyfromlabel.c
bin/dnssec/dnssec-keygen.c
bin/dnssec/dnssec-ksr.c
bin/dnssec/dnssec-revoke.c
bin/dnssec/dnssec-settime.c
bin/dnssec/dnssec-signzone.c
bin/dnssec/dnssec-verify.c
bin/dnssec/dnssectool.c
bin/dnssec/dnssectool.h
bin/named/main.c
bin/named/zoneconf.c
bin/rndc/rndc.c
bin/rndc/util.c
bin/tests/system/makejournal.c
bin/tests/wire_test.c
bin/tools/dnstap-read.c
bin/tools/named-journalprint.c
bin/tools/nsec3hash.c
lib/isc/commandline.c
lib/isc/file.c
lib/isc/include/isc/commandline.h
lib/isc/include/isc/file.h

index 98a73cf338c45be3b201ca6557bddcb27d4f7e69..471b36d1305c9282b63614321d04191b92de18b8 100644 (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);
        }
 
index b91192bed30774712ee606af5cd70dd4bb539f01..3b981c090dc6a75e12e158097ec58fc18058440c 100644 (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);
        }
index 5965c30b82c77f030fad1e2782edb323269125a3..94d8dec4008c113d0699c54efa67ca58e6505045 100644 (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);
index 344608dd34107038f51518c4d255d84d1c953e7e..75293193ed30e580867c66e6a752bc4ae20b10f3 100644 (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;
-
-       /*
-        * 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)
+       isc_commandline_init(argc, argv);
 
-       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;
index 5d7ce509e47cdcb1b45b0b9013bbd85946880879..c682ab93be1794f1e13a6b1465b5b52db8a66522 100644 (file)
 
 #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);
index 2a4bc30f3d04ed6dde1afba5a57f387a4e5b457f..d8c7966c33dd5e74219e26207dc296425fd76dfa 100644 (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);
index 8ede6acdb57095fa212f92f8ef7a2bef6ec23018..bb2abf880e265976a691a95338d9a30379af51d6 100644 (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);
 }
 
index b0651e3941aaf8764abeabde74261022419b4eb8..533dc79d2ef5a69fe78b3d42e6eb1c90d6db48b9 100644 (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;
index f1670280b4a5adb11a1c269f127ca2b250227873..3e446177e01ce0ed345abade012eb665930fc84e 100644 (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);
index b2cdf878d2c292e56c57c164489566c510af5406..746a0181486815a883ece383dd3e0e8932d01f44 100644 (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) {
index 8f6b57f5545a3e305441293381062249cc77160b..769a1b5f244231f915b61a11fc73f1674b9cd5cc 100644 (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);
index 457d5c5ac56ed39c20a89d973dfad637928ab746..3c7db4d0eda1359e6cfcde8010235225fa3a57c5 100644 (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);
index 4421a4574f42961d997eb03ae4662499ced794f1..6fd0d35dcb3e2b0d6ad1637bf8e5e482f0706ac9 100644 (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);
                }
index 8f81481cef06b9e6d11ad08ef2efd72cbcb72ef5..6d5b9a6eaaf02d68f4cf66083e60b0f3ef41191c 100644 (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);
                }
index 62fa2400300ae84f5883a14465ecc681a84eb42b..6d57204034095e5dab1eb941b2924512125c8a2b 100644 (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);
index b0679b03e4f96f54b45f4c47fa30f00b866e32d5..12bbbe0d852d91375e98ceb03307ccb006873106 100644 (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);
                }
index 826e635bb53274cee5f0a6db13672c6b4c0d32c5..189f8994fab3982a397365b1ebd6d73b92fdc3ca 100644 (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);
index b2d72011809077cb0f87af28e4128330ca9f7bb3..76dde76da5ae762939a534614b71ddaa547c4b9b 100644 (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);
index 72d4662f4f3ec6d2e5a1838a9bcbca95145d0e8b..a5d9451a9ec9e9eca239395e28463ecf8931ed6a 100644 (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);
        }
index c4b95dace992277ddc2b6125321fefb298b2845b..68a6cc5c2c6e5c30296955e76cb5206c4660ec11 100644 (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) {
index 536dedb48acda6dbaf25d87f145241673e0d13e8..e2ccb250cd4347b1b837f58ac1e277068b25bfaf 100644 (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);
                }
index e766aae0e732152c668124e66924349f646cf618..cb42bb710a1e49fdc3867514d860dcec674314b3 100644 (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,
index dc6a5dfe7574219912242e6eeb20b38d606a6f82..0702034c7e732d540167a6598e6ebd6aae5c9f1c 100644 (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;
 
index 8ee2edf576f992552a8325ae76ae10b0752a3a21..470d5723b34b40b82276b0d66868c6fb25be7477 100644 (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);
 
index 1b1c1842599f14917ce056ca65fe797d16533892..0cf76c3269b05b9d219d661d59350ca60427aa76 100644 (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>
index 03c4848ccbcdd49d5dbeeca9c4dce84bedb63980..a61886d9597cc709f266df88894d02708cc472ad 100644 (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,
index e0529aa77277d0dcfc1c8ca96f7835e396b2da2c..874864bbd2e02a43448fddde9aa8c955c47ef8a7 100644 (file)
 #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);
index 47e69c28922fde56e32564f37d8ca75bf7c05b3d..690c38fb4359b661a169621c85b4900d60df37a5 100644 (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(
index dda2cc82c9e46d98399c604bc86a260e2da5381b..c005b323e9e6f81dfcd70ea2edb6c820f4e9cd05 100644 (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>
index 8e21e5bf06fac78e936f38543a6e9ddb59893655..7f4c016f343f958eec02ed7548dd4ebc18e6b55c 100644 (file)
@@ -62,16 +62,15 @@ 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, \
-                               isc_result_totext(result));           \
-                       goto cleanup;                                 \
-               }                                                     \
+#define CHECKM(op, msg)                                        \
+       do {                                                   \
+               result = (op);                                 \
+               if (result != ISC_R_SUCCESS) {                 \
+                       fprintf(stderr, "%s: %s: %s\n",        \
+                               isc_commandline_progname, msg, \
+                               isc_result_totext(result));    \
+                       goto cleanup;                          \
+               }                                              \
        } while (0)
 
 ISC_NORETURN static void
@@ -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");
index 78dda92683d3625300756adf2d3e1a79028fe3df..08de975c84847ee8aac86771e86c3920ef3502af 100644 (file)
 #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) {
index e55800821e7f8c9a666cd4f3459b64a9528174ea..d5735be9efef132430c0a10c397576c2c481984c 100644 (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':
index 491830e976e60bb21cca02ac2e47e54c2802ed78..4e18730033224c08b60dacb94a960eaa976db2e0 100644 (file)
 
 #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]) != '-')
                {
index c476cf6ef8610e18e9982af5d01d6a505cdc0110..fe027ae24c03cbef0294f35a079ab90a22f7eebe 100644 (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);
-       len = strlen(base) + 1;
 
-       if (len > buflen) {
-               return ISC_R_NOSPACE;
+       /*
+        * Libtool doesn't preserve the program name prior to final
+        * installation.  Remove the libtool prefix ("lt-").
+        */
+       if (strncmp(base, "lt-", 3) == 0) {
+               base += 3;
        }
-       memmove(buf, base, len);
 
-       return ISC_R_SUCCESS;
+       len = strlen(base) + 1;
+
+       RUNTIME_CHECK(len <= buflen);
+
+       memmove(buf, base, len);
 }
 
 /*
index 2caec1f1d1df0dbcf7194656a38f6e0a4d8460c0..c0d226ddcc1d3f856c2c128b9e88a25b8dab934d 100644 (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);
 /*%<
index 200b2d6fb6e5c47a00f519d385f95c37b4e8f82f..ce23cedbe318630b3c508d35a300085d1f1cbcc0 100644 (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