diff --git a/configure.ac b/configure.ac
index fb07249..cb79e96 100644
--- a/configure.ac
+++ b/configure.ac
@@ -687,7 +687,7 @@ AC_CHECK_HEADERS([sys/param.h sys/resource.h mach/mach_time.h])
 AC_CHECK_HEADERS([sys/select.h stdint.h inttypes.h sched.h malloc.h])
 AC_CHECK_HEADERS([sys/vfs.h sys/vmount.h sys/statfs.h sys/statvfs.h sys/filio.h])
 AC_CHECK_HEADERS([mntent.h sys/mnttab.h sys/vfstab.h sys/mntctl.h fstab.h])
-AC_CHECK_HEADERS([linux/magic.h])
+AC_CHECK_HEADERS([linux/magic.h sys/prctl.h])
 AC_CHECK_HEADERS([termios.h])
 
 # Some versions of MSC lack these
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 5fff514..7bbd0a9 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -60,6 +60,9 @@
 #ifdef HAVE_SCHED_H
 #include <sched.h>
 #endif
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
 #ifdef G_OS_WIN32
 #include <windows.h>
 #endif
@@ -1232,10 +1235,12 @@ g_system_thread_exit (void)
 void
 g_system_thread_set_name (const gchar *name)
 {
-#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID)
-  pthread_setname_np (pthread_self(), name); /* on Linux and Solaris */
+#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
+  prctl (PR_SET_NAME, name, 0, 0, 0, 0); /* on Linux */
 #elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
-  pthread_setname_np (name); /* on OS X and iOS */
+  pthread_setname_np(name); /* on OS X and iOS */
+#elif defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID)
+  pthread_setname_np(pthread_self(), name); /* on Solaris */
 #endif
 }
 
diff --git a/glib/tests/thread.c b/glib/tests/thread.c
index a79b951..4f754c2 100644
--- a/glib/tests/thread.c
+++ b/glib/tests/thread.c
@@ -174,12 +174,14 @@ test_thread5 (void)
 static gpointer
 thread6_func (gpointer data)
 {
-#if defined (HAVE_PTHREAD_SETNAME_NP_WITH_TID) && defined (HAVE_PTHREAD_GETNAME_NP)
-  char name[16];
+#ifdef HAVE_SYS_PRCTL_H
+#ifdef PR_GET_NAME
+  const gchar name[16];
 
-  pthread_getname_np (pthread_self(), name, 16);
+  prctl (PR_GET_NAME, name, 0, 0, 0, 0);
 
-  g_assert_cmpstr (name, ==, data);
+  g_assert_cmpstr (name, ==, (gchar*)data);
+#endif
 #endif
 
   return NULL;
