Date: Wed, 11 May 2016 10:54:38 -0700 From: Conrad Meyer <cem@FreeBSD.org> To: svn-src-head@freebsd.org Cc: src-committers@freebsd.org, svn-src-all@freebsd.org Subject: Re: svn commit: r299473 - head/usr.bin/whois Message-ID: <CAG6CVpVWdW3s-Lu_=cRb1Sf8%2BaB=mn2GVFc6CeKowUu%2BrYpU0g@mail.gmail.com> In-Reply-To: <201605111752.u4BHq6TI054784@repo.freebsd.org> References: <201605111752.u4BHq6TI054784@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This commit message should have said: "No functional change." (As opposed to the follow-up commit which will come shortly.) Thanks, Conrad On Wed, May 11, 2016 at 10:52 AM, Conrad E. Meyer <cem@freebsd.org> wrote: > Author: cem > Date: Wed May 11 17:52:06 2016 > New Revision: 299473 > URL: https://svnweb.freebsd.org/changeset/base/299473 > > Log: > whois(1): Pull out async multiple host connection code into a routine > > This logic was added to the whois() function in r281959, but could easily be > its own routine. In this case, I think the abstraction makes both functions > easier to reason about. > > This precedes some Coverity-suggested cleanup. > > Sponsored by: EMC / Isilon Storage Division > > Modified: > head/usr.bin/whois/whois.c > > Modified: head/usr.bin/whois/whois.c > ============================================================================== > --- head/usr.bin/whois/whois.c Wed May 11 17:40:51 2016 (r299472) > +++ head/usr.bin/whois/whois.c Wed May 11 17:52:06 2016 (r299473) > @@ -285,19 +285,15 @@ s_asprintf(char **ret, const char *forma > va_end(ap); > } > > -static void > -whois(const char *query, const char *hostname, int flags) > +static int > +connect_to_any_host(struct addrinfo *hostres) > { > - FILE *fp; > - struct addrinfo *hostres, *res; > - char *buf, *host, *nhost, *p; > - int s = -1, f; > + struct addrinfo *res; > nfds_t i, j; > - size_t len, count; > + size_t count; > struct pollfd *fds; > - int timeout = 180; > + int timeout = 180, s = -1; > > - hostres = gethostinfo(hostname, 1); > for (res = hostres, count = 0; res; res = res->ai_next) > count++; > fds = calloc(count, sizeof(*fds)); > @@ -401,15 +397,29 @@ whois(const char *query, const char *hos > s = -1; > if (count == 0) > errno = ETIMEDOUT; > -done: > - if (s == -1) > - err(EX_OSERR, "connect()"); > > +done: > /* Close all watched fds except the succeeded one */ > for (j = 0; j < i; j++) > if (fds[j].fd != s && fds[j].fd != -1) > close(fds[j].fd); > free(fds); > + return (s); > +} > + > +static void > +whois(const char *query, const char *hostname, int flags) > +{ > + FILE *fp; > + struct addrinfo *hostres; > + char *buf, *host, *nhost, *p; > + int s, f; > + size_t len, i; > + > + hostres = gethostinfo(hostname, 1); > + s = connect_to_any_host(hostres); > + if (s == -1) > + err(EX_OSERR, "connect()"); > > /* Restore default blocking behavior. */ > if ((f = fcntl(s, F_GETFL)) == -1) >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpVWdW3s-Lu_=cRb1Sf8%2BaB=mn2GVFc6CeKowUu%2BrYpU0g>