diff mbox series

[ovs-dev,v5] util: fix an issue that thread name cannot be set

Message ID 202304190938517979390@chinatelecom.cn
State Accepted
Commit 3fa0fc5824324c11d78bf961648bb200da31d7bd
Headers show
Series [ovs-dev,v5] util: fix an issue that thread name cannot be set | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Songtao Zhan April 19, 2023, 1:38 a.m. UTC
To: dev@openvswitch.org,
    i.maximets@ovn.org

The name of the current thread consists of a name with a maximum
length of 16 bytes and a thread ID. The final name may be longer
than 16 bytes. If the name is longer than 16 bytes, the thread
name will fail to be set

Signed-off-by: Songtao Zhan <zhanst1@chinatelecom.cn>
---
 lib/util.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Eelco Chaudron April 19, 2023, 4:26 p.m. UTC | #1
On 19 Apr 2023, at 3:38, Songtao Zhan wrote:

> To: dev@openvswitch.org,
>     i.maximets@ovn.org
>
> The name of the current thread consists of a name with a maximum
> length of 16 bytes and a thread ID. The final name may be longer
> than 16 bytes. If the name is longer than 16 bytes, the thread
> name will fail to be set

Thanks for fixing this! Changes look good to me.

Acked-by: Eelco Chaudron <echaudro@redhat.com>

> Signed-off-by: Songtao Zhan <zhanst1@chinatelecom.cn>
> ---
>  lib/util.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/util.c b/lib/util.c
> index 96a71550d..5f230f5eb 100644
> --- a/lib/util.c
> +++ b/lib/util.c
> @@ -645,6 +645,12 @@ set_subprogram_name(const char *subprogram_name)
>      free(subprogram_name_set(pname));
>
>  #if HAVE_GLIBC_PTHREAD_SETNAME_NP
> +    /* The maximum thead name including '\0' supported is 16.
> +     * add '>' at 0th position to highlight that the name was truncated. */
> +    if (strlen(pname) > 15) {
> +        memmove(pname, &pname[strlen(pname) - 15], 15 + 1);
> +        pname[0] = '>';
> +    }
>      pthread_setname_np(pthread_self(), pname);
>  #elif HAVE_NETBSD_PTHREAD_SETNAME_NP
>      pthread_setname_np(pthread_self(), "%s", pname);
> -- 
> 2.39.1
>
>
>
>
> zhanst1@chinatelecom.cn
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Ilya Maximets April 25, 2023, 9:52 p.m. UTC | #2
On 4/19/23 18:26, Eelco Chaudron wrote:
> 
> 
> On 19 Apr 2023, at 3:38, Songtao Zhan wrote:
> 
>> To: dev@openvswitch.org,
>>     i.maximets@ovn.org
>>
>> The name of the current thread consists of a name with a maximum
>> length of 16 bytes and a thread ID. The final name may be longer
>> than 16 bytes. If the name is longer than 16 bytes, the thread
>> name will fail to be set
> 
> Thanks for fixing this! Changes look good to me.
> 
> Acked-by: Eelco Chaudron <echaudro@redhat.com>
> 
>> Signed-off-by: Songtao Zhan <zhanst1@chinatelecom.cn>

Applied.  Thanks!

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/lib/util.c b/lib/util.c
index 96a71550d..5f230f5eb 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -645,6 +645,12 @@  set_subprogram_name(const char *subprogram_name)
     free(subprogram_name_set(pname));

 #if HAVE_GLIBC_PTHREAD_SETNAME_NP
+    /* The maximum thead name including '\0' supported is 16.
+     * add '>' at 0th position to highlight that the name was truncated. */
+    if (strlen(pname) > 15) {
+        memmove(pname, &pname[strlen(pname) - 15], 15 + 1);
+        pname[0] = '>';
+    }
     pthread_setname_np(pthread_self(), pname);
 #elif HAVE_NETBSD_PTHREAD_SETNAME_NP
     pthread_setname_np(pthread_self(), "%s", pname);