Improve binary search algorithm

If a directory of the same name is in the current directory, this preventing the search running.  So, if the binary path is not fully qualified always search, and check to ensure it is a file that is found, rather than an executable directory.
Thanks to Ian Marsh for the patch
This commit is contained in:
Duncan Ferguson 2009-11-27 19:11:17 +00:00
parent 214f5a6a71
commit 77e31c4a62
3 changed files with 7 additions and 2 deletions

View file

@ -307,7 +307,7 @@ sub find_binary($) {
logmsg( 2, "Looking for $binary" );
my $path;
if ( !-x $binary ) {
if ( !-x $binary || substr($binary, 0, 1) ne '/' ) {
# search the users $PATH and then a few other places to find the binary
# just in case $PATH isnt set up right
@ -326,7 +326,7 @@ sub find_binary($) {
{
logmsg( 3, "Looking in $_" );
if ( -x $_ . '/' . $binary ) {
if ( -f $_ . '/' . $binary && -x $_ . '/' . $binary ) {
$path = $_ . '/' . $binary;
logmsg( 2, "Found at $path" );
last;