in reply to Testing the current directory with Cwd and File::Spec

Here is another Cwd consideration. If the directory is a mounted filesystem, getcwd() (as the owner of the mounted filesystem) may return undefined if the owner has insufficient access to the underlying mount-point even if he has full access to the mounted filesystem.

For example:

#get group $groups = `/usr/bin/id -G $username`; chomp $groups; # drop privileges to owner of filesystem $) = "$groups"; #setegid $> = $uid; #seteuid $currentdir = Cwd::getcwd(); my $lasterr = $!; if (not defined $currentdir) { print "getcwd() failed : @_\n"; } else { print "getcwd() for $over is OK."; }

A command like tar will usually give an error like "tar: The getwd subroutine failed. Cannot open parent directory."

This is useful to know in cases where the underlying stub directory's permissions affect programs relying on getcwd() e.g. /bin/pwd, tar etc.

0xbeef

Replies are listed 'Best First'.
Re^2: Testing the current directory with Cwd and File::Spec
by Celada (Monk) on Dec 07, 2005 at 00:57 UTC
    That's an interesting little quirk! I guess that's why it's considered unwise to give less than 0555 permission to mountpoints. By the way I can't reproduce the behaviour under Linux but I can under Solaris.