From 0fdf2b894e27cb34c2793c7b1eb21776f823c888 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Kr=C3=BCger?= Date: Fri, 5 Nov 2010 06:17:54 +0100 Subject: [PATCH] jobd: shotgun fixes for new job handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Disconnect child processes from our STDIN to prevent confusing them - Shorten delay in children to prevent annoying slowdowns - Don't consider processes for hang checks if they are not running in the first place - Simplify and correctify code for running success/error handlers Signed-off-by: Jan Krüger --- jobd/jobd.pl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/jobd/jobd.pl b/jobd/jobd.pl index 6e0fe90..3ca416e 100755 --- a/jobd/jobd.pl +++ b/jobd/jobd.pl @@ -146,6 +146,11 @@ sub exec_job_command { return; } if (!$pid) { + open STDIN, '/dev/null' || do { + error(_job_name($job) ."Can't read from /dev/null: $!"); + $job->{'finished'} = 1; + return; + } if ($err_only) { open STDOUT, '>/dev/null' || do { error(_job_name($job) ." Can't write to /dev/null: $!"); @@ -154,7 +159,7 @@ sub exec_job_command { }; } # "Prevent" races - select(undef, undef, undef, 0.25); + select(undef, undef, undef, 0.1); exec @$command; # Stop perl from complaining exit $?; @@ -171,7 +176,7 @@ sub job_skip { sub reap_hanging_jobs { for (@running) { - if ((time - $_->{'started_at'}) > $kill_after) { + if (defined($_->{'started_at'}) && (time - $_->{'started_at'}) > $kill_after) { $_->{'finished'} = 1; kill 'KILL', $_->{'pid'}; print STDERR _job_name($_) ." KILLED due to timeout\n"; @@ -190,15 +195,12 @@ sub reap_finished_jobs { if ($?) { # XXX- we currently don't care } - $child[0]->{'finished'} = 2 if (@child && !$child[0]->{'finished'}); - my $status = $child[0]->{'finished'}; - if ($status == 0) { next; } - elsif ($status == 1 && defined($child[0]->{'on_error'})) { - $child[0]->{'on_error'}->($_); - } elsif ($status == 2 && defined($child[0]->{'on_success'})) { - $child[0]->{'on_success'}->($_); + if (@child && !$child[0]->{'finished'}) { + $child[0]->{'on_success'}->($_) if defined($child[0]->{'on_success'}); + $jobs_executed++; + } elsif (@child) { + $child[0]->{'on_error'}->($_) if defined($child[0]->{'on_error'}); } - $jobs_executed++; } @running = grep { $_->{'finished'} == 0 } @running; } -- 2.11.4.GIT