The following commit has been merged in the master branch:
commit 383247f0d2dfbd3d0d6388f87869ac1abaa8b7cd
Author: Guillem Jover <[email protected]>
Date:   Sat Dec 10 03:04:57 2011 +0100

    Do not use absolute paths for programs in perl and shell code
    
    The location of programs on the filesystem is not standardized, and as
    such using absolute paths is not a portable assumption to make. This
    causes test suite errors on at least Mac OS X.
    
    Use just the program name on perl system() calls, when needing the full
    path use Dpkg::Path::find_command() in perl code and “which” in shell
    code.
    
    Reported-by: Stuart Ambler <[email protected]>

diff --git a/debian/changelog b/debian/changelog
index 3b7e1a7..640e56f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -41,6 +41,7 @@ dpkg (1.16.2) UNRELEASED; urgency=low
     currently supported value is “extreme” for xz. Closes: #647915
   * Stop using brace expansion to install man pages by using dh_installman
     instead of dh_install, the former does not abort on empty glob expansion.
+  * Do not use absolute paths for programs in perl and shell code.
 
   [ Raphaël Hertzog ]
   * Update Dpkg::Shlibs to look into multiarch paths when cross-building
diff --git a/dselect/methods/Debian/Dselect/Ftp.pm 
b/dselect/methods/Debian/Dselect/Ftp.pm
index 73e3bdf..478134a 100644
--- a/dselect/methods/Debian/Dselect/Ftp.pm
+++ b/dselect/methods/Debian/Dselect/Ftp.pm
@@ -58,7 +58,7 @@ sub store_config {
 
 sub view_mirrors {
   if (-f '/usr/lib/dpkg/methods/ftp/README.mirrors.txt') {
-    system('/usr/bin/pager', '/usr/lib/dpkg/methods/ftp/README.mirrors.txt');
+    system('pager', '/usr/lib/dpkg/methods/ftp/README.mirrors.txt');
   } elsif (-f '/usr/lib/dpkg/methods/ftp/README.mirrors.txt.gz') {
     system('gzip -dc /usr/lib/dpkg/methods/ftp/README.mirrors.txt.gz | pager');
   } else {
diff --git a/dselect/methods/disk/setup b/dselect/methods/disk/setup
index ca1f0cc..1ed5d51 100755
--- a/dselect/methods/disk/setup
+++ b/dselect/methods/disk/setup
@@ -241,7 +241,7 @@ then
                        response="$defaultnfsserver"
                fi
                if [ -z "$response" ]; then continue; fi
-               if [ -x /usr/bin/rpcinfo ]
+               if [ -x "`which rpcinfo`" ]
                then
                        if rpcinfo -u "$response" mountd | grep -q 'ready'
                        then
@@ -249,7 +249,7 @@ then
                        else
                                echo "$response appears not to be an NFS 
server."
                        fi
-               elif [ -x /bin/ping ]
+               elif [ -x "`which ping`" ]
                then
                        if ping -q -c 1 "$response" | grep -q ', 1 packets 
received'
                        then
@@ -259,7 +259,7 @@ then
                        fi
                else
                        echo \
-"(I can't check that now because there is no /usr/bin/rpcinfo or /bin/ping.)"
+"(I can't check that now because there is no rpcinfo or ping.)"
                        nfsserver="$response"
                fi
        done
diff --git a/dselect/methods/ftp/install b/dselect/methods/ftp/install
index faa113a..f1a1c4c 100755
--- a/dselect/methods/ftp/install
+++ b/dselect/methods/ftp/install
@@ -131,7 +131,7 @@ procstatus();
 sub dcmpvers {
     my($a, $p, $b) = @_;
     my ($r);
-    $r = system("/usr/bin/dpkg", "--compare-versions", "$a", "$p", "$b");
+    $r = system("dpkg", "--compare-versions", "$a", "$p", "$b");
     $r = $r/256;
     if ($r == 0) {
        return 1;
diff --git a/dselect/methods/multicd/install b/dselect/methods/multicd/install
index f9262f9..4872f28 100755
--- a/dselect/methods/multicd/install
+++ b/dselect/methods/multicd/install
@@ -53,7 +53,7 @@ xit=1
 do_umount() {
        if [ "$method" = "multi_mount" ]
        then
-               echo /bin/true
+               echo true
                return
        fi
        if [ -n "$umount" ]; then
@@ -66,7 +66,7 @@ do_mount() {
 
        if [ "$method" = "multi_mount" ]
        then
-               echo /bin/true
+               echo true
                return
        fi
 
diff --git a/dselect/methods/multicd/setup b/dselect/methods/multicd/setup
index c7485b4..3444fc4 100755
--- a/dselect/methods/multicd/setup
+++ b/dselect/methods/multicd/setup
@@ -282,7 +282,7 @@ then
                        response="$defaultnfsserver"
                fi
                if [ -z "$response" ]; then continue; fi
-               if [ -x /usr/bin/rpcinfo ]
+               if [ -x "`which rpcinfo`" ]
                then
                        if rpcinfo -u "$response" mountd >/dev/null
                        then
@@ -290,7 +290,7 @@ then
                        else
                                echo "$response appears not to be an NFS 
server."
                        fi
-               elif [ -x /bin/ping ]
+               elif [ -x "`which ping`" ]
                then
                        if ping -q -c 1 "$response" | grep -q ', 1 packets 
received'
                        then
@@ -300,7 +300,7 @@ then
                        fi
                else
                        echo \
-"(I can't check that now because there is no /usr/bin/rpcinfo or /bin/ping.)"
+"(I can't check that now because there is no rpcinfo or ping.)"
                        nfsserver="$response"
                fi
        done
diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm
index 94e6b8f..502d402 100644
--- a/scripts/Dpkg/Source/Package.pm
+++ b/scripts/Dpkg/Source/Package.pm
@@ -44,7 +44,7 @@ use Dpkg::Checksums;
 use Dpkg::Version;
 use Dpkg::Compression;
 use Dpkg::Exit;
-use Dpkg::Path qw(check_files_are_the_same);
+use Dpkg::Path qw(check_files_are_the_same find_command);
 use Dpkg::IPC;
 use Dpkg::Vendor qw(run_vendor_hook);
 
@@ -342,9 +342,9 @@ sub check_signature {
     my ($self) = @_;
     my $dsc = $self->get_filename();
     my @exec;
-    if (-x '/usr/bin/gpgv') {
+    if (find_command('gpgv')) {
         push @exec, "gpgv";
-    } elsif (-x '/usr/bin/gpg') {
+    } elsif (find_command('gpg') {
         push @exec, "gpg", "--no-default-keyring", "-q", "--verify";
     }
     if (scalar(@exec)) {
diff --git a/scripts/Dpkg/Vendor/Ubuntu.pm b/scripts/Dpkg/Vendor/Ubuntu.pm
index f3ead0a..7e60fcf 100644
--- a/scripts/Dpkg/Vendor/Ubuntu.pm
+++ b/scripts/Dpkg/Vendor/Ubuntu.pm
@@ -26,6 +26,7 @@ our $VERSION = "0.01";
 
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
+use Dpkg::Path qw(find_command);
 use Dpkg::Control::Types;
 use Dpkg::BuildOptions;
 use Dpkg::Arch qw(debarch_eq get_host_arch);
@@ -119,7 +120,7 @@ sub run_hook {
        if (defined $hardening) {
            my $flag = 'DEB_BUILD_HARDENING';
            if ($hardening ne "0") {
-               if (! -x '/usr/bin/hardened-cc') {
+               if (!find_command('hardened-cc')) {
                    syserr(_g("'hardening' flag found but 'hardening-wrapper' 
not installed"));
                }
                if ($hardening ne "1") {
diff --git a/scripts/dpkg-gensymbols.pl b/scripts/dpkg-gensymbols.pl
index a6c73ad..06bbbba 100755
--- a/scripts/dpkg-gensymbols.pl
+++ b/scripts/dpkg-gensymbols.pl
@@ -27,7 +27,7 @@ use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
 use Dpkg::Control::Info;
 use Dpkg::Changelog::Parse;
-use Dpkg::Path qw(check_files_are_the_same);
+use Dpkg::Path qw(check_files_are_the_same find_command);
 
 textdomain("dpkg-dev");
 
@@ -306,7 +306,7 @@ unless ($quiet) {
        my $diff_label = sprintf("%s (%s_%s_%s)",
        ($ref_symfile->{file}) ? $ref_symfile->{file} : "new_symbol_file",
        $oppackage, $sourceversion, $host_arch);
-       system("diff", "-u", "-L", $diff_label, $a, $b) if -x "/usr/bin/diff";
+       system("diff", "-u", "-L", $diff_label, $a, $b) if find_command("diff");
     }
 }
 exit($exitcode);
diff --git a/utils/t/100_update_alternatives.t 
b/utils/t/100_update_alternatives.t
index 1926ec1..40a5990 100644
--- a/utils/t/100_update_alternatives.t
+++ b/utils/t/100_update_alternatives.t
@@ -14,6 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use Dpkg::IPC;
+use Dpkg::Path qw(find_command);
 use File::Spec;
 use Test::More;
 
@@ -28,6 +29,15 @@ my $bindir = File::Spec->rel2abs("$tmpdir/bin");
 my @ua = ("$ENV{builddir}/update-alternatives", "--log", "/dev/null",
           "--quiet", "--admindir", "$admindir", "--altdir", "$altdir");
 
+my %paths = (
+    true => find_command("true"),
+    false => find_command("false"),
+    yes => find_command("yes"),
+    cat => find_command("cat"),
+    date => find_command("date"),
+    sleep => find_command("sleep"),
+);
+
 if (! -x "$ENV{builddir}/update-alternatives") {
     plan skip_all => "update-alternatives not available";
     exit(0);
@@ -37,44 +47,44 @@ my $main_link = "$bindir/generic-test";
 my $main_name = "generic-test";
 my @choices = (
     {
-       path => "/bin/true",
+       path => $paths{true},
        priority => 20,
        slaves => [
            {
                "link" => "$bindir/slave2",
                name => "slave2",
-               path => "/bin/cat",
+               path => $paths{cat},
            },
            {
                "link" => "$bindir/slave3",
                name => "slave3",
-               path => "/bin/cat",
+               path => $paths{cat},
            },
            {
                "link" => "$bindir/slave1",
                name => "slave1",
-               path => "/usr/bin/yes",
+               path => $paths{yes},
            },
            {
                "link" => "$bindir/slave4",
                name => "slave4",
-               path => "/bin/cat",
+               path => $paths{cat},
            },
        ],
     },
     {
-        path => "/bin/false",
+        path => $paths{false},
         priority => 10,
         slaves => [
            {
                "link" => "$bindir/slave1",
                name => "slave1",
-               path => "/bin/date",
+               path => $paths{date},
            },
         ],
     },
     {
-        path => "/bin/sleep",
+        path => $paths{sleep},
         priority => 5,
         slaves => [],
     },
@@ -262,35 +272,35 @@ $bindir/slave3
 slave4
 $bindir/slave4
 
-/bin/false
+$paths{false}
 10
-/bin/date
+$paths{date}
 
 
 
-/bin/sleep
+$paths{sleep}
 5
 
 
 
 
-/bin/true
+$paths{true}
 20
-/usr/bin/yes
-/bin/cat
-/bin/cat
-/bin/cat
+$paths{yes}
+$paths{cat}
+$paths{cat}
+$paths{cat}
 
 ", "administrative file is as expected");
 }
 
 # manual change with --set-selections
-my $input = "doesntexist auto /bin/date\ngeneric-test manual /bin/false\n";
+my $input = "doesntexist auto $paths{date}\ngeneric-test manual 
$paths{false}\n";
 my $output = "";
 call_ua(["--set-selections"], from_string => \$input,
         to_string => \$output, test_id => "manual update with 
--set-selections");
 check_choice(1, "manual", "manual update with --set-selections");
-$input = "generic-test auto /bin/true\n";
+$input = "generic-test auto $paths{true}\n";
 call_ua(["--set-selections"], from_string => \$input,
         to_string => \$output, test_id => "auto update with --set-selections");
 check_choice(0, "auto", "auto update with --set-selections");
@@ -365,7 +375,7 @@ check_no_link($old_slave, "rename lost file");
 # update of alternative with many slaves not currently installed
 # and the link of the renamed slave exists while it should not
 set_choice(1);
-symlink("/bin/cat", "$bindir/generic-slave-bis");
+symlink("$paths{cat}", "$bindir/generic-slave-bis");
 $choices[0]{"slaves"}[0]{"link"} = "$bindir/slave2";
 install_choice(0, test_id => "update with non-installed slaves");
 check_no_link("$bindir/generic-slave-bis",
@@ -384,30 +394,30 @@ install_choice(0, error_to_file => "/dev/null", 
expect_failure => 1);
 cleanup();
 install_choice(0);
 # try to install a slave alternative as new master
-call_ua(["--install", "$bindir/testmaster", "slave1", "/bin/date", "10"],
+call_ua(["--install", "$bindir/testmaster", "slave1", "$paths{date}", "10"],
         expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # try to install a master alternative as slave
-call_ua(["--install", "$bindir/testmaster", "testmaster", "/bin/date", "10",
-        "--slave", "$bindir/testslave", "generic-test", "/bin/true" ],
+call_ua(["--install", "$bindir/testmaster", "testmaster", "$paths{date}", "10",
+        "--slave", "$bindir/testslave", "generic-test", "$paths{true}" ],
        expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # try to reuse master link in slave
-call_ua(["--install", "$bindir/testmaster", "testmaster", "/bin/date", "10",
-        "--slave", "$bindir/testmaster", "testslave", "/bin/true" ],
+call_ua(["--install", "$bindir/testmaster", "testmaster", "$paths{date}", "10",
+        "--slave", "$bindir/testmaster", "testslave", "$paths{true}" ],
        expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # try to reuse links in master alternative
-call_ua(["--install", "$bindir/slave1", "testmaster", "/bin/date", "10"],
+call_ua(["--install", "$bindir/slave1", "testmaster", "$paths{date}", "10"],
         expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # try to reuse links in slave alternative
-call_ua(["--install", "$bindir/testmaster", "testmaster", "/bin/date", "10",
-        "--slave", "$bindir/generic-test", "testslave", "/bin/true" ],
+call_ua(["--install", "$bindir/testmaster", "testmaster", "$paths{date}", "10",
+        "--slave", "$bindir/generic-test", "testslave", "$paths{true}" ],
        expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # try to reuse slave link in another slave alternative of another choice of
 # the same main alternative
-call_ua(["--install", $main_link, $main_name, "/bin/date", "10",
-        "--slave", "$bindir/slave1", "testslave", "/bin/true" ],
+call_ua(["--install", $main_link, $main_name, "$paths{date}", "10",
+        "--slave", "$bindir/slave1", "testslave", "$paths{true}" ],
        expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # lack of absolute filenames in links or file path, non-existing path,
-call_ua(["--install", "../testmaster", "testmaster", "/bin/date", "10"],
+call_ua(["--install", "../testmaster", "testmaster", "$paths{date}", "10"],
         expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 call_ua(["--install", "$bindir/testmaster", "testmaster", 
"./update-alternatives.pl", "10"],
         expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
@@ -415,18 +425,18 @@ call_ua(["--install", "$bindir/testmaster", "testmaster", 
"./update-alternatives
 call_ua(["--install", "$bindir/testmaster", "testmaster", 
"$bindir/doesntexist", "10"],
         expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # invalid alternative name in master
-call_ua(["--install", "$bindir/testmaster", "test/master", "/bin/date", "10"],
+call_ua(["--install", "$bindir/testmaster", "test/master", "$paths{date}", 
"10"],
         expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # invalid alternative name in slave
-call_ua(["--install", "$bindir/testmaster", "testmaster", "/bin/date", "10",
-        "--slave", "$bindir/testslave", "test slave", "/bin/true" ],
+call_ua(["--install", "$bindir/testmaster", "testmaster", "$paths{date}", "10",
+        "--slave", "$bindir/testslave", "test slave", "$paths{true}" ],
        expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 # install in non-existing dir should fail
-call_ua(["--install", "$bindir/doesntexist/testmaster", "testmaster", 
"/bin/date", "10",
-        "--slave", "$bindir/testslave", "testslave", "/bin/true" ],
+call_ua(["--install", "$bindir/doesntexist/testmaster", "testmaster", 
"$paths{date}", "10",
+        "--slave", "$bindir/testslave", "testslave", "$paths{true}" ],
        expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
-call_ua(["--install", "$bindir/testmaster", "testmaster", "/bin/date", "10",
-        "--slave", "$bindir/doesntexist/testslave", "testslave", "/bin/true" ],
+call_ua(["--install", "$bindir/testmaster", "testmaster", "$paths{date}", "10",
+        "--slave", "$bindir/doesntexist/testslave", "testslave", 
"$paths{true}" ],
        expect_failure => 1, to_file => "/dev/null", error_to_file => 
"/dev/null");
 
 # non-existing alternative path in slave is not a failure

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to