Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Sep 2012 13:14:29 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Sam Varshavchik <mrsam@courier-mta.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: What happened to my /proc/curproc/file?
Message-ID:  <20120904101429.GV33100@deviant.kiev.zoral.com.ua>
In-Reply-To: <cone.1346723177.448775.23058.1000@monster.email-scan.com>
References:  <cone.1346723177.448775.23058.1000@monster.email-scan.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <stdio.h>
> #include <unistd.h>
> #include <sys/stat.h>
>=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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120904101429.GV33100>