From 1ba0f93d81a93fdf3ec9d6e233f511e90a16888c Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 3 Apr 2015 14:42:59 +0200 Subject: [PATCH] syscall-dump: add TID (thread id) to log --- tools/syscall-dump.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/syscall-dump.c b/tools/syscall-dump.c index 4a89874b..e2658833 100644 --- a/tools/syscall-dump.c +++ b/tools/syscall-dump.c @@ -16,6 +16,7 @@ Usage: #include #include #include +#include #include #include #include @@ -31,6 +32,15 @@ Usage: #define REAL_LIBC ((void *) -1L) #endif +#ifdef SYS_gettid +static inline int gettid(void) +{ + return syscall(SYS_gettid); +} +#else +#error "SYS_gettid unavailable on this system" +#endif + /* Function pointers for real libc versions */ static int dlog_fd = -1; static int (*real_open)(const char *pathname, int flags, ...); @@ -69,8 +79,9 @@ static void dlog(const char *fmt, ...) dlog_fd = f ? real_open(f, O_CREAT|O_APPEND|O_WRONLY, 0600) : 2 /* stderr */; if (dlog_fd < 0) exit(1002); } + sprintf(buf, "[%5d]", gettid()); va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); + vsnprintf(buf + 7, sizeof(buf) - 7, fmt, ap); va_end(ap); REDIR(real_write, "write"); len = strlen(b = buf);