]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
install: Always use a temporary file.
authorDag-Erling Smørgrav <des@FreeBSD.org>
Fri, 12 Apr 2024 17:30:48 +0000 (19:30 +0200)
committerDag-Erling Smørgrav <des@FreeBSD.org>
Fri, 12 Apr 2024 17:31:35 +0000 (19:31 +0200)
commite5035d08578e372d40b4e2d4c3574b7583549bd6
treef17f809cf1c5603f20b15a09ba901de1d2310eb8
parentbfd2ce2a5a61f16f2f8c98f4fbdcf47a758275ce
install: Always use a temporary file.

Previously, we would only use a temporary file if explicitly asked to
with the `-S` option, and even then, only if the target file already
existed.  This meant that an outside observer looking for the target
file might see a partial file, and might see the file disappear and
then reappear.

With this patch, we always use a temporary file, ensuring atomicity.
The downside is slightly increased disk usage.  The upside is never
having to worry about, for instance, cron jobs randomly failing if
they happen to run simultaneously with `make installworld`.

The `-S` option is retained, partly for compatibility, and partly
to control the use of `fsync(2)`, which has a non-negligible cost
(approximately 10% increase in wall time for `make installworld`).

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: 0mp, brooks, imp, markj
Differential Revision: https://reviews.freebsd.org/D44742
usr.bin/xinstall/install.1
usr.bin/xinstall/xinstall.c