From owner-freebsd-hackers@FreeBSD.ORG Tue Sep 4 10:14:46 2012 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 DA3BC106566B for ; Tue, 4 Sep 2012 10:14:46 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 3C4E48FC14 for ; Tue, 4 Sep 2012 10:14:45 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q84AEfmE050642; Tue, 4 Sep 2012 13:14:41 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q84AETjh043864; Tue, 4 Sep 2012 13:14:29 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q84AETxF043863; Tue, 4 Sep 2012 13:14:29 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 4 Sep 2012 13:14:29 +0300 From: Konstantin Belousov To: Sam Varshavchik Message-ID: <20120904101429.GV33100@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="FDAG2dCwjLTo0D1e" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-hackers@freebsd.org Subject: Re: What happened to my /proc/curproc/file? 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: Tue, 04 Sep 2012 10:14:46 -0000 --FDAG2dCwjLTo0D1e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 03, 2012 at 09:46:17PM -0400, Sam Varshavchik wrote: > Am I the only one who's seeing this weirdness with procfs on=20 > 9.0-RELEASE-p3. Unless I'm overlooking something stupid, a process that= =20 > rmdir(2)s a subdirectory of its current directory ends up with a broken = =20 > /proc/curproc/file symlink: >=20 > [mrsam@freebsd ~/stasher/stasher]$ cat t.c > #include > #include > #include >=20 > void dump(int n) > { > char buf[2048]; >=20 > printf("Line %d, rc=3D%s\n", n, > (readlink("/proc/curproc/file", buf, 2048) < 0 ? "err":"ok")); > } >=20 > int main(int argc, char **argv) > { > dump(__LINE__); > mkdir("conftestdir.tst", 0777); > rmdir("conftestdir.tst"); > dump(__LINE__); > } > [mrsam@freebsd ~/stasher/stasher]$ cc -o t t.c > [mrsam@freebsd ~/stasher/stasher]$ ./t > Line 15, rc=3Dok > Line 18, rc=3Derr >=20 > ??????? >=20 The procfs links, as well as any other user of vn_fullpath(9) function, can only translate a vnode to path if namecache contains useful data. As such, the facilities are not guaranteed to success all the time. In case of rmdir(2), UFS explicitely purges the cache for directory which contained direntry of the removed directory. I suspect that you have your test program binary located in the same directory which was the parent of the removed one. Similar purge is done by UFS for directories which are the sources or destinations of the move. --FDAG2dCwjLTo0D1e Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlBF1IQACgkQC3+MBN1Mb4hagACglV/jrLzN+NlNSuPmioMXtmhK L7YAnjyPvTYx9P14gdX6QVc93Ek+//S0 =/nd5 -----END PGP SIGNATURE----- --FDAG2dCwjLTo0D1e--