Date: Sat, 20 Nov 2010 19:13:05 +1300 From: Andrew Thompson <thompsa@FreeBSD.org> To: Jilles Tjoelker <jilles@stack.nl> 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 Message-ID: <AANLkTimjem=YW6Sh5jn3zk8U9KKxnqJPoxkqKbhTL%2B67@mail.gmail.com> In-Reply-To: <20101119152151.GC7614@stack.nl> References: <201011190117.oAJ1HnOT051021@svn.freebsd.org> <20101119152151.GC7614@stack.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
On 20 November 2010 04:21, Jilles Tjoelker <jilles@stack.nl> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTimjem=YW6Sh5jn3zk8U9KKxnqJPoxkqKbhTL%2B67>