Skip to content

fix: use pthread_self() in thread callbacks instead of parent-stored handle#844

Open
aki1770-del wants to merge 1 commit into
COVESA:masterfrom
aki1770-del:fix/dlt-pthread-setname-self-811
Open

fix: use pthread_self() in thread callbacks instead of parent-stored handle#844
aki1770-del wants to merge 1 commit into
COVESA:masterfrom
aki1770-del:fix/dlt-pthread-setname-self-811

Conversation

@aki1770-del
Copy link
Copy Markdown

Fixes #811.

Bug

Two thread callbacks in `src/lib/dlt_user.c` call `pthread_setname_np` with a handle stored by the parent thread:

  • `dlt_user_trace_network_segmented_thread` (line 3952): uses `dlt_user.dlt_segmented_nwt_handle`
  • `dlt_user_housekeeperthread_function` (line 4838): uses `dlt_housekeeperthread_handle`

Both handles are written by `pthread_create` in the parent. Because the callback begins executing before `pthread_create` returns, the handle is zero or uninitialized at the point `pthread_setname_np` is called. On musl C (standard in many embedded Linux / Yocto configurations), this causes a coredump.

The callbacks are already running in the target thread — `pthread_self()` is the correct and sufficient call.

Fix

```diff

  • if (pthread_setname_np(dlt_user.dlt_segmented_nwt_handle, "dlt_segmented"))
  • if (pthread_setname_np(pthread_self(), "dlt_segmented"))
    ```

```diff

  • if (pthread_setname_np(dlt_housekeeperthread_handle, "dlt_housekeeper"))
  • if (pthread_setname_np(pthread_self(), "dlt_housekeeper"))
    ```

Files: `src/lib/dlt_user.c` — +2/−2


AI-assisted — authored with Claude, reviewed by Komada.

…handle

pthread_setname_np is called with a handle stored by the parent thread
before pthread_create returns, causing a race where the handle is
zero/uninitialized at callback entry. On musl C this causes a coredump.
Replace both sites with pthread_self().

Fixes COVESA#811.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

about pthread_setname_np use(a probability bug in musl C)

1 participant