support: Kill process group for test failure

Message ID ec69b155-6546-d7dc-d8c4-056536a08aed@linaro.org
State Dropped
Headers

Commit Message

Adhemerval Zanella Feb. 20, 2020, 4:50 p.m. UTC
  On 20/02/2020 12:12, Carlos O'Donell wrote:
> On Thu, Feb 20, 2020 at 10:05 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * Adhemerval Zanella:
>>
>>> Some testcases that create multiple subprocesses might abort or exit
>>> prior waiting for their children.  In such case, support_test_main
>>> does not try to kill the spawned test process group (as in the
>>> test timeout case).
>>
>> Does this actually work?  Is the process group preserved if a process is
>> reparented to init?
> 
> No, you are right.
> 
> There is a race too which I didn't see.
> 
> Once you waitpid the pid and pgid might be free for reuse and we can't
> guarantee this will work.
> 

I tested by explicit injecting faulty fork calls with:


And without killing the process groups I see:

azanella 18876  6236 18874  7869  0 13:41 pts/0    00:00:00 ./elf/ld-linux-x86-64.so.2 --library-path .:./math:./elf:./dlfcn:./nss:./nis:./rt:./resolv:./mathvec:./support:./crypt:./nptl malloc/tst-mallocfork2
azanella 18878  6236 18874  7869  0 13:41 pts/0    00:00:00 ./elf/ld-linux-x86-64.so.2 --library-path .:./math:./elf:./dlfcn:./nss:./nis:./rt:./resolv:./mathvec:./support:./crypt:./nptl malloc/tst-mallocfork2
azanella 18879  6236 18874  7869  0 13:41 pts/0    00:00:00 ./elf/ld-linux-x86-64.so.2 --library-path .:./math:./elf:./dlfcn:./nss:./nis:./rt:./resolv:./mathvec:./support:./crypt:./nptl malloc/tst-mallocfork2
azanella 18880  6236 18874  7869  0 13:41 pts/0    00:00:00 ./elf/ld-linux-x86-64.so.2 --library-path .:./math:./elf:./dlfcn:./nss:./nis:./rt:./resolv:./mathvec:./support:./crypt:./nptl malloc/tst-mallocfork2
azanella 18881  6236 18874  7869  0 13:41 pts/0    00:00:00 ./elf/ld-linux-x86-64.so.2 --library-path .:./math:./elf:./dlfcn:./nss:./nis:./rt:./resolv:./mathvec:./support:./crypt:./nptl malloc/tst-mallocfork2

So the process group is still preserved even when it is reparented
to init (6236 is systemd in my case).  In any case, as Carlos pointed
out the issue is the possible race when the process fails, but it
has not spawn any process and thus its group id might be reused.

I would aiming to add a more generic solution, but it seems that
the testcase itself would need to handle it on the abort situations.
  

Patch

diff --git a/malloc/tst-mallocfork2.c b/malloc/tst-mallocfork2.c
index 0602a94895..c14cf9ef41 100644
--- a/malloc/tst-mallocfork2.c
+++ b/malloc/tst-mallocfork2.c
@@ -65,10 +65,13 @@  static volatile sig_atomic_t progress_indicator = 1;
 static void
 sigusr1_handler (int signo)
 {
+  static int count = 0;
   sigusr1_received = 1;

   /* Perform a fork with a trivial subprocess.  */
   pid_t pid = fork ();
+  if (++count == 100)
+    pid = -1;
   if (pid == -1)
     { 
       write_message ("error: fork\n");