aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorent Villard <warly@mandriva.com>2005-12-13 14:58:14 +0000
committerFlorent Villard <warly@mandriva.com>2005-12-13 14:58:14 +0000
commitbcbcc436d6464589bb35a7033e6b82a4bb5289e1 (patch)
treecd803be171dbc027ea08c34e67fe0a0f13d3a555
parent12288b0a62deeb750183e8368305e75f58f4deb2 (diff)
downloadiurt-bcbcc436d6464589bb35a7033e6b82a4bb5289e1.tar
iurt-bcbcc436d6464589bb35a7033e6b82a4bb5289e1.tar.gz
iurt-bcbcc436d6464589bb35a7033e6b82a4bb5289e1.tar.bz2
iurt-bcbcc436d6464589bb35a7033e6b82a4bb5289e1.tar.xz
iurt-bcbcc436d6464589bb35a7033e6b82a4bb5289e1.zip
Use alarm for perform_command (no more need to fork)
-rwxr-xr-xiurt290
1 files changed, 43 insertions, 47 deletions
diff --git a/iurt2 b/iurt2
index a490f4c..921b81a 100755
--- a/iurt2
+++ b/iurt2
@@ -435,61 +435,57 @@ sub fix_srpm_name {
}
sub perform_command {
- my ($command, %opt) = @_;
- $opt{timeout} ||= 300;
- $opt{freq} ||= 24;
- print "Timeout $opt{timeout}\n";
- my $p_pid = $$;
- my $pid = fork;
- my $stat;
- if ($pid) {
- print "$command\n";
- my $output;
- if ($opt{log}) {
- $output = `$command 2>&1 | tee $opt{log}/$opt{hash}.$run.log`;
- } else {
- $output = `$command 2>&1`;
- }
- # FIXME process goes in defunct always, kill -14 should unsleep it, but not
- kill 9, $pid;
- if ($? || $opt{error_regexp} && $output =~ /$opt{error_regexp}/) {
- if ($opt{mail}) {
- if ($::warning->{$opt{hash}}{$my_arch}{$opt{mail}} % $opt{freq}) {
- sendmail($opt{mail}, $opt{cc} , $opt{error} , $output, 0, 0);
- } else {
- sendmail('warly@mandriva.com', '' , $opt{error}, $output, 0, 0);
- }
- }
- $::warning->{$opt{hash}}{$my_arch}{$opt{mail}}++;
- print "\n$output\n";
- die "FATAL iurt: $opt{error}." if $opt{die};
- return 0
- }
+ my ($command, %opt) = @_;
+ $opt{timeout} ||= 300;
+ $opt{freq} ||= 24;
+ print "Timeout $opt{timeout}\n";
+ # from alarm perldoc
+ my $output;
+ eval {
+ local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
+ alarm $opt{timeout};
+ print "$command\n";
+ if ($opt{log}) {
+ $output = `$command 2>&1 | tee $opt{log}/$opt{hash}.$run.log`;
} else {
- my $t = sleep $opt{timeout};
- my ($cmd) = $command =~ s/^sudo //;
- my $pgrep=`pgrep -f "$cmd"`;
- print "iurt: PGREP $pgrep timeout $t\n";
- if ($t == $opt{timeout} && $pgrep) {
- print "\niurt: killing -9 $cmd\n\n";
- system(qq{sudo pkill -9 -u root -f "$cmd"});
+ $output = `$command 2>&1`;
+ }
+ alarm 0;
+ };
+ if ($@) {
+ # timed out
+ die unless $@ eq "alarm\n"; # propagate unexpected errors
+ return 0
+ } else {
+ # didn't
+ if ($? || $opt{error_regexp} && $output =~ /$opt{error_regexp}/) {
+ if ($opt{mail}) {
+ if ($::warning->{$opt{hash}}{$my_arch}{$opt{mail}} % $opt{freq}) {
+ sendmail($opt{mail}, $opt{cc} , $opt{error} , $output, 0, 0);
+ } else {
+ sendmail('warly@mandriva.com', '' , $opt{error}, $output, 0, 0);
}
- exit
+ }
+ $::warning->{$opt{hash}}{$my_arch}{$opt{mail}}++;
+ print "\n$output\n";
+ die "FATAL iurt: $opt{error}." if $opt{die};
+ return 0
}
- 1
+ }
+ 1
}
sub kill_for_good {
- my ($pid) = @_;
- kill 14, $pid;
+ my ($pid) = @_;
+ kill 14, $pid;
+ sleep 2;
+ if (getpgrp $pid != -1) {
+ kill 15, $pid;
sleep 2;
- if (getpgrp $pid != -1) {
- kill 15, $pid;
- sleep 2;
- if (getpgrp $pid != -1) {
- kill 9, $pid
- }
+ if (getpgrp $pid != -1) {
+ kill 9, $pid
}
+ }
}
sub dump_rpmmacros {