From 286a2beaa981296e94afbc2010584c0a421226c7 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 11 Mar 2019 17:36:58 +0100 Subject: [PATCH] bandk: store the worker name as part of 'struct bankd_worker' Change-Id: Ife981a4d555f96b63aeaedf27c3ebe513191b0c7 --- src/bankd.h | 3 +++ src/bankd_main.c | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/bankd.h b/src/bankd.h index f3770f2..5411968 100644 --- a/src/bankd.h +++ b/src/bankd.h @@ -46,6 +46,9 @@ struct bankd_worker { /* back-pointer to bankd */ struct bankd *bankd; + /* name of the worker */ + char *name; + /* thread number */ unsigned int num; /* worker thread state */ diff --git a/src/bankd_main.c b/src/bankd_main.c index f20d3b0..f0cb813 100644 --- a/src/bankd_main.c +++ b/src/bankd_main.c @@ -698,14 +698,9 @@ static void *worker_main(void *arg) { void *top_ctx; int rc; - char worker_name[32]; g_worker = (struct bankd_worker *) arg; - /* set the thread name */ - snprintf(worker_name, sizeof(worker_name), "bankd-worker(%u)", g_worker->num); - pthread_setname_np(pthread_self(), worker_name); - worker_set_state(g_worker, BW_ST_INIT); /* not permitted in multithreaded environment */ @@ -713,6 +708,10 @@ static void *worker_main(void *arg) top_ctx = talloc_named_const(NULL, 0, "top"); talloc_asn1_ctx = talloc_named_const(top_ctx, 0, "asn1"); + /* set the thread name */ + g_worker->name = talloc_asprintf(g_worker->tall_ctx, "bankd-worker(%u)", g_worker->num); + pthread_setname_np(pthread_self(), g_worker->name); + /* push cleanup helper */ pthread_cleanup_push(&worker_cleanup, g_worker);