From owner-svn-src-all@freebsd.org Wed May 11 17:54:46 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 59978B373C1; Wed, 11 May 2016 17:54:46 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-oi0-f54.google.com (mail-oi0-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2A1A018F1; Wed, 11 May 2016 17:54:46 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-oi0-f54.google.com with SMTP id v145so80332467oie.0; Wed, 11 May 2016 10:54:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :date:message-id:subject:from:to:cc; bh=enb728PCsTq+xXl8+PX0uPMZdI98uZvfim4MZxlLd00=; b=cI9Zd07ttVtjEmpI7U4W8E8K59D3MJdMllh1Vqa01jVx7+t8x1Q/zW3FIXDDA8OO9R hJiWdhToJT1U1UV3X2XD9GtH+nSJeAI4NRhqQO0PdQwXWwxEO1SquNuaGRF6gojXF1Tj TDUYutW110r+bWYdmILZazVQkrJgpNV9aYX51nuoYupkwm+xRp4sgXhruPSTyMv1gNvU neMy1b7Nn29L95c2FQquNBdBRXmeCPETJRjeF/0vdfhDHX9HRVgUTZD20bdOEAja5/aZ 00FzvFZKSqB4awqig1jYiGTgJWXoKNqkix3COGPiEpdcnogJ+SVg+vSmbEXGtzy+82ec Y0IA== X-Gm-Message-State: AOPr4FXf0/oPneqvzYy33TcYKnaxiHKRDyoxl7aEHcZHWOqbFj194oyJEGnBl4Ts9kVlNg== X-Received: by 10.157.47.165 with SMTP id r34mr3076998otb.135.1462989279175; Wed, 11 May 2016 10:54:39 -0700 (PDT) Received: from mail-oi0-f45.google.com (mail-oi0-f45.google.com. [209.85.218.45]) by smtp.gmail.com with ESMTPSA id p31sm2484844ota.35.2016.05.11.10.54.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 May 2016 10:54:39 -0700 (PDT) Received: by mail-oi0-f45.google.com with SMTP id k142so80463864oib.1; Wed, 11 May 2016 10:54:38 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.202.102.222 with SMTP id m91mr2863623oik.79.1462989278555; Wed, 11 May 2016 10:54:38 -0700 (PDT) Reply-To: cem@FreeBSD.org Received: by 10.157.19.20 with HTTP; Wed, 11 May 2016 10:54:38 -0700 (PDT) In-Reply-To: <201605111752.u4BHq6TI054784@repo.freebsd.org> References: <201605111752.u4BHq6TI054784@repo.freebsd.org> Date: Wed, 11 May 2016 10:54:38 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r299473 - head/usr.bin/whois From: Conrad Meyer To: svn-src-head@freebsd.org Cc: src-committers@freebsd.org, svn-src-all@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2016 17:54:46 -0000 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 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) >