From: Tony Finch Date: Fri, 2 Nov 2018 15:02:54 +0000 (+0000) Subject: dig: a -r option to disable .digrc X-Git-Tag: v9.13.4~22^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdb74fed9eee641873ad122032905a8bba9e36f1;p=thirdparty%2Fbind9.git dig: a -r option to disable .digrc --- diff --git a/bin/dig/dig.c b/bin/dig/dig.c index b7133803a3d..f1de7d44c13 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -66,7 +66,7 @@ static char hexcookie[81]; static bool short_form = false, printcmd = true, plusquest = false, pluscomm = false, - ipv4only = false, ipv6only = false; + ipv4only = false, ipv6only = false, digrc = true; static uint32_t splitwidth = 0xffffffff; /*% opcode text */ @@ -157,6 +157,7 @@ help(void) { " -m (enable memory usage debugging)\n" " -p port (specify port number)\n" " -q name (specify query name)\n" +" -r (do not read ~/.digrc)\n" " -t type (specify query type)\n" " -u (display times in usec instead of msec)\n" " -x dot-notation (shortcut for reverse lookups)\n" @@ -1543,8 +1544,8 @@ plus_option(char *option, bool is_batchfile, /*% * #true returned if value was used */ -static const char *single_dash_opts = "46dhimnuv"; -static const char *dash_opts = "46bcdfhikmnpqtvyx"; +static const char *single_dash_opts = "46dhimnruv"; +static const char *dash_opts = "46bcdfhikmnpqrtvyx"; static bool dash_option(char *option, char *next, dig_lookup_t **lookup, bool *open_type_class, bool *need_clone, @@ -1615,6 +1616,10 @@ dash_option(char *option, char *next, dig_lookup_t **lookup, case 'n': /* deprecated */ break; + case 'r': + debug("digrc (late)"); + digrc = false; + break; case 'u': (*lookup)->use_usec = true; break; @@ -1841,11 +1846,23 @@ preparse_args(int argc, char **argv) { option = &rv[0][1]; while (strpbrk(option, single_dash_opts) == &option[0]) { switch (option[0]) { + case 'd': + /* For debugging early startup */ + debugging = true; + break; case 'm': memdebugging = true; isc_mem_debugging = ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD; break; + case 'r': + /* + * Must be done early, because ~/.digrc + * is read before command line parsing + */ + debug("digrc (early)"); + digrc = false; + break; case '4': if (ipv6only) fatal("only one of -4 and -6 allowed"); @@ -1939,8 +1956,9 @@ parse_args(bool is_batchfile, bool config_only, */ INSIST(batchfp == NULL); homedir = getenv("HOME"); - if (homedir != NULL) { + if (homedir != NULL && digrc) { unsigned int n; + debug("digrc (open)"); n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir); if (n < sizeof(rcfile)) { diff --git a/bin/dig/dig.docbook b/bin/dig/dig.docbook index aa1bd3a38cb..79fdee9ec72 100644 --- a/bin/dig/dig.docbook +++ b/bin/dig/dig.docbook @@ -131,9 +131,10 @@ It is possible to set per-user defaults for dig via - ${HOME}/.digrc. This file is read and - any options in it - are applied before the command line arguments. + ${HOME}/.digrc. This file is read and any + options in it are applied before the command line arguments. + The option disables this feature, for + scripts that need predictable behaviour. @@ -323,6 +324,16 @@ + + -r + + + Do not read options from ${HOME}/.digrc. + This is useful for scripts that need predictable behaviour. + + + + -t type