From owner-freebsd-hackers@FreeBSD.ORG Sun Apr 20 03:07:55 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0B9E2106566C for ; Sun, 20 Apr 2008 03:07:55 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from mail35.syd.optusnet.com.au (mail35.syd.optusnet.com.au [211.29.133.51]) by mx1.freebsd.org (Postfix) with ESMTP id 8FFD68FC27 for ; Sun, 20 Apr 2008 03:07:54 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from server.vk2pj.dyndns.org (c220-239-20-82.belrs4.nsw.optusnet.com.au [220.239.20.82]) by mail35.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id m3K37o8C005013 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 20 Apr 2008 13:07:50 +1000 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by server.vk2pj.dyndns.org (8.14.2/8.14.1) with ESMTP id m3K37oVx013757; Sun, 20 Apr 2008 13:07:50 +1000 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.14.2/8.14.2/Submit) id m3K37nw8013756; Sun, 20 Apr 2008 13:07:49 +1000 (EST) (envelope-from peter) Date: Sun, 20 Apr 2008 13:07:49 +1000 From: Peter Jeremy To: Randall Hyde Message-ID: <20080420030749.GL73016@server.vk2pj.dyndns.org> References: <29853546.1208628147652.JavaMail.root@elwamui-rustique.atl.sa.earthlink.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="o41d8xLWOaLD8vYh" Content-Disposition: inline In-Reply-To: <29853546.1208628147652.JavaMail.root@elwamui-rustique.atl.sa.earthlink.net> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.17 (2007-11-01) Cc: freebsd-hackers@freebsd.org Subject: Re: chdir/rmdir X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Apr 2008 03:07:55 -0000 --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--