From ea329d52db9610065797e28fae5e6ee6a8ed7985 Mon Sep 17 00:00:00 2001 From: Michael Tuexen <tuexen@fh-muenster.de> Date: Mon, 6 Jun 2016 12:03:22 +0200 Subject: [PATCH] Provide names for the threads. This helps in debugging. --- gtests/net/packetdrill/packetdrill.c | 16 +++++++++++++++- gtests/net/packetdrill/run_system_call.c | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gtests/net/packetdrill/packetdrill.c b/gtests/net/packetdrill/packetdrill.c index d95c6aaa..990e0a45 100644 --- a/gtests/net/packetdrill/packetdrill.c +++ b/gtests/net/packetdrill/packetdrill.c @@ -27,6 +27,10 @@ #include <arpa/inet.h> #include <assert.h> #include <getopt.h> +#include <pthread.h> +#if defined(__FreeBSD__) +#include <pthread_np.h> +#endif #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -64,9 +68,19 @@ static void run_init_scripts(struct config *config) int main(int argc, char *argv[]) { struct config config; + char **arg; + +#if defined(__APPLE__) + pthread_setname_np("main thread"); +#elif defined(linux) + prctl(PR_SET_NAME, "main thread"); +#elif defined(__FreeBSD__) + pthread_set_name_np(pthread_self(), "main thread"); +#endif + set_default_config(&config); /* Get command line options and list of test scripts. */ - char **arg = parse_command_line_options(argc, argv, &config); + arg = parse_command_line_options(argc, argv, &config); /* If we're running as a server, just listen for connections forever. */ if (config.is_wire_server) { diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c index 072dc959..5809c1ea 100644 --- a/gtests/net/packetdrill/run_system_call.c +++ b/gtests/net/packetdrill/run_system_call.c @@ -32,6 +32,9 @@ #include <netinet/in.h> #include <poll.h> #include <pthread.h> +#if defined(__FreeBSD__) +#include <pthread_np.h> +#endif #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -6174,6 +6177,13 @@ static void *system_call_thread(void *arg) struct syscall_spec *syscall = NULL; bool done = false; +#if defined(__APPLE__) + pthread_setname_np("syscall thread"); +#elif defined(linux) + prctl(PR_SET_NAME, "syscall thread"); +#elif defined(__FreeBSD__) + pthread_set_name_np(pthread_self(), "syscall thread"); +#endif DEBUGP("syscall thread: starting and locking\n"); run_lock(state); -- GitLab