Subject: Re: CVS commit: src/usr.bin/find
To: None <tech-userlevel@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 02/10/2007 18:18:56
> More basically, could someone point me to a description of the
> problem that '-delete' is intended to solve?
I didn't add it, so I don't really know. But based on this thread, I'd
say it's the race inherent in "find $DIR ...condition... -print0 |
xargs -0 rm". The race is that find produces pathnames, but what the
pathname refers to can change between find producing it and rm
removing it. For example, /tmp/adir/bdir/cdir/master.passwd could be
a real file under /tmp when find encounters it, but cdir could be a
symlink leading to /etc when rm gets to it. AIUI, -delete is designed
to close this hole by guaranteeing that the object being removed is the
object find found. It certainly looks as though it works for that.
>> -delete ... exists to minimize a specific race condition opportunity
>> because pipes pass filenames, not filehandles.
> As Mouse said (approximately), it would be interesting to consider
> the problem in terms of what find(1) would have to pass to a filter
> that could do what -delete is meant for. We know how to pass handles
> between processes.
Yes, but not through pipes, I think, not since pipes stopped being
AF_LOCAL sockets. Maybe pipes need to grow the ability to pass
filehandles, or perhaps shells need to grow a way to specify the use of
AF_LOCAL socketpairs for pipes, or perhaps pipes need to notice such
calls and convert themselves into AF_LOCAL sockets, or some such.
For that matter, I'd like to create ways to pass things other than file
descriptors as access rights. Perhaps I should work on this a bit;
it's the sort of thing that I find interesting and fun....
> Might it be useful to make find(1) do that instead? Various
> handle-accepting filters could do different things with them,
> unlinking being only one possibility.
This strikes me as very much the Unix way: design a general mechanism
that allows solving the problem, rather than a special-case fix.
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B