summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>2021-02-12 19:21:18 +0700
committerAliaksey Kandratsenka <alkondratenko@gmail.com>2021-02-14 12:50:10 -0800
commitd9c4c3b481e641b719d3d790987ed7d094157bf2 (patch)
tree7e66e22443967089f633b736f76f0e23e153783c
parent43459feb33b87d3300e3b8b4917e5226678e4a0f (diff)
downloadgperftools-d9c4c3b481e641b719d3d790987ed7d094157bf2.tar.gz
profile-handler: use documented sigev_notify_thread_id in sigevent
sigevent(7) is documented to have sigev_notify_thread_id as its member. In glibc system, it's a macro expanded to the legacy _sigev_un._tid, _sigev_un._tid is obviously an internal implementation detail as signaled by its underscore prefix. And this macro was hidden inside linux/signal.h in older version of glibc. On Linux that use musl libc, sigev_notify_thread_id is also a macro, but it's expanded to __sev_fields.sigev_notify_thread_id [alkondratenko@gmail.com: amputated broken linux/signal.h dependency] [alkondratenko@gmail.com: see https://github.com/gperftools/gperftools/pull/1250] Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
-rw-r--r--src/profile-handler.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/profile-handler.cc b/src/profile-handler.cc
index 7fdcb69..fe3715b 100644
--- a/src/profile-handler.cc
+++ b/src/profile-handler.cc
@@ -49,6 +49,9 @@
#if HAVE_LINUX_SIGEV_THREAD_ID
// for timer_{create,settime} and associated typedefs & constants
#include <time.h>
+// for sigevent
+#include <signal.h>
+
// for sys_gettid
#include "base/linux_syscall_support.h"
// for perftools_pthread_key_create
@@ -61,6 +64,18 @@
#include "base/spinlock.h"
#include "maybe_threads.h"
+// Some Linux systems don't have sigev_notify_thread_id defined in
+// signal.h (despite having SIGEV_THREAD_ID defined) and also lack
+// working linux/signal.h. So lets workaround. Note, we know that at
+// least on Linux sigev_notify_thread_id is macro.
+//
+// See https://sourceware.org/bugzilla/show_bug.cgi?id=27417 and
+// https://bugzilla.kernel.org/show_bug.cgi?id=200081
+//
+#if __linux__ && HAVE_LINUX_SIGEV_THREAD_ID && !defined(sigev_notify_thread_id)
+#define sigev_notify_thread_id _sigev_un._tid
+#endif
+
using std::list;
using std::string;
@@ -272,7 +287,7 @@ static void StartLinuxThreadTimer(int timer_type, int signal_number,
struct itimerspec its;
memset(&sevp, 0, sizeof(sevp));
sevp.sigev_notify = SIGEV_THREAD_ID;
- sevp._sigev_un._tid = sys_gettid();
+ sevp.sigev_notify_thread_id = sys_gettid();
sevp.sigev_signo = signal_number;
clockid_t clock = CLOCK_THREAD_CPUTIME_ID;
if (timer_type == ITIMER_REAL) {