]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - continuous/gw-setup/run.pl
tmp
[can-benchmark.git] / continuous / gw-setup / run.pl
index d026b12fa0e3792e505a4e1366dd5e94e2b49553..f1bfe33fcca9fddf8bde06d1f7fdd8682bec55c8 100755 (executable)
@@ -2,10 +2,12 @@
 
 use FindBin;
 
+# Create startup script in ramdisk
 my $S99 = "$FindBin::Bin/initramfs/etc/init.d/S99benchmark";
 system("rm -f $S99");
 system("cat > $S99; chmod +x $S99") unless -t STDIN;
 
+# Boot gateway
 my $boot;
 my $pid = &run_boot;
 $|=1;
@@ -16,6 +18,7 @@ while (<$boot>){
 }
 die "Boot failed" unless $ready;
 
+# Measure latencies
 my $latester=<<'EOF';
 rm -f tmp-stat.txt
 echo "Starting latester"
@@ -34,13 +37,16 @@ my $status = system((qw(ssh -T glab), $latester));
 kill('TERM', -$pid);
 exit($status >> 8);
 
-
+# Helper functions
+sub kill_boot() { kill('TERM', -$pid) if defined $pid; }
 sub run_boot()
 {
     # die("No boot command") if ($#ARGV eq -1);
-    # my $bootcmd = "'".join("' '", @ARGV)."'";
+    my $bootcmd = "'".join("' '", @ARGV)."'";
+
+    $bootcmd ||= "$FindBin::Bin/boot";
 
-    my $bootcmd = "$FindBin::Bin/boot";
+    $SIG{INT} = sub { kill_boot(); exit; };
 
     pipe($boot, $wh) || die("pipe: $!");
     my $pid = fork() // die("fork: $!");
@@ -49,11 +55,11 @@ sub run_boot()
                    # background processes at once
        close($boot);
        open(STDERR, ">&", $wh) || die "Can't dup STDERR: $!";
-       my $cmd = "$bootcmd | tee /dev/stderr";
+       my $cmd = "$bootcmd 2>&1 | tee /dev/stderr";
        exec($cmd) || die "Can't exec $cmd: $!";
     }
     close($wh);
     return $pid;
 }
 
-END { kill('TERM', -$pid) if defined $pid; }
+END { kill_boot(); }