From: Matt S Trout Date: Tue, 15 Nov 2011 08:37:56 +0000 (+0000) Subject: make --local implementation saner X-Git-Tag: v0.001002~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8facab5f2e83e16470b817e2f06891f508bf50ec;p=scpubgit%2FTak.git make --local implementation saner --- diff --git a/lib/Tak/Client/Router.pm b/lib/Tak/Client/Router.pm index f4c4fff..3672ab6 100644 --- a/lib/Tak/Client/Router.pm +++ b/lib/Tak/Client/Router.pm @@ -8,6 +8,4 @@ sub ensure { shift->do(meta => ensure => @_); } -sub host { 'localhost' } - 1; diff --git a/lib/Tak/ConnectorService.pm b/lib/Tak/ConnectorService.pm index b9f59d1..15e39bf 100644 --- a/lib/Tak/ConnectorService.pm +++ b/lib/Tak/ConnectorService.pm @@ -17,9 +17,10 @@ has ssh => (is => 'ro', default => sub { {} }); sub handle_create { my ($self, $on, %args) = @_; + die [ mistake => "No target supplied to create" ] unless $on; my $log_level = $args{log_level}||'info'; my ($kid_in, $kid_out, $kid_pid) = $self->_open($on, $log_level); - $kid_in->print($Tak::STDIONode::DATA, "__END__\n"); + $kid_in->print($Tak::STDIONode::DATA, "__END__\n") unless $on eq '-'; # Need to get a handshake to indicate STDIOSetup has finished # messing around with file descriptors, otherwise we can severely # confuse things by sending before the dup. @@ -34,7 +35,7 @@ sub handle_create { # actually, we should register with a monotonic id and # stash the pid elsewhere. but meh for now. my $pid = $client->do(meta => 'pid'); - my $name = ($on||'|').':'.$pid; + my $name = $on.':'.$pid; my $conn_router = Tak::Router->new; $conn_router->register(local => $connection->receiver->service); $conn_router->register(remote => $connection); @@ -44,8 +45,8 @@ sub handle_create { sub _open { my ($self, $on, @args) = @_; - unless ($on) { - my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, $^X, '-', '-', @args) + if ($on eq '-') { + my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, 'tak-stdio-node', '-', @args) or die "Couldn't open2 child: $!"; return ($kid_in, $kid_out, $kid_pid); } diff --git a/lib/Tak/Script.pm b/lib/Tak/Script.pm index b7a8f5f..0a4ce6e 100644 --- a/lib/Tak/Script.pm +++ b/lib/Tak/Script.pm @@ -118,13 +118,12 @@ sub _run_local { sub _run_each { my ($self, $cmd, $code, @argv) = @_; my @targets = $self->_host_list_for($cmd); - unless (@targets or $self->options->{local}) { + unless (@targets) { $self->stderr->print("No targets for ${cmd}\n"); return; } my $opt = $self->_maybe_parse_options($code, \@argv); $self->local_client->ensure(connector => 'Tak::ConnectorService'); - $self->$code($self->local_client, $opt, @argv) if $self->options->{local}; foreach my $target (@targets) { my $remote = $self->_connection_to($target); $self->$code($remote, $opt, @argv); @@ -134,20 +133,21 @@ sub _run_each { sub _run_every { my ($self, $cmd, $code, @argv) = @_; my @targets = $self->_host_list_for($cmd); - unless (@targets or $self->options->{local}) { + unless (@targets) { $self->stderr->print("No targets for ${cmd}\n"); return; } my $opt = $self->_maybe_parse_options($code, \@argv); $self->local_client->ensure(connector => 'Tak::ConnectorService'); my @remotes = map $self->_connection_to($_), @targets; - unshift @remotes, $self->local_client if $self->options->{local}; $self->$code(\@remotes, $opt, @argv); } sub _host_list_for { my ($self, $command) = @_; my @host_spec = map split(' ', $_), @{$self->options->{host}}; + unshift(@host_spec, '-') if $self->options->{local}; + return @host_spec; } sub _connection_to {