ユーザ権限でのインストール

まあレンタル鯖の管理人なので、rootで作業することも多く、お客さんが実際にできること、を調べておかないと安心して薦められないので、自分の会社の鯖でユーザ権限で色々インストールを試しているんですが、rubypythonなんかは苦労することもなくmakeできますが、gccになるとgcjのmakeでメモリ使いすぎて、メモリリミットでとめられちゃう。perlはどうかというと、結構あちこちで苦労してる方がいらっしゃるようなので、自分も試しに入れてみました。

% cd perl-5.10.0
% sh Configure -Dprefix=/home/samaiyou/local -Dusethreads -des

 中略

opendir(./../../../../..): 許可がありません at ../../lib/File/Spec/Unix.pm line 478

最初は普通に失敗。 google:opendir(./../../../../..) perl ../../lib/File/Spec/Unix.pm 調べたら、やっぱり Cwd.pmにパッチをあてておりました。なぜこんなことがおきるかというと、多くのレンタルサーバーでは各々のユーザが /homeを参照できないように設定されてるためで、上の階層が読めないと、変なPATHを渡してしまうみたいなので、lib/Cwd.pmを直接いじって回避しているみたいです。

--- lib/Cwd.pm	Tue Dec 18 10:47:07 2007
+++ lib/Cwd.pm.cwd	Thu Jan 24 12:33:29 2008
@@ -501,6 +501,11 @@
 sub _perl_abs_path
 {
     my $start = @_ ? shift : '.';
+
+    # this just returns a path down from /, without attempting to
+    # resolve .. or symlinks. It *may* be sufficient to build perl.
+    return $start =~ m!^/! ? $start : cwd() . '/' . $start;
+
     my($dotdots, $cwd, @pst, @cst, $dir, @tst);
 
     unless (@cst = stat( $start ))

comp.lang.perl.misc より。

これのハックをしたら普通にさっきのConfigのあとのmakeがちゃんと通ります。testの時にエラーが出るのがいやな人は、パッチ当てたところを元に戻しておきましょう。

その後ソース見てたら

lib/Cwd.pm

=head2 getcwd and friends

Each of these functions are called without arguments and return the
absolute path of the current working directory.

=over 4

=item getcwd

    my $cwd = getcwd();

Returns the current working directory.

Exposes the POSIX function getcwd(3) or re-implements it if it's not
available.

=item cwd

    my $cwd = cwd();

The cwd() is the most natural form for the current architecture. For
most systems it is identical to `pwd` (but without the trailing line
terminator).

=item fastcwd

    my $cwd = fastcwd();

A more dangerous version of getcwd(), but potentially faster.

It might conceivably chdir() you out of a directory that it can't
chdir() you back into.  If fastcwd encounters a problem it will return
undef but will probably leave you in a different directory.  For a
measure of extra security, if everything appears to have worked, the
fastcwd() function will check that it leaves you in the same directory
that it started in. If it has changed it will C<die> with the message
"Unstable directory path, current directory changed
unexpectedly". That should never happen.

=item fastgetcwd

  my $cwd = fastgetcwd();

The fastgetcwd() function is provided as a synonym for cwd().
=item getdcwd

    my $cwd = getdcwd();
    my $cwd = getdcwd('C:');

The getdcwd() function is also provided on Win32 to get the current working
directory on the specified drive, since Windows maintains a separate current
working directory for each drive.  If no drive is specified then the current
drive is assumed.

This function simply calls the Microsoft C library _getdcwd() function.

=back


=head2 abs_path and friends

These functions are exported only on request.  They each take a single
argument and return the absolute pathname for it.  If no argument is
given they'll use the current working directory.

=over 4

=item abs_path

  my $abs_path = abs_path($file);

Uses the same algorithm as getcwd().  Symbolic links and relative-path
components ("." and "..") are resolved to return the canonical
pathname, just like realpath(3).

=item realpath

  my $abs_path = realpath($file);

A synonym for abs_path().

=item fast_abs_path

  my $abs_path = fast_abs_path($file);

A more dangerous, but potentially faster version of abs_path.

=back

ちゃんとこういう実装になってるので、同じようなDartyHackでもこっちを使うほうがそれっぽいかもしれんね。

と思ったらすでに試してる人がいた。