chdir/rmdir

Peter Jeremy peterjeremy at optushome.com.au
Sun Apr 20 03:07:55 UTC 2008


On Sat, Apr 19, 2008 at 11:02:27AM -0700, Randall Hyde wrote:
>Hi,
>I recently made a couple of calls like the following
>
>// currently in /x/y/z
>
>chdir( "/x/y" );
>rmdir( "/x/y/z" );

Presumably you checked the return codes and both these succeeded.

>When I did at "gwd" call, it returned "/x/y/z" along with ENOTDIR.
>Is this a known issue?

What do you mean by "gwd"?  There's getcwd(3) which uses __getcwd(2) -
but the syscall may fail, in which case getcwd(3) falls back to stat(2)ing
.. until it reaches root and then using directory(3) to translate the
inode numbers to a pathname.  And, even if __getcwd(3) succeeds, the
result may need massaging before being returned to the caller.

Note that system calls very rarely both fail and return a value -
normally, any output buffer will be returned untouched if there's an
error.

>P.S. I noticed that the man pages said something about using open on
>"." and fchdir to more robustly switch back to some previous
>directory;

This is for security and reliability reasons:  The process can still
get back to the original directory even if components of its pathname
have been renamed.

-- 
Peter Jeremy
Please excuse any delays as the result of my ISP's inability to implement
an MTA that is either RFC2821-compliant or matches their claimed behaviour.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20080420/73c7a077/attachment.pgp


More information about the freebsd-hackers mailing list