]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use existing thread names
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 May 2026 22:32:55 +0000 (18:32 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 May 2026 22:47:02 +0000 (18:47 -0400)
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.

src/lib/io/schedule.c

index bb7a917b4654761b29f69ec8a9914f45704d6fa7..35ea2bcfd8ff947c13a2b99033621ce0acccbc4c 100644 (file)
@@ -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);