Author: arkurth
Date: Thu Sep 19 14:20:23 2013
New Revision: 1524750
URL: http://svn.apache.org/r1524750
Log:
VCL-725
Reworked utils.pm::run_command to call the command via backticks instead of
opening a pipe. This seems to always return the correct exit status.
VCL-726
Added call to vcld:: make_new_child which sets the process group of vcld state
processes to that of the forked state process. Without doing this, the process
group of the forked process is that of the parent vcld daemon process.
Added kill call to REAPER which kills all processes in the process group. Since
the process group was set for the forked vcld state process, all processes it
forks will be in its process group. This causes forked processes to be killed
when a vcld state process is killed.
Modified:
vcl/trunk/managementnode/bin/vcld
vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: vcl/trunk/managementnode/bin/vcld
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/bin/vcld?rev=1524750&r1=1524749&r2=1524750&view=diff
==============================================================================
--- vcl/trunk/managementnode/bin/vcld (original)
+++ vcl/trunk/managementnode/bin/vcld Thu Sep 19 14:20:23 2013
@@ -560,6 +560,10 @@ sub make_new_child {
# Child must *NOT* return from this subroutine after
this point. It must exit.
# If child returns it will become a parent process and
spawn off its own children
+ # Set the process group of this child process to its
own PID instead of it's parent PID
+ # This allows any processes forked by this child to be
killed when this process is killed
+ setpgrp $$, 0;
+
# Configure the SIGINT signal to kill this process
normally
$SIG{INT} = 'DEFAULT';
@@ -736,6 +740,9 @@ sub REAPER {
# Child which died was a VCL state process since its
pid is in the hash
$child_count--;
delete $child_pids{$dead_pid};
+
+ # Kill all child processes which were forked by this
process
+ kill 'SIGTERM', -$dead_pid;
}
}
Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1524750&r1=1524749&r2=1524750&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Thu Sep 19 14:20:23 2013
@@ -8862,39 +8862,21 @@ sub reservation_being_processed {
sub run_command {
my ($command, $no_output) = @_;
- my $pid;
- my @output = ();
- my $exit_status;
-
- # Pipe the command output to a file handle
- # The open function returns the pid of the process
- if ($pid = open(COMMAND, "$command 2>&1 |")) {
- # Capture the output of the command
- @output = <COMMAND>;
-
- # Save the exit status
- $exit_status = $? >> 8;
-
- if ($? == -1) {
- notify($ERRORS{'OK'}, 0, "\$? is set to $?, setting
exit status to 0, Perl bug likely encountered");
- $exit_status = 0;
- }
-
- # Close the command handle
- close(COMMAND);
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "failed to execute command:
$command, error: $!");
- return;
+ my $output_string = `$command 2>&1`;
+ my $exit_status = $?;
+ if ($exit_status >= 0) {
+ $exit_status = $exit_status >> 8;
}
- if (!$no_output) {
- notify($ERRORS{'DEBUG'}, 0, "executed command: $command, pid:
$pid, exit status: $exit_status, output:\n@output");
- }
+ # Remove any trailing newlines from the output
+ chomp $output_string;
- # Remove newlines from output lines
- map { chomp $_ } @output;
+ # Split the output string into an array of lines
+ my @output = split(/[\r\n]+/, $output_string);
+ if (!$no_output) {
+ notify($ERRORS{'DEBUG'}, 0, "executed command: $command, exit
status: $exit_status, output:\n@output");
+ }
return ($exit_status, \@output);
}