aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjelmn <Nathan Hjelm hjelmn@cs.unm.edu>2013-07-29 10:22:53 -0600
committerhjelmn <Nathan Hjelm hjelmn@cs.unm.edu>2013-07-30 09:10:49 -0600
commit242d49c636b390d64740b79953c68c2b28cae8ff (patch)
treeb9b51860a8df69c1b08313c531b8d65b93b2ff19
parent252e193d9a910389baf9aa0736551f388c43e95c (diff)
downloadandroid_external_libusbx-242d49c636b390d64740b79953c68c2b28cae8ff.tar.gz
android_external_libusbx-242d49c636b390d64740b79953c68c2b28cae8ff.tar.bz2
android_external_libusbx-242d49c636b390d64740b79953c68c2b28cae8ff.zip
work around Linux systems that don't provide SOCK_CLOEXEC or SOCK_NONBLOCK
These options were added in 2.6.27 and are not available on all kernels that support netlink. Set these options using fcntl when SOCK_CLOEXEC and SOCK_NONBLOCK are not available. Closes #124.
-rw-r--r--libusb/os/linux_netlink.c17
-rw-r--r--libusb/version_nano.h2
2 files changed, 17 insertions, 2 deletions
diff --git a/libusb/os/linux_netlink.c b/libusb/os/linux_netlink.c
index 6dd0f8b..2a0268a 100644
--- a/libusb/os/linux_netlink.c
+++ b/libusb/os/linux_netlink.c
@@ -64,15 +64,30 @@ struct sockaddr_nl snl = { .nl_family=AF_NETLINK, .nl_groups=KERNEL };
int linux_netlink_start_event_monitor(void)
{
+ int socktype = SOCK_RAW;
int ret;
snl.nl_groups = KERNEL;
- linux_netlink_socket = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);
+#if defined(SOCK_CLOEXEC)
+ socktype |= SOCK_CLOEXEC;
+#endif
+#if defined(SOCK_NONBLOCK)
+ socktype |= SOCK_NONBLOCK;
+#endif
+
+ linux_netlink_socket = socket(PF_NETLINK, socktype, NETLINK_KOBJECT_UEVENT);
if (-1 == linux_netlink_socket) {
return LIBUSB_ERROR_OTHER;
}
+#if !defined(SOCK_CLOEXEC) && defined(FD_CLOEXEC)
+ fcntl (linux_netlink_socket, F_SETFD, FD_CLOEXEC);
+#endif
+#if !defined(SOCK_NONBLOCK)
+ fcntl (linux_netlink_socket, F_SETFL, O_NONBLOCK);
+#endif
+
ret = bind(linux_netlink_socket, (struct sockaddr *) &snl, sizeof(snl));
if (0 != ret) {
return LIBUSB_ERROR_OTHER;
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index fc3efff..d9cef34 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10780
+#define LIBUSB_NANO 10781