From owner-p4-projects@FreeBSD.ORG Sat Jun 5 12:50:24 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 45E531065679; Sat, 5 Jun 2010 12:50:24 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 094AD1065677 for ; Sat, 5 Jun 2010 12:50:24 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (unknown [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id EB0708FC1B for ; Sat, 5 Jun 2010 12:50:23 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o55CoNxa076994 for ; Sat, 5 Jun 2010 12:50:23 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o55CoNIn076992 for perforce@freebsd.org; Sat, 5 Jun 2010 12:50:23 GMT (envelope-from hselasky@FreeBSD.org) Date: Sat, 5 Jun 2010 12:50:23 GMT Message-Id: <201006051250.o55CoNIn076992@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 179216 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Jun 2010 12:50:24 -0000 http://p4web.freebsd.org/@@179216?ac=10 Change 179216 by hselasky@hselasky_laptop001 on 2010/06/05 12:49:46 LibUSB: - fix possibly broken IOCTL code that was submitted to make LibUSB build and work in Linux. - found during review. - not critical for the operation of LibUSB. Affected files ... .. //depot/projects/usb/src/lib/libusb/libusb10.c#26 edit Differences ... ==== //depot/projects/usb/src/lib/libusb/libusb10.c#26 (text+ko) ==== @@ -70,12 +70,30 @@ ctx->debug = level; } +static void +libusb_set_nonblocking(int f) +{ + int flags; + + /* + * We ignore any failures in this function, hence the + * non-blocking flag is not critical to the operation of + * libUSB. We use F_GETFL and F_SETFL to be compatible with + * Linux. + */ + + flags = fcntl(f, F_GETFL, NULL); + if (flags == -1) + return; + flags |= O_NONBLOCK; + fcntl(f, F_SETFL, flags); +} + int libusb_init(libusb_context **context) { struct libusb_context *ctx; char *debug; - int flag; int ret; ctx = malloc(sizeof(*ctx)); @@ -106,12 +124,8 @@ return (LIBUSB_ERROR_OTHER); } /* set non-blocking mode on the control pipe to avoid deadlock */ - flag = 1; - ret = fcntl(ctx->ctrl_pipe[0], O_NONBLOCK, &flag); - assert(ret != -1 && "Couldn't set O_NONBLOCK for ctx->ctrl_pipe[0]"); - flag = 1; - ret = fcntl(ctx->ctrl_pipe[1], O_NONBLOCK, &flag); - assert(ret != -1 && "Couldn't set O_NONBLOCK for ctx->ctrl_pipe[1]"); + libusb_set_nonblocking(ctx->ctrl_pipe[0]); + libusb_set_nonblocking(ctx->ctrl_pipe[1]); libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->ctrl_pipe[0], POLLIN);