Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Jun 2010 12:50:23 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 179216 for review
Message-ID:  <201006051250.o55CoNIn076992@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006051250.o55CoNIn076992>