fix: use pthread_self() for thread naming inside thread callback#839
Open
aki1770-del wants to merge 1 commit intoCOVESA:masterfrom
Open
fix: use pthread_self() for thread naming inside thread callback#839aki1770-del wants to merge 1 commit intoCOVESA:masterfrom
aki1770-del wants to merge 1 commit intoCOVESA:masterfrom
Conversation
pthread_setname_np() must be called from within the thread whose name is being set (Linux: max 15 chars, affects only the calling thread's /proc entry). Both dlt_segmented_nwt_handle and dlt_housekeeperthread_handle were passed as the first argument from inside the thread function itself, but the Linux man page specifies that passing a non-self TID is unreliable when the thread may not have been fully scheduled yet. Replace the stored handle argument with pthread_self() at both call sites so the name is always applied to the running thread. Fixes COVESA#811
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two thread functions set their thread name using a stored
pthread_thandle:On Linux,
pthread_setname_np(3)with a non-self TID is implemented viaprctl(PR_SET_NAME)on the target thread, but the stored handle may not be fully committed to the kernel thread table at the moment the call is made (the spawningpthread_create()and the thread start racing). Using the stored handle instead ofpthread_self()inside the thread body is a TOCTOU race.The POSIX-safe and portable approach is to call
pthread_setname_np(pthread_self(), name)from within the thread function, which is what this patch does.Reported in #811.
Fix
Replace the stored handle with
pthread_self()at both call sites.Testing
Thread names visible in
/proc/<pid>/task/*/commandps -Tcorrectly reflectdlt_segmentedanddlt_housekeepr(15-char kernel limit) after the fix.