Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

varnishd: truncate thread name on Linux #4211

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bin/varnishd/cache/cache_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ THR_GetWorker(void)

static pthread_key_t name_key;

static void
thr_setname_generic(const char *name)
{
char buf[16];

/* The Linux kernel enforces a strict limitation of 15 bytes name,
* truncate the name if we would overflow it.
*/
if (strlen(name) > 15) {
bprintf(buf, "%.14s~", name);
name = buf;
}

PTOK(pthread_setname_np(pthread_self(), name));
}

void
THR_SetName(const char *name)
{
Expand All @@ -140,7 +156,7 @@ THR_SetName(const char *name)
#elif defined(__NetBSD__)
(void)pthread_setname_np(pthread_self(), "%s", (char *)(uintptr_t)name);
#else
(void)pthread_setname_np(pthread_self(), name);
thr_setname_generic(name);
#endif
}

Expand Down