From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RxpIv-0007Um-CI for garchives@archives.gentoo.org; Thu, 16 Feb 2012 00:34:33 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5D016E0AC0; Thu, 16 Feb 2012 00:26:39 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 0FC12E0A91 for ; Thu, 16 Feb 2012 00:26:38 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 30D411B401F for ; Thu, 16 Feb 2012 00:26:33 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id F02B9E540D for ; Thu, 16 Feb 2012 00:26:29 +0000 (UTC) From: "Kent Fredric" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Kent Fredric" Message-ID: <1314596357.3a05ea43a2e634e12124f44e49b7c8b059d264ec.kent@gentoo> Subject: [gentoo-commits] proj/perl-overlay:eclass-moretests commit in: scripts/ X-VCS-Repository: proj/perl-overlay X-VCS-Files: scripts/ssh_multiplex.pl X-VCS-Directories: scripts/ X-VCS-Committer: kent X-VCS-Committer-Name: Kent Fredric X-VCS-Revision: 3a05ea43a2e634e12124f44e49b7c8b059d264ec X-VCS-Branch: eclass-moretests Date: Thu, 16 Feb 2012 00:26:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 672191cf-2a6d-419b-b33b-207e860f8f67 X-Archives-Hash: dc86224c68f936cc330803657cc41c42 commit: 3a05ea43a2e634e12124f44e49b7c8b059d264ec Author: Kent Fredric gmail com> AuthorDate: Tue Aug 2 01:46:29 2011 +0000 Commit: Kent Fredric gmail com> CommitDate: Mon Aug 29 05:39:17 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/perl-overlay.= git;a=3Dcommit;h=3D3a05ea43 [scripts] new script to facilitate spawning the ssh backgrounded connecti= ons. ( I always forget how to do this and its annoying, this script most= ly just does the right thing. Its a bit more annoying on subsequent calls= to the script if the master connection is already up, but its really not= worth mention ) --- scripts/ssh_multiplex.pl | 109 ++++++++++++++++++++++++++++++++++++++++= ++++++ 1 files changed, 109 insertions(+), 0 deletions(-) diff --git a/scripts/ssh_multiplex.pl b/scripts/ssh_multiplex.pl new file mode 100644 index 0000000..a83cd62 --- /dev/null +++ b/scripts/ssh_multiplex.pl @@ -0,0 +1,109 @@ +#!/usr/bin/env perl=20 +eval 'echo "Called with something not perl"' && exit 1 # Non-Perl pro= tection. + if 0; + +use strict; +use warnings; +use 5.12.1; + +# FILENAME: ssh_multiplex.pl +# CREATED: 02/08/11 12:18:23 by Kent Fredric (kentnl) +# ABSTRACT: Spawn Background SSH Masters for Gentoo Git Sources + +use File::Which qw( which ); +use Data::Dump qw( dump ); + +my $ssh_cmd =3D which(qw( ssh )); +my %flag_map =3D ( + background =3D> ['-f'], + no_execute_command =3D> ['-N'], + no_stdin =3D> ['-n'], + control_master =3D> [ '-o', 'ControlMaster=3Dauto' ], +); + +my @pids; + +spawn_cmd( + { + pids =3D> \@pids, + params =3D> [qw( background no_execute_command no_stdin control_mas= ter )], + connect =3D> 'git@github.com', + cleanup =3D> sub { + say "\e[31mConnected to git\@github.com\e[0m"; + }, + } +); + +spawn_cmd( + { + pids =3D> \@pids, + params =3D> [qw( background no_execute_command no_stdin control_mas= ter )], + connect =3D> 'git@git.overlays.gentoo.org', + cleanup =3D> sub { + say "\e[32mConnected to git\@git.overlays.gentoo.org\e[0m"; + }, + } +); + +for (@pids) { + waitpid $_, 0; +} + +say "Done."; + +exit; + +sub map_option { + my ($option) =3D @_; + if ( not exists $flag_map{$option} ) { + require Carp; + Carp::croak("Map for $option undefined"); + } + return @{ $flag_map{$option} }; +} + +sub map_literal_array { + my ($literal) =3D @_; + return @{$literal}; +} + +sub map_param { + my ($param) =3D @_; + return map_option($param) if not ref $param; + return map_literal_array($param) if ref $param eq 'ARRAY'; + require Carp; + Carp::croak("Unhandled parameter $param"); +} + +sub spawn_child { + my (@cmd) =3D @_; + my $cleanup =3D pop @cmd; + my $pid; + if ( not defined( $pid =3D fork() ) ) { + my (@error) =3D ( $!, $?, $@ ); + require Carp; + Carp::croak("Forking Failed :( @error "); + } + if ($pid) { + return $pid; + } + system(@cmd) =3D=3D 0 or do { + my (@error) =3D ( $!, $?, $@ ); + require Carp; + Carp::croak("Running command Failed :( @error "); + }; + $cleanup->(); + exit; +} + +sub spawn_cmd { + my ($args) =3D @_; + my @outargs =3D map { map_param($_) } @{ $args->{'params'} }; + my (@cmd) =3D ( $ssh_cmd, @outargs, $args->{'connect'} ); + say "Spawning " . dump( \@cmd ); + $args->{cleanup} //=3D sub { + say "\e[31mConnected to " . $args->{'connect'} . "\e[0m"; + }; + push @{ $args->{pids} }, grep { defined } spawn_child( @cmd, $args->{c= leanup} ); +} +