0b26f7
commit 4bf72519987ebc2be4a2058c670379040fae90ea
0b26f7
Author: Florian Weimer <fweimer@redhat.com>
0b26f7
Date:   Fri Oct 1 18:16:41 2021 +0200
0b26f7
0b26f7
    support: Add check for TID zero in support_wait_for_thread_exit
0b26f7
    
0b26f7
    Some kernel versions (observed with kernel 5.14 and earlier) can list
0b26f7
    "0" entries in /proc/self/task.  This happens when a thread exits
0b26f7
    while the task list is being constructed.  Treat this entry as not
0b26f7
    present, like the proposed kernel patch does:
0b26f7
    
0b26f7
    [PATCH] procfs: Do not list TID 0 in /proc/<pid>/task
0b26f7
    <https://lore.kernel.org/all/8735pn5dx7.fsf@oldenburg.str.redhat.com/>
0b26f7
    
0b26f7
    Fixes commit 032d74eaf6179100048a5bf0ce942e97dc8b9a60 ("support: Add
0b26f7
    support_wait_for_thread_exit").
0b26f7
    
0b26f7
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
0b26f7
    Tested-by: Carlos O'Donell <carlos@redhat.com>
0b26f7
    (cherry picked from commit 176c88f5214d8107d330971cbbfbbba5186a111f)
0b26f7
0b26f7
diff --git a/support/support_wait_for_thread_exit.c b/support/support_wait_for_thread_exit.c
0b26f7
index 658a81381006ea62..5e3be421a78a4c78 100644
0b26f7
--- a/support/support_wait_for_thread_exit.c
0b26f7
+++ b/support/support_wait_for_thread_exit.c
0b26f7
@@ -43,7 +43,10 @@ support_wait_for_thread_exit (void)
0b26f7
           return;
0b26f7
         }
0b26f7
 
0b26f7
-      if (strcmp (e->d_name, ".") == 0 || strcmp (e->d_name, "..") == 0)
0b26f7
+      /* In some kernels, "0" entries denote a thread that has just
0b26f7
+         exited.  */
0b26f7
+      if (strcmp (e->d_name, ".") == 0 || strcmp (e->d_name, "..") == 0
0b26f7
+          || strcmp (e->d_name, "0") == 0)
0b26f7
         continue;
0b26f7
 
0b26f7
       int task_tid = atoi (e->d_name);