From owner-svn-src-stable@FreeBSD.ORG Sat Nov 20 06:39:54 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0227D106566C; Sat, 20 Nov 2010 06:39:54 +0000 (UTC) (envelope-from andy@fud.org.nz) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 6FE5F8FC08; Sat, 20 Nov 2010 06:39:53 +0000 (UTC) Received: by wwd20 with SMTP id 20so5296146wwd.31 for ; Fri, 19 Nov 2010 22:39:52 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.129.71 with SMTP id n7mr3255313wbs.128.1290233585483; Fri, 19 Nov 2010 22:13:05 -0800 (PST) Sender: andy@fud.org.nz Received: by 10.227.146.67 with HTTP; Fri, 19 Nov 2010 22:13:05 -0800 (PST) In-Reply-To: <20101119152151.GC7614@stack.nl> References: <201011190117.oAJ1HnOT051021@svn.freebsd.org> <20101119152151.GC7614@stack.nl> Date: Sat, 20 Nov 2010 19:13:05 +1300 X-Google-Sender-Auth: urTkqmot5R46UVbPwDDLBrd15Sw Message-ID: From: Andrew Thompson To: Jilles Tjoelker Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: svn-src-stable@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, svn-src-stable-8@freebsd.org Subject: Re: svn commit: r215475 - stable/8/lib/libusb X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Nov 2010 06:39:54 -0000 On 20 November 2010 04:21, Jilles Tjoelker wrote: > On Fri, Nov 19, 2010 at 01:17:49AM +0000, Andrew Thompson wrote: >> Author: thompsa >> Date: Fri Nov 19 01:17:49 2010 >> New Revision: 215475 >> URL: http://svn.freebsd.org/changeset/base/215475 > >> Log: >> =A0 MFC r203774 > >> =A0 =A0Use more standard way for setting nonblocking flag for a filedesc= riptor. >> =A0 =A0This makes libusb porting a bit easier. > >> Modified: >> =A0 stable/8/lib/libusb/libusb10.c >> Directory Properties: >> =A0 stable/8/lib/libusb/ =A0 (props changed) >> =A0 stable/8/lib/libusb/usb.h =A0 (props changed) >> >> Modified: stable/8/lib/libusb/libusb10.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- stable/8/lib/libusb/libusb10.c =A0 =A0Thu Nov 18 23:46:55 2010 =A0 = =A0 =A0 =A0(r215474) >> +++ stable/8/lib/libusb/libusb10.c =A0 =A0Fri Nov 19 01:17:49 2010 =A0 = =A0 =A0 =A0(r215475) > [...] >> @@ -105,10 +105,12 @@ libusb_init(libusb_context **context) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (LIBUSB_ERROR_OTHER); >> =A0 =A0 =A0 } >> =A0 =A0 =A0 /* set non-blocking mode on the control pipe to avoid deadlo= ck */ >> - =A0 =A0 ret =3D 1; >> - =A0 =A0 ioctl(ctx->ctrl_pipe[0], FIONBIO, &ret); >> - =A0 =A0 ret =3D 1; >> - =A0 =A0 ioctl(ctx->ctrl_pipe[1], FIONBIO, &ret); >> + =A0 =A0 flag =3D 1; >> + =A0 =A0 ret =3D fcntl(ctx->ctrl_pipe[0], O_NONBLOCK, &flag); >> + =A0 =A0 assert(ret !=3D -1 && "Couldn't set O_NONBLOCK for ctx->ctrl_p= ipe[0]"); >> + =A0 =A0 flag =3D 1; >> + =A0 =A0 ret =3D fcntl(ctx->ctrl_pipe[1], O_NONBLOCK, &flag); >> + =A0 =A0 assert(ret !=3D -1 && "Couldn't set O_NONBLOCK for ctx->ctrl_p= ipe[1]"); >> >> =A0 =A0 =A0 libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->ctrl_pip= e[0], POLLIN); > > This is not the correct way to use fcntl() to turn on non-blocking mode. > The correct way is > > =A0 =A0 =A0 =A0flag =3D fcntl(ctx->ctrl_pipe[0], F_GETFL, 0); > =A0 =A0 =A0 =A0if (flag !=3D -1) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D fcntl(ctx->ctrl_pipe[0], F_SETFL, = flag | O_NONBLOCK); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (ret =3D=3D -1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0handle_error(); > =A0 =A0 =A0 =A0} else > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0handle_error(); > > substituting some sort of error handling for handle_error(). > > This has been fixed in head in r213853, but that commit also makes other > changes. > > It turns out that on FreeBSD both F_SETFL and O_NONBLOCK have the value > 4, so there is some chance the desired result is achieved and fcntl() > will not fail. It may also set other flags for the open file > description, which could lead to unexpected results. I have merged r213853 now.