Date: Wed, 14 Apr 2010 08:00:53 -0700 From: Tim Kientzle <kientzle@freebsd.org> To: Garrett Cooper <gcooper@freebsd.org> Cc: David Forsythe <dforsyth@freebsd.org>, Perforce Change Reviews <perforce@freebsd.org>, Florent Thoumie <flz@esat.net> Subject: Re: PERFORCE change 176831 for review Message-ID: <4BC5D8A5.7000004@freebsd.org> In-Reply-To: <r2x364299f41004140053y7b43d454qb7804e111d1920a6@mail.gmail.com> References: <201004121230.o3CCUsIX029146@repoman.freebsd.org> <4BC3EB5B.5070801@freebsd.org> <l2y364299f41004122249q2f5734a7j89be807581e42dac@mail.gmail.com> <4BC53714.80805@freebsd.org> <r2x364299f41004140053y7b43d454qb7804e111d1920a6@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4BC5D8A5.7000004>