PERFORCE change 176831 for review

Tim Kientzle kientzle at freebsd.org
Wed Apr 14 15:01:00 UTC 2010


Garrett Cooper wrote:
> 
> To prevent race conditions [with regular files only], I should use
> open(2). For all other files I would use the standard extract method
> (so I don't get too fancy?). It seems like the file creation times
> should be sufficiently fast with other file types that this kind of
> behavior of open(2), blah wouldn't be required.

No.  This is only for a file that you're going to extract to
disk and then turn around and read back again immediately.

Rather than asking extract() to handle it and then opening
it again yourself, you should open the file yourself, ask
libarchive to write to the fd, then you can rewind and
use the fd without reopening the file.  Mostly, this is
a small performance optimization since you avoid the close
and re-open syscalls.  Depending on the situation,
it can also be a security improvement (it eliminates the
window between libarchive closing the file and you re-opening
it in which someone could conceivably replace the file
with something else).

The standard extract method is recommended if you're
just pushing something out to disk, whether it's a regular
file or a block device or hardlink.  Libarchive knows a lot
more about creating objects on disk than you want to
teach pkg_install.  As I said, this is just for
the case where you want to pull something out of an
archive into a file that you're going to immediately
read back again.

Tim


More information about the p4-projects mailing list