diff --git a/sbin/mount_nfs/mount_nfs.c.sav b/sbin/mount_nfs/mount_nfs.c --- a/sbin/mount_nfs/mount_nfs.c.sav +++ b/sbin/mount_nfs/mount_nfs.c @@ -96,6 +96,7 @@ #define OF_NOINET6 0x08 #define BGRNDNOW 0x10 static int retrycnt = -1; +static int retrydns = 1; static int opflags = 0; static int nfsproto = IPPROTO_TCP; static int mnttcp_ok = 1; @@ -327,6 +328,12 @@ if (*p || num < 0) errx(1, "illegal retrycnt value -- %s", val); retrycnt = num; + } else if (strcmp(opt, "retrydns") == 0) { + pass_flag_to_nmount=0; + num = strtol(val, &p, 10); + if (*p || num < 0) + errx(1, "illegal retrydns value -- %s", val); + retrydns = num; } else if (strcmp(opt, "maxgroups") == 0) { num = strtol(val, &p, 10); if (*p || num <= 0) @@ -644,16 +651,37 @@ hints.ai_socktype = SOCK_DGRAM; if (getaddrinfo(hostp, portspec, &hints, &ai_nfs) != 0) { + unsigned int retrydns_timeout; + hints.ai_flags = AI_CANONNAME; - if ((ecode = getaddrinfo(hostp, portspec, &hints, &ai_nfs)) - != 0) { - if (portspec == NULL) - errx(1, "%s: %s", hostp, gai_strerror(ecode)); - else - errx(1, "%s:%s: %s", hostp, portspec, - gai_strerror(ecode)); - return (0); - } + retrydns_timeout = 1; + do { + retrydns--; + if ((ecode = getaddrinfo(hostp, portspec, &hints, + &ai_nfs)) != 0) { + if (retrydns == 0) { + if (portspec == NULL) + errx(1, "%s: %s", hostp, + gai_strerror(ecode)); + else + errx(1, "%s:%s: %s", hostp, + portspec, + gai_strerror(ecode)); + return (0); + } else { + if (portspec == NULL) + warnx("%s: %s", hostp, + gai_strerror(ecode)); + else + warnx("%s:%s: %s", + hostp, portspec, + gai_strerror(ecode)); + sleep(retrydns_timeout); + if (retrydns_timeout < 16) + retrydns_timeout *= 2; + } + } + } while (ecode != 0); /* * For a Kerberized nfs mount where the "principal"