sched_getcpu sysconf sync_file_range
])
+# Check for pthread_setname_np and its signature
+LTTNG_PTHREAD_SETNAME_NP
+
# Check if clock_gettime, timer_create, timer_settime, and timer_delete are available in lib rt, and if so,
# add -lrt to LIBS
AC_CHECK_LIB([rt], [clock_gettime, timer_create, timer_settime, timer_delete])
--- /dev/null
+# SYNOPSIS
+#
+# LTTNG_PTHREAD_SETNAME_NP
+#
+# LICENSE
+#
+# Copyright (c) 2020 Michael Jeanson <mjeanson@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+AC_DEFUN([LTTNG_PTHREAD_SETNAME_NP], [
+AC_REQUIRE([AX_PTHREAD])
+AC_LANG_PUSH([C])
+
+lttng_pthread_setname_np_save_LDFLAGS="$LDFLAGS"
+lttng_pthread_setname_np_save_LIBS="$LIBS"
+LDFLAGS="$LDFLAGS $PTHREAD_CFLAGS"
+LIBS="$LIBS $PTHREAD_LIBS"
+
+# GLIBC >= 2.12, Solaris >= 11.3
+AC_MSG_CHECKING(for pthread_setname_np(pthread_t, const char*))
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <pthread.h>],
+ [pthread_setname_np(pthread_self(), "example")])],
+ [AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_WITH_TID,1,
+ [Have function pthread_setname_np(pthread_t, const char*)])],
+ [AC_MSG_RESULT(no)])
+
+# MacOS X >= 10.6, iOS >= 3.2
+AC_MSG_CHECKING(for pthread_setname_np(const char*))
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <pthread.h>],
+ [pthread_setname_np("example")])],
+ [AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID,1,
+ [Have function pthread_setname_np(const char*)])],
+ [AC_MSG_RESULT(no)])
+
+LDFLAGS=$lttng_pthread_setname_np_save_LDFLAGS
+LIBS=$lttng_pthread_setname_np_save_LIBS
+
+AC_LANG_POP
+])dnl LTTNG_PTHREAD_SETNAME_NP
userspace-probe.c \
utils.c utils.h \
uuid.c uuid.h \
+ thread.c thread.h \
tracker.c tracker.h \
waiter.c waiter.h
libcompat_la_SOURCES = poll.h fcntl.h endian.h mman.h dirent.h \
socket.h compat-fcntl.c tid.h \
- getenv.h string.h prctl.h paths.h netdb.h $(COMPAT) \
+ getenv.h string.h paths.h pthread.h netdb.h $(COMPAT) \
time.h directory-handle.h directory-handle.c path.h
+++ /dev/null
-/*
- * Copyright (C) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * SPDX-License-Identifier: GPL-2.0-only
- *
- */
-
-#ifndef _COMPAT_PRCTL_H
-#define _COMPAT_PRCTL_H
-
-#ifdef __linux__
-#include <sys/prctl.h>
-
-static inline
-int lttng_prctl(int option, unsigned long arg2, unsigned long arg3,
- unsigned long arg4, unsigned long arg5)
-{
- return prctl(option, arg2, arg3, arg4, arg5);
-}
-
-#else
-
-#ifndef PR_SET_NAME
-#define PR_SET_NAME 0
-#endif /* PR_SET_NAME */
-
-static inline
-int lttng_prctl(int option, unsigned long arg2, unsigned long arg3,
- unsigned long arg4, unsigned long arg5)
-{
- return -ENOSYS;
-}
-
-#endif /* __linux__ */
-
-#endif /* _COMPAT_PRCTL_H */
--- /dev/null
+/*
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ */
+
+#ifndef _COMPAT_PTHREAD_H
+#define _COMPAT_PTHREAD_H
+
+#include <pthread.h>
+
+#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID)
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+ return pthread_setname_np(pthread_self(), name);
+}
+#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+ return pthread_setname_np(name);
+}
+#else
+/*
+ * For platforms without thread name support, do nothing.
+ */
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+ return -ENOSYS;
+}
+#endif
+
+#endif /* _COMPAT_PTHREAD_H */
#include <string.h>
#include <common/common.h>
+#include <common/thread.h>
#include <common/compat/getenv.h>
#include <lttng/lttng-error.h>
URCU_TLS(logger_thread_name) = name;
if (set_pthread_name) {
- char pthread_name[16];
-
- /*
- * Truncations are expected since pthread limits thread names to
- * a generous 16 characters.
- */
- strncpy(pthread_name, name, sizeof(pthread_name));
- pthread_name[sizeof(pthread_name) - 1] = '\0';
- ret = pthread_setname_np(pthread_self(), pthread_name);
- if (ret) {
+ ret = lttng_thread_setname(name);
+ if (ret && ret != -ENOSYS) {
+ /* Don't fail as this is not essential. */
DBG("Failed to set pthread name attribute");
}
}
#include <common/common.h>
#include <common/utils.h>
#include <common/compat/getenv.h>
-#include <common/compat/prctl.h>
#include <common/unix.h>
#include <common/defaults.h>
#include <common/lttng-elf.h>
+#include <common/thread.h>
#include <lttng/constant.h>
memset(worker->procname, 0, proc_orig_len);
strncpy(worker->procname, DEFAULT_RUN_AS_WORKER_NAME, proc_orig_len);
- ret = lttng_prctl(PR_SET_NAME,
- (unsigned long) DEFAULT_RUN_AS_WORKER_NAME, 0, 0, 0);
+ ret = lttng_thread_setname(DEFAULT_RUN_AS_WORKER_NAME);
if (ret && ret != -ENOSYS) {
/* Don't fail as this is not essential. */
- PERROR("prctl PR_SET_NAME");
+ DBG("Failed to set pthread name attribute");
}
memset(&sendret, 0, sizeof(sendret));
--- /dev/null
+/*
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <string.h>
+
+#include <common/compat/pthread.h>
+#include "thread.h"
+
+#define LTTNG_PTHREAD_NAMELEN 16
+
+int lttng_thread_setname(const char *name)
+{
+ int ret;
+ char pthread_name[LTTNG_PTHREAD_NAMELEN];
+
+ /*
+ * Truncations are expected since pthread limits thread names to
+ * a generous 16 characters.
+ */
+ strncpy(pthread_name, name, sizeof(pthread_name));
+ pthread_name[sizeof(pthread_name) - 1] = '\0';
+
+ ret = lttng_pthread_setname_np(pthread_name);
+
+ return ret;
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_THREAD_H
+#define LTTNG_THREAD_H
+
+#include <common/macros.h>
+
+/*
+ * Set the current thread name on platforms that support it. The name can
+ * be of arbitrary length and will be truncated to the platform limit,
+ * usually 16.
+ */
+LTTNG_HIDDEN
+int lttng_thread_setname(const char *name);
+
+#endif /* LTTNG_THREAD_H */