From: Arran Cudbard-Bell Date: Tue, 5 May 2026 22:32:55 +0000 (-0400) Subject: Use existing thread names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84931a2d60af2abb089afd6259e16121ca829e2f;p=thirdparty%2Ffreeradius-server.git Use existing thread names Set the OS thread name for network and worker threads via pthread_setname_np so they appear in ps/top/htop output. Adds a configure check for pthread_setname_np (from pthread.h). Linux and macOS have different signatures (2-arg vs 1-arg), handled with an __APPLE__ guard matching the existing pattern in thread.c. --- diff --git a/src/lib/io/schedule.c b/src/lib/io/schedule.c index bb7a917b465..35ea2bcfd8f 100644 --- a/src/lib/io/schedule.c +++ b/src/lib/io/schedule.c @@ -135,20 +135,16 @@ static void *fr_schedule_worker_thread(void *arg) worker_id = sw->thread.id; /* Store the current worker ID */ + snprintf(worker_name, sizeof(worker_name), "Worker %d", sw->thread.id); + #ifdef HAVE_PTHREAD_SETNAME_NP - { - char os_name[16]; - snprintf(os_name, sizeof(os_name), "fr_worker_%d", sw->thread.id); # ifdef __APPLE__ - pthread_setname_np(os_name); + pthread_setname_np(worker_name); # else - pthread_setname_np(pthread_self(), os_name); + pthread_setname_np(pthread_self(), worker_name); # endif - } #endif - snprintf(worker_name, sizeof(worker_name), "Worker %d", sw->thread.id); - if (fr_thread_setup(&sw->thread, worker_name) < 0) goto fail; sw->worker = fr_worker_alloc(sw->thread.ctx, sw->thread.el, worker_name, sc->log, sc->lvl, &sc->config->worker); @@ -232,20 +228,16 @@ static void *fr_schedule_network_thread(void *arg) fr_thread_status_t status = FR_THREAD_FAIL; char network_name[32]; + snprintf(network_name, sizeof(network_name), "Network %d", sn->thread.id); + #ifdef HAVE_PTHREAD_SETNAME_NP - { - char os_name[16]; - snprintf(os_name, sizeof(os_name), "fr_network_%d", sn->thread.id); # ifdef __APPLE__ - pthread_setname_np(os_name); + pthread_setname_np(network_name); # else - pthread_setname_np(pthread_self(), os_name); + pthread_setname_np(pthread_self(), network_name); # endif - } #endif - snprintf(network_name, sizeof(network_name), "Network %d", sn->thread.id); - if (fr_thread_setup(&sn->thread, network_name) < 0) goto fail; sn->nr = fr_network_create(sn->thread.ctx, sn->thread.el, network_name, sc->log, sc->lvl, &sc->config->network);