tesh: kill may fail for background processes followed by foreground ones
Tested with tesh in 4ea9f48f "[tesh] check output on timeout".
MWE
hello.c
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void signal_handler(int signal)
{
printf("Got signal: %s\n", strsignal(signal));
exit(1);
}
int main()
{
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
printf("Going into an infinite loop.\n");
for (;;);
return 0;
}
pass.tesh
! timeout 1
& ./hello
Running tesh pass.tesh
does the expected: Cry because the process reached timeout and print its output:
Test suite '/tmp/tesh-kill/pass.tesh'
[pass.tesh:2] ./hello
Test suite `pass.tesh': NOK (<pass.tesh:2> timeout after 1 sec)
Output of <pass.tesh:2> mismatch:
--- expected
+++ obtained
@@ -0,0 +1,2 @@
+Going into an infinite loop.
+Got signal: Terminated
Test suite `pass.tesh': NOK (<pass.tesh:2> output mismatch)
fail.tesh
! timeout 1
& ./hello
$ sleep 0.1
$ sleep 0.1
Unfortunately, this one fails:
- output is lost
- log order is not intuitive
Test suite '/tmp/tesh-kill/fail.tesh'
[fail.tesh:4] sleep 0.1
[fail.tesh:2] ./hello
[fail.tesh:5] sleep 0.1
Test suite `fail.tesh': NOK (<fail.tesh:2> timeout after 1 sec)
[fail.tesh:2] Could not retrieve output. Killing the process group failed?
Problems detected:
- Looks like the second process is launched after the first one. tesh should wait for the process to start before launching the second one
- A single global is used to store the pgid to kill, this should probably be replaced by something better
Edited by Millian Poquet