Date: Sun, 20 Apr 2008 13:07:49 +1000 From: Peter Jeremy <peterjeremy@optushome.com.au> To: Randall Hyde <randyhyde@earthlink.net> Cc: freebsd-hackers@freebsd.org Subject: Re: chdir/rmdir Message-ID: <20080420030749.GL73016@server.vk2pj.dyndns.org> In-Reply-To: <29853546.1208628147652.JavaMail.root@elwamui-rustique.atl.sa.earthlink.net> References: <29853546.1208628147652.JavaMail.root@elwamui-rustique.atl.sa.earthlink.net>
next in thread | previous in thread | raw e-mail | index | archive | help
--o41d8xLWOaLD8vYh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 =2E. 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. --=20 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. --o41d8xLWOaLD8vYh Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.8 (FreeBSD) iEYEARECAAYFAkgKs4UACgkQ/opHv/APuIc0uwCeMZGFjh5OQ+MVJshWcQ2ypuXG sgYAn1WeN141KiIAGK2dcTO8Yswnbrks =utDe -----END PGP SIGNATURE----- --o41d8xLWOaLD8vYh--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080420030749.GL73016>