Linux: better EACCES handling
authorDaniel Drake <dsd@gentoo.org>
Sat, 3 May 2008 13:34:54 +0000 (14:34 +0100)
committerDaniel Drake <dsd@gentoo.org>
Sat, 3 May 2008 13:34:54 +0000 (14:34 +0100)
TODO
libusb/os/linux_usbfs.c

diff --git a/TODO b/TODO
index 4598e4f..955e501 100644 (file)
--- a/TODO
+++ b/TODO
@@ -7,7 +7,6 @@ doxygen warnings
 serialization of handle_events
 0.1 compat layer
 internal docs for OS porters
-passing of "access denied" error code from op_open
 
 1.0 API style/naming points to reconsider
 =========================================
index bf68d39..ecf6e0a 100644 (file)
@@ -399,8 +399,16 @@ static int op_open(struct libusb_device_handle *handle)
 
        hpriv->fd = open(dpriv->nodepath, O_RDWR);
        if (hpriv->fd < 0) {
-               usbi_err("open failed, code %d errno %d", hpriv->fd, errno);
-               return -EIO;
+               if (errno == EACCES) {
+                       fprintf(stderr, "libusb couldn't open USB device %s: "
+                               "Permission denied.\n"
+                               "libusb requires write access to USB device nodes.\n",
+                               dpriv->nodepath);
+                       return -EACCES;
+               } else {
+                       usbi_err("open failed, code %d errno %d", hpriv->fd, errno);
+                       return -EIO;
+               }
        }
 
        return usbi_add_pollfd(hpriv->fd, POLLOUT);