@@ -236,7 +236,7 @@ static void *pidfd_info_pause_thread(void *arg)
236236
237237TEST_F (pidfd_info , thread_group )
238238{
239- pid_t pid_leader , pid_thread ;
239+ pid_t pid_leader , pid_poller , pid_thread ;
240240 pthread_t thread ;
241241 int nevents , pidfd_leader , pidfd_thread , pidfd_leader_thread , ret ;
242242 int ipc_sockets [2 ];
@@ -262,6 +262,35 @@ TEST_F(pidfd_info, thread_group)
262262 syscall (__NR_exit , EXIT_SUCCESS );
263263 }
264264
265+ /*
266+ * Opening a PIDFD_THREAD aka thread-specific pidfd based on a
267+ * thread-group leader must succeed.
268+ */
269+ pidfd_leader_thread = sys_pidfd_open (pid_leader , PIDFD_THREAD );
270+ ASSERT_GE (pidfd_leader_thread , 0 );
271+
272+ pid_poller = fork ();
273+ ASSERT_GE (pid_poller , 0 );
274+ if (pid_poller == 0 ) {
275+ /*
276+ * We can't poll and wait for the old thread-group
277+ * leader to exit using a thread-specific pidfd. The
278+ * thread-group leader exited prematurely and
279+ * notification is delayed until all subthreads have
280+ * exited.
281+ */
282+ fds .events = POLLIN ;
283+ fds .fd = pidfd_leader_thread ;
284+ nevents = poll (& fds , 1 , 10000 /* wait 5 seconds */ );
285+ if (nevents != 0 )
286+ _exit (EXIT_FAILURE );
287+ if (fds .revents & POLLIN )
288+ _exit (EXIT_FAILURE );
289+ if (fds .revents & POLLHUP )
290+ _exit (EXIT_FAILURE );
291+ _exit (EXIT_SUCCESS );
292+ }
293+
265294 /* Retrieve the tid of the thread. */
266295 EXPECT_EQ (close (ipc_sockets [1 ]), 0 );
267296 ASSERT_EQ (read_nointr (ipc_sockets [0 ], & pid_thread , sizeof (pid_thread )), sizeof (pid_thread ));
@@ -275,12 +304,7 @@ TEST_F(pidfd_info, thread_group)
275304 pidfd_thread = sys_pidfd_open (pid_thread , PIDFD_THREAD );
276305 ASSERT_GE (pidfd_thread , 0 );
277306
278- /*
279- * Opening a PIDFD_THREAD aka thread-specific pidfd based on a
280- * thread-group leader must succeed.
281- */
282- pidfd_leader_thread = sys_pidfd_open (pid_leader , PIDFD_THREAD );
283- ASSERT_GE (pidfd_leader_thread , 0 );
307+ ASSERT_EQ (wait_for_pid (pid_poller ), 0 );
284308
285309 /*
286310 * Note that pidfd_leader is a thread-group pidfd, so polling on it
0 commit comments