1
0
mirror of synced 2026-04-25 20:11:20 +00:00

Move findBinary to Xen::Tools::Common

This commit is contained in:
Axel Beckert
2012-11-27 23:42:21 +01:00
parent 6b64dcc122
commit 4c3e4abff7
3 changed files with 36 additions and 33 deletions

View File

@@ -21,7 +21,8 @@ use vars qw(@EXPORT_OK @EXPORT);
use English;
@EXPORT = qw(readConfigurationFile xenRunning runCommand setupAdminUsers
findXenToolstack logprint_with_config logonly_with_config fail_with_config);
findXenToolstack findBinary
logprint_with_config logonly_with_config fail_with_config);
=head1 FUNCTIONS
@@ -137,6 +138,38 @@ sub xenRunning ($$)
return ($running);
}
=head2 findBinary
=begin doc
Find the location of the specified binary on the curent user's PATH.
Return undef if the named binary isn't found.
=end doc
=cut
sub findBinary
{
my ($bin) = (@_);
# strip any path which might be present.
$bin = $2 if ( $bin =~ /(.*)[\/\\](.*)/ );
foreach my $entry ( split( /:/, $ENV{ 'PATH' } ) )
{
# guess of location.
my $guess = $entry . "/" . $bin;
# return it if it exists and is executable
return $guess if ( -e $guess && -x $guess );
}
return undef;
}
=head2 findXenToolstack
=begin doc