From: Daniel Kahn Gillmor Date: Fri, 12 Mar 2010 00:23:36 +0000 (-0500) Subject: handle race condition with rapid subprocess death; also ensure termination of subproc... X-Git-Tag: msva-perl/0.2~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c388476dfae3fa728e17962bb31df4c107ab55f6;p=monkeysphere-validation-agent.git handle race condition with rapid subprocess death; also ensure termination of subprocess if exec itself fails. --- diff --git a/msva-perl b/msva-perl index ad494f4..2a8b36d 100755 --- a/msva-perl +++ b/msva-perl @@ -380,8 +380,11 @@ use strict; my $pid = shift; my $server = shift; + msvalog('debug', "Subprocess %d terminated.\n", $pid); + if (exists $self->{child_pid} && - $self->{child_pid} == $pid) { + ($self->{child_pid} == 0 || + $self->{child_pid} == $pid)) { my $exitstatus = POSIX::WEXITSTATUS($?); msvalog('verbose', "Subprocess %d terminated; exiting %d.\n", $pid, $exitstatus); $server->set_exit_status($exitstatus); @@ -403,14 +406,16 @@ use strict; my $argcount = @ARGV; if ($argcount) { + $self->{child_pid} = 0; # indicate that we are planning to fork. my $fork = fork(); if (! defined $fork) { msvalog('error', "could not fork\n"); } else { if ($fork) { + msvalog('debug', "Child process has PID %d\n", $fork); $self->{child_pid} = $fork; } else { - msvalog('verbose', "Executing: \n"); + msvalog('verbose', "PID %d executing: \n", $$); for my $arg (@ARGV) { msvalog('verbose', " %s\n", $arg); } @@ -420,7 +425,7 @@ use strict; push @args, untaint($_); } $ENV{MONKEYSPHERE_VALIDATION_AGENT_SOCKET} = sprintf('http://localhost:%d', $self->port); - exec(@args); + exec(@args) or die; } } };