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);