diff mbox series

support: Add check for TID zero in support_wait_for_thread_exit

Message ID 878rze4690.fsf@oldenburg.str.redhat.com
State Committed
Commit 176c88f5214d8107d330971cbbfbbba5186a111f
Headers show
Series support: Add check for TID zero in support_wait_for_thread_exit | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Florian Weimer Sept. 30, 2021, 12:06 p.m. UTC
Some kernel versions (observed with kernel 5.14 and earlier) can list
"0" entries in /proc/self/task.  This happens when a thread exits
while the task list is being constructed.  Treat this entry as not
present, like the proposed kernel patch does:

[PATCH] procfs: Do not list TID 0 in /proc/<pid>/task
<https://lore.kernel.org/all/8735pn5dx7.fsf@oldenburg.str.redhat.com/>

---
 support/support_wait_for_thread_exit.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Carlos O'Donell Oct. 1, 2021, 3:27 p.m. UTC | #1
On 9/30/21 08:06, Florian Weimer via Libc-alpha wrote:
> Some kernel versions (observed with kernel 5.14 and earlier) can list
> "0" entries in /proc/self/task.  This happens when a thread exits
> while the task list is being constructed.  Treat this entry as not
> present, like the proposed kernel patch does:
> 
> [PATCH] procfs: Do not list TID 0 in /proc/<pid>/task
> <https://lore.kernel.org/all/8735pn5dx7.fsf@oldenburg.str.redhat.com/>

Upstream kernel patch has been ack by Christian Brauner.

Testing looks good on x86_64 and i686. Patchwork CI/CD is clean 2/2.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  support/support_wait_for_thread_exit.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/support/support_wait_for_thread_exit.c b/support/support_wait_for_thread_exit.c
> index 658a813810..5e3be421a7 100644
> --- a/support/support_wait_for_thread_exit.c
> +++ b/support/support_wait_for_thread_exit.c
> @@ -43,7 +43,10 @@ support_wait_for_thread_exit (void)
>            return;
>          }
>  
> -      if (strcmp (e->d_name, ".") == 0 || strcmp (e->d_name, "..") == 0)
> +      /* In some kernels, "0" entries denote a thread that has just
> +         exited.  */
> +      if (strcmp (e->d_name, ".") == 0 || strcmp (e->d_name, "..") == 0
> +          || strcmp (e->d_name, "0") == 0)

OK. Skip "0" entry.

>          continue;
>  
>        int task_tid = atoi (e->d_name);
>
diff mbox series

Patch

diff --git a/support/support_wait_for_thread_exit.c b/support/support_wait_for_thread_exit.c
index 658a813810..5e3be421a7 100644
--- a/support/support_wait_for_thread_exit.c
+++ b/support/support_wait_for_thread_exit.c
@@ -43,7 +43,10 @@  support_wait_for_thread_exit (void)
           return;
         }
 
-      if (strcmp (e->d_name, ".") == 0 || strcmp (e->d_name, "..") == 0)
+      /* In some kernels, "0" entries denote a thread that has just
+         exited.  */
+      if (strcmp (e->d_name, ".") == 0 || strcmp (e->d_name, "..") == 0
+          || strcmp (e->d_name, "0") == 0)
         continue;
 
       int task_tid = atoi (e->d_name);