From: Tyler Riddle Date: Wed, 30 Jan 2013 18:50:58 +0000 (-0800) Subject: removed process groups from the connection class child cleanup logic X-Git-Tag: v0.003001_01~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=commitdiff_plain;h=5ccce2d5c1fb651f83c73c811069003e4a591a53 removed process groups from the connection class child cleanup logic --- diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index 6c10d45..77fc2d7 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -21,13 +21,14 @@ use Carp qw(croak); BEGIN { router()->exclude_forwarding } END { - log_debug { "Killing all child processes in the process group" }; - - #FIXME update along with setpgrp() to not use a process - #group anymore + our %child_pids; + + log_trace { "END handler is being invoked in " . __PACKAGE__ }; - #send SIGINT to the process group for our children - kill(1, -2); + foreach(keys(%child_pids)) { + log_debug { "Killing child process '$_'" }; + kill('TERM', $_); + } } has _id => ( is => 'ro', required => 1, default => sub { our $NEXT_CONNECTION_ID++ } ); @@ -89,17 +90,10 @@ has _json => ( after BUILD => sub { my ($self) = @_; my $pid = $self->child_pid; - - unless (defined $pid) { - log_trace { "After BUILD invoked for connection but there was no pid" }; - return; - } - - log_trace { "Setting process group of child process '$pid'" }; - - #FIXME moving things into a process group has side effects for - #users of the library - move to a list - setpgrp($self->child_pid, 1); + our %child_pids; + return unless defined $pid; + $child_pids{$pid} = 1; + return; }; sub BUILD { } @@ -142,6 +136,7 @@ sub _fail_outstanding { sub _install_future_handlers { my ($self, $f) = @_; + our %child_pids; Dlog_trace { "Installing handlers into future for connection $_" } $self->_id; weaken($self); $f->on_done(sub { @@ -162,6 +157,8 @@ sub _install_future_handlers { "Remote Perl interpreter exited with value '$exit_value'" }; } + + delete $child_pids{$pid}; }); return $f; }; diff --git a/t/perl_execute.t b/t/perl_execute.t index f7eae02..3792db4 100644 --- a/t/perl_execute.t +++ b/t/perl_execute.t @@ -7,24 +7,15 @@ use Object::Remote::Connector::Local; use Object::Remote::Connector::SSH; my $defaults = Object::Remote::Connector::Local->new; - my $normal = $defaults->final_perl_command; -my $ulimit = Object::Remote::Connector::Local->new(ulimit => "-v 536")->final_perl_command; -my $nice = Object::Remote::Connector::Local->new(nice => 834)->final_perl_command; -my $both = Object::Remote::Connector::Local->new(nice => 612, ulimit => "-v 913")->final_perl_command; -my $ssh = Object::Remote::Connector::SSH->new(nice => 494, ulimit => "-v 782", ssh_to => 'testhost')->final_perl_command; +my $ssh = Object::Remote::Connector::SSH->new(ssh_to => 'testhost')->final_perl_command; is($defaults->timeout, 10, 'Default connection timeout value is correct'); is($defaults->watchdog_timeout, undef, 'Watchdog is not enabled by default'); -is($defaults->nice, undef, 'Nice is not enabled by default'); -is($defaults->ulimit, undef, 'Ulimit is not enabled by default'); is($defaults->stderr, undef, 'Child process STDERR is clone of parent process STDERR by default'); -is_deeply($normal, ['bash', '-c', 'perl -'], 'Default Perl interpreter arguments correct'); -is_deeply($ulimit, ['bash', '-c', 'ulimit -v 536 || exit 1; perl -'], 'Arguments for ulimit are correct'); -is_deeply($nice, ['bash', '-c', 'nice -n 834 perl -'], 'Arguments for nice are correct'); -is_deeply($both, ['bash', '-c', 'ulimit -v 913 || exit 1; nice -n 612 perl -'], 'Arguments for nice and ulimit are correct'); -is_deeply($ssh, [qw(ssh -A testhost), "bash -c 'ulimit -v 782 || exit 1; nice -n 494 perl -'"], "Arguments using ssh are correct"); +is_deeply($normal, ['perl', '-'], 'Default Perl interpreter arguments correct'); +is_deeply($ssh, [qw(ssh -A testhost), "perl -"], "Arguments using ssh are correct"); done_testing;