Skip to contentSkip to conversation

TestSupport: use timeout(1)

PATCH In review Ian Jackson 2 participants 2 messages Dec 8, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 TestSupport: use timeout(1)

If a command we run times out, the machinery in tcmdex() will arrange for the ts-* script to spot the timeout, and stop waiting for it.

However it is also necessary for the command we ran to die. It has a copy of the owner daemon fd, so if it doesn't, our resources won't get freed. In sufficiently exciting bugs, our allocation might continue indefinitely, while a subprocess of ours hangs on after we are long gone.

timeout(1) does not print a message when the process times out (!) So we can't do away with the logic in tcmdex(). We set the timeout(1) timeout to 30s more than our own timeout, so that tcmdex() will time out first and print a message.

We could use alarm(1) as we do in Osstest/Serial/sympathy.pm but that program isn't packaged and its unsophisticated approach is not really appropriate for arbitrary nonconsenting programs.

---
 Osstest/TestSupport.pm |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Osstest/TestSupport.pm +4 -1
index a3b6936..ca680c0 100644
@@ -388,7 +388,10 @@ sub sshopts () {
 sub tcmdex {
     my ($timeout,$stdout,$cmd,$optsref,@args) = @_;
     logm("executing $cmd ... @args");
-    my $r= cmd($timeout,$stdout, $cmd,@$optsref,@args);
+    # We use timeout(1) as a backstop, in case $cmd doesn't die.  We
+    # need $cmd to die because we won't release the resources we own
+    # until all of our children are dead.
+    my $r= cmd($timeout,$stdout, 'timeout',$timeout+30, $cmd,@$optsref,@args);
     $r and die "status $r";
 }
 
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ian Jackson

If a command we run times out, the machinery in tcmdex() will arrange for the ts-* script to spot the timeout, and stop waiting for it.

However it is also necessary for the command we ran to die. It has a copy of the owner daemon fd, so if it doesn't, our resources won't get freed. In sufficiently exciting bugs, our allocation might continue indefinitely, while a subprocess of ours hangs on after we are long gone.

timeout(1) does not print a message when the process times out (!) So we can't do away with the logic in tcmdex().

I think you mean s/tcmdex/cmd/ in a few places here, since cmd() is where all the existing timeout stuff is.

Quoted 9 lines

We set the timeout(1)
timeout to 30s more than our own timeout, so that tcmdex() will time out first and print a message.

We could use alarm(1) as we do in Osstest/Serial/sympathy.pm but that program isn't packaged and its unsophisticated approach is not really appropriate for arbitrary nonconsenting programs.

Apart from that niggle:

Quoted 20 lines
---
 Osstest/TestSupport.pm |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Osstest/TestSupport.pm +4 -1
index a3b6936..ca680c0 100644
@@ -388,7 +388,10 @@ sub sshopts () {
 sub tcmdex {
     my ($timeout,$stdout,$cmd,$optsref,@args) = @_;
     logm("executing $cmd ... @args");
-    my $r= cmd($timeout,$stdout, $cmd,@$optsref,@args);
+    # We use timeout(1) as a backstop, in case $cmd doesn't die.  We
+    # need $cmd to die because we won't release the resources we own
+    # until all of our children are dead.
+    my $r= cmd($timeout,$stdout, 'timeout',$timeout+30, $cmd,@$optsref,@args);
     $r and die "status $r";
 }