summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Stein <alexander.stein@mailbox.org>2020-02-05 21:41:07 +0100
committerChris Dickens <christopher.a.dickens@gmail.com>2020-02-07 15:59:30 -0800
commit6e0028ccb07918fe10a3a77beb1bbd56d31d6d1e (patch)
tree2bdbef49b5a54d0f5dd77b6c178d1ed42c0953c4
parenta5f6a43342d6bd0da57092ec4e1a6bce30bb2bce (diff)
downloadlibusb-6e0028ccb07918fe10a3a77beb1bbd56d31d6d1e.tar.gz
linux: provide an event thread name
Instead of having just the application name as thread name, provide a more descriptive one, which can e.g. read by htop. If setting the name fails, the thread will still work as intended, just raise a warning in this case. Closes #689 Signed-off-by: Alexander Stein <alexander.stein@mailbox.org> Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--configure.ac1
-rw-r--r--libusb/os/linux_netlink.c6
-rw-r--r--libusb/os/linux_udev.c6
-rw-r--r--libusb/version_nano.h2
4 files changed, 14 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 53a904e..6512078 100644
--- a/configure.ac
+++ b/configure.ac
@@ -143,6 +143,7 @@ linux)
THREAD_CFLAGS="-pthread"
LIBS="${LIBS} -pthread"
fi
+ AC_CHECK_FUNCS([pthread_setname_np])
;;
netbsd)
AC_DEFINE([OS_NETBSD], [1], [NetBSD backend])
diff --git a/libusb/os/linux_netlink.c b/libusb/os/linux_netlink.c
index 025ddd5..9917df2 100644
--- a/libusb/os/linux_netlink.c
+++ b/libusb/os/linux_netlink.c
@@ -365,6 +365,12 @@ static void *linux_netlink_event_thread_main(void *arg)
UNUSED(arg);
+#if defined(HAVE_PTHREAD_SETNAME_NP)
+ r = pthread_setname_np(pthread_self(), "libusb_event");
+ if (r)
+ usbi_warn(NULL, "failed to set hotplug event thread name, error=%d", r);
+#endif
+
usbi_dbg("netlink event thread entering");
while ((r = poll(fds, 2, -1)) >= 0 || errno == EINTR) {
diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c
index d079c79..d8851cf 100644
--- a/libusb/os/linux_udev.c
+++ b/libusb/os/linux_udev.c
@@ -176,6 +176,12 @@ static void *linux_udev_event_thread_main(void *arg)
.events = POLLIN},
};
+#if defined(HAVE_PTHREAD_SETNAME_NP)
+ r = pthread_setname_np(pthread_self(), "libusb_event");
+ if (r)
+ usbi_warn(NULL, "failed to set hotplug event thread name, error=%d", r);
+#endif
+
usbi_dbg("udev event thread entering.");
while ((r = poll(fds, 2, -1)) >= 0 || errno == EINTR) {
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 2256782..05e7280 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11455
+#define LIBUSB_NANO 11456