aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/xinstall
Commit message (Collapse)AuthorAgeFilesLines
* install: Always use a temporary file.Dag-Erling Smørgrav2024-04-273-304/+142
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 (cherry picked from commit e5035d08578e372d40b4e2d4c3574b7583549bd6) install: Simplify path construction. There's no need to copy the path twice to split it into base and dir. We simply call `basename()` first, then handle the two trivial cases in which it isn't safe to call `dirname()`. While here, add an early check that the destination is not an empty string. This would always fail eventually, so it may as well fail right away. Also add a test case for this shortcut. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D44743 (cherry picked from commit 17dc7017d7375b3463d65adffe1eb980b0f86795) install: Remove the mmap(2) option. We already removed it from cp(1) over a year ago but never followed up here. Do so now, for the same reasons: significant complexity for little to no benefit. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D44809 (cherry picked from commit a0439a1b820fa0e742c00d095f5f5c06f5f19432) install: Assorted nitpickery. * Use `errc()` instead of manually setting `errno` before calling `err()`. * Change one warning into a fatal error. * Drop some unnecessary casts. * `strlcat()` bounds checks were off-by-one. This does not matter in practice because the subsequent code renders an overrun harmless. * We were passing `SSIZE_MAX` to `copy_file_range()` instead of the requested size. This only matters if we're asked to install a file which is still being written to while we are copying it. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D44810 (cherry picked from commit 000a533e6d1db9878296b32d1cc212e11a2cc718)
* install: Prefer strsnvis() to strsvis().Dag-Erling Smørgrav2024-04-041-8/+11
| | | | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D44514 (cherry picked from commit 2cab4be46b0eeb64b8ade010bc16245151af5ccd)
* install: handle -m +X more accuratelyKyle Evans2023-11-262-2/+26
| | | | | | | | | | | | | | | As described by chmod(1), +X in the mode may be used to optionally set the +x bit if the file is a directory if any of the execute/search bits are set in the original mode. The latter is not applicable because we assume -m is a fresh mask, but a functional +X could be useful in the former case if we're passing along a common INSTALL_MODE that's designed to install either 0644 or 0755 depending simply on whether it's a directory or not. Reviewed by: des Sponsored by: Klara, Inc. (cherry picked from commit 767c97c501ae72eb3d74bc23ddf5a1d570d8f841)
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-231-1/+0
| | | | | | | Remove /^\.\\"\s*\$FreeBSD\$$\n/ Similar commit in main: (cherry picked from commit b2c76c41be32)
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-235-5/+0
| | | | | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/ Similar commit in main: (cherry picked from commit d0b2dbfa0ecf)
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-231-2/+0
| | | | | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/ Similar commit in main: (cherry picked from commit 1d386b48a555)
* xinstall: fix dounpriv logic, add testsDag-Erling Smørgrav2022-11-024-21/+181
| | | | | | | | | | | | | | | | | | | | | | | | | Sponsored by: Klara, Inc. MFC after: 1 week (cherry picked from commit 36d67475f5497664d33c41c2f6745dcb30b0ec42) xinstall: make md5 and ripemd160 conditional Sponsored by: Klara, Inc. (cherry picked from commit c7a8e8d372b212c97dde6ce2731db27aa0b2201c) xinstall: use dynamic bufsize as in cat(1) / cp(1). Sponsored by: Klara, Inc. (cherry picked from commit 54d8d0fe12a4996427923048ab4261819774fbd4) xinstall: alphabetize: upper case precedes lower. Sponsored by: Klara, Inc. (cherry picked from commit f44e2577120c60cd92f685037bbb63127e0091e4)
* pkgbase: Put more binaries/lib in runtimeEmmanuel Vadot2022-01-051-0/+2
| | | | | | | | | | | Move some needed binaries/libs from FreeBSD-utilities to FreeBSD_runtime. This is everything needed to boot to multiuser with FreeBSD-rc installed. MFC after: 2 weeks Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D33435 (cherry picked from commit 93c43690960274dd3bb67b1ee0f1dd3ca4d13def)
* install(1): Avoid unncessary fstatfs() calls and use mmap() based on sizeAlex Richardson2020-10-141-23/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | According to git blame the trymmap() function was added in 1996 to skip mmap() calls for NFS file systems. However, nowadays mmap() should be perfectly safe even on NFS. Importantly, onl ufs and cd9660 file systems were whitelisted so we don't use mmap() on ZFS. It also prevents the use of mmap() when bootstrapping from macOS/Linux since on those systems the trymmap() function was always returning zero due to the missing MFSNAMELEN define. This change keeps the trymmap() function but changes it to check whether using mmap() can reduce the number of system calls that are required. Using mmap() only reduces the number of system calls if we need multiple read() syscalls, i.e. if the file size is > MAXBSIZE. However, mmap() is more expensive than read() so this sets the threshold at 4 fewer syscalls. Additionally, for larger file size mmap() can significantly increase the number of page faults, so avoid it in that case. It's unclear whether using mmap() is ever faster than a read with an appropriate buffer size, but this change at least removes two unnecessary system calls for every file that is installed. Reviewed By: markj Differential Revision: https://reviews.freebsd.org/D26041 Notes: svn path=/head/; revision=366697
* Allow install(1)'s create_tempfile() to work on Linux hostsAlex Richardson2020-07-152-5/+5
| | | | | | | | | | | GLibc expects six 'X' characters in the mkstemp template argument and will return EINVAL otherwise. Reviewed By: emaste, imp, mjg Differential Revision: https://reviews.freebsd.org/D25662 Notes: svn path=/head/; revision=363230
* install(1): another correction after r363064Eugene Grosbein2020-07-121-9/+16
| | | | | | | | | | | | Make sure we call fsync(2) on strip result in case of "safecopy" and "strip -o tempcopy -- src" before renaming tempcopy to destination. MFC after: 3 weeks X-MFC-With: r363064 Notes: svn path=/head/; revision=363136
* Fix the tests for install(1): add support for STRIPBIN's -o option.Eugene Grosbein2020-07-101-2/+6
| | | | | | | | Reported by: lwhsu MFC after: 1 week Notes: svn path=/head/; revision=363088
* install(1): addition to r363067Eugene Grosbein2020-07-101-1/+1
| | | | | | | | | | | | Also, make it not break if STRIPBIN points to strip version without -o support and destination does not exist before installing. Reported by: lwhsu MFC after: 1 month X-MFC-With: 363064 Notes: svn path=/head/; revision=363081
* install(1): correction after r363064Eugene Grosbein2020-07-101-1/+1
| | | | | | | | | | | Make it not break if STRIPBIN points to strip version without -o support. In that case, perform extra copy just like before r363064. MFC after: 1 month X-MFC-With: 363064 Notes: svn path=/head/; revision=363067
* Optimize install(1) a bit.Eugene Grosbein2020-07-101-23/+50
| | | | | | | | | | | | | | | | | | | | | | Currently, "install -s -S" behaviour is inefficient for upgrade. First it finds that destination file already exists and copies source file to temporary file. Then it calls strip(1) with name of temporary file as single agrument and our strip(1) creates another temporary file in the /tmp (or TMPDIR) making another copy that is finally copied to DESTDIR third time. Meantime, strip(1) has an option "-o dst" to specify destination so install(1) is allowed to skip initial copying from obj to DESTDIR. This change makes it do so. Take a look at https://reviews.freebsd.org/D25551 for details and efficiency numbers (in short: upto 32% gained for installword). MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D25551 Notes: svn path=/head/; revision=363064
* Allow boostrapping xinstall on LinuxAlex Richardson2019-11-202-1/+11
| | | | | | | | | | Linux does not have st_flags so we have to avoid using it there. Reviewed By: emaste, imp Differential Revision: https://reviews.freebsd.org/D22446 Notes: svn path=/head/; revision=354901
* install.1: Add missing arguments to option descriptionsMateusz Piotrowski2019-08-121-13/+9
| | | | | | | | | | | | | While here: - Remove deprecated Tn macros. - Do not use macros with the -width option. Reviewed by: bcr Approved by: doc (bcr) Differential Revision: https://reviews.freebsd.org/D21173 Notes: svn path=/head/; revision=350895
* install(1): Fix relative path calculation with partial common dest/srcKyle Evans2019-01-312-2/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | For example, from the referenced PR [1]: $ mkdir /tmp/lib/ /tmp/libexec $ touch /tmp/lib/foo.so $ install -lrs /tmp/lib/foo.so /tmp/libexec/ The common path identification bits terminate src at /tmp/lib/ and the destination at /tmp/libe. The subsequent backtracking is then incorrect, as it traverses the destination and backtraces exactly one level while eating the 'libexec' because it was previously (falsely) identified as common with 'lib'. The obvious fix would be to make sure we've actually terminated just after directory separators and rewind a character if we haven't. In the above example, we would end up rewinding to /tmp/ and subsequently doing the right thing. Test case added. PR: 235330 [1] MFC after: 1 week Notes: svn path=/head/; revision=343601
* When doing a -S "safe copy", the install command should do anKirk McKusick2018-08-271-0/+6
| | | | | | | | | | | | fsync(2) system call after copying the installed file to ensure that it is on stable storage. PR: 230851 Reviewed by: kib Approved by: re (marius) Notes: svn path=/head/; revision=338340
* Allow xinstall and makefs to be crossbuilt on Linux and MacAlex Richardson2018-01-162-1/+23
| | | | | | | | | | | | | | I need these tools in order to install the crossbuilt FreeBSD and create a disk image. Linux does not have a st_flags in struct stat so unfortunately I need a bunch of ugly ifdefs. The resulting binaries allow me to sucessfully install a MIPS64 world and create a disk-image that boots. Reviewed By: brooks, bdrewery, emaste Approved By: jhb (mentor) Differential Revision: https://reviews.freebsd.org/D13307 Notes: svn path=/head/; revision=328064
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-1/+3
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* DIRDEPS_BUILD: Update dependencies.Bryan Drewery2017-10-311-1/+0
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325188
* xinstall: plug an infinite loop in directory creationMateusz Guzik2017-10-121-2/+4
| | | | | | | | | | | | If stat continues to fail with ENOENT and mkdir with EEXIST the code wont finish. In particular this can show up when the target path follows through a symlink to a non-existent directory. Reported by: ae MFC after: 1 week Notes: svn path=/head/; revision=324547
* Add HAS_TESTS to all Makefiles that are currently using theEnji Cooper2017-08-021-0/+1
| | | | | | | | | `SUBDIR.${MK_TESTS}+= tests` idiom. This is a follow up to r321912. Notes: svn path=/projects/make-check-sandbox/; revision=321914
* Convert traditional ${MK_TESTS} conditional idiom for including testEnji Cooper2017-08-021-3/+1
| | | | | | | | | | | | | | directories to SUBDIR.${MK_TESTS} idiom This is being done to pave the way for future work (and homogenity) in ^/projects/make-check-sandbox . No functional change intended. MFC after: 1 weeks Notes: svn path=/head/; revision=321912
* Adopt SRCTOP in usr.binWarner Losh2017-03-121-3/+3
| | | | | | | | | | | | Prefer ${SRCTOP}/foo over ${.CURDIR}/../../foo and ${SRCTOP}/usr.bin/foo over ${.CURDIR}/../foo for paths in Makefiles. Differential Revision: https://reviews.freebsd.org/D9932 Sponsored by: Netflix Silence on: arch@ (twice) Notes: svn path=/head/; revision=315170
* Restore some of the error message text accidentally removed in r315098Enji Cooper2017-03-121-2/+2
| | | | | | | | | | | | "unexpected symlink contents" is more pedantically correct than "unexpected symlink". MFC after: 1 week X-MFC with: r315098 Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315108
* Add 3 more testcases demonstrating how install -l sr worksEnji Cooper2017-03-121-0/+66
| | | | | | | | | | | | | | | The additional testcases use absolute paths for sources and targets, as the other testcase which tested `-l sr` used flat relative paths in the same directory. Please note that these testcases do not test `-l a` -- that's already addressed in the battery of tests. MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315106
* Clarify src vs dest path mismatch in :symbolic_link_{absolute,relative}_bodyEnji Cooper2017-03-121-2/+10
| | | | | | | | | | | | | | Unfortunately kyua does not omit the path mismatch on failure, so it must be coded into the error message. Cache the values, run the test(1) call, then print out the values in an atf_fail call to emit the required diagnostics to debug why things are failing. MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315098
* DIRDEPS_BUILD: Add some missing dirctories to the build.Bryan Drewery2016-08-311-0/+11
| | | | | | | Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=305148
* Squelch a false-positive Clang static analyzer warning.Bryan Drewery2016-08-101-0/+1
| | | | | | | | MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=303933
* Fix -b failure not restoring flags on the destination file.Bryan Drewery2016-08-101-2/+16
| | | | | | | | MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=303932
* Fix -S with -l not being atomic.Bryan Drewery2016-08-101-3/+0
| | | | | | | | | | | | | It was unlinking the target even though it uses rename(2) which already effectively does that. -S is intended to not unlink(2) the target first. MFC after: 1 week Reviewed by: jhb Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D7452 Notes: svn path=/head/; revision=303931
* Support -v for -l.Bryan Drewery2016-08-101-1/+14
| | | | | | | | MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=303930
* Fix -S with -b not atomically updating the destination file.Bryan Drewery2016-08-101-2/+8
| | | | | | | | | | | | | | | | | | | | | With both of these flags, the backup was created via rename(dest, backup) followed by rename(tmp, dest). This left the destination file missing for a moment which contradicts the point of -S. This fixes a race with installworld where PRECIOUSPROG and PRECIOUSLIB files (which use -S for installation) would briefly be missing. In the case of installing rtld with parallel installworld it could render an error due to not having rtld present to run install/cp in another process. Reported by: jhb Reviewed by: jhb MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D7451 Notes: svn path=/head/; revision=303929
* Trim out excessive / with -v when target directory ends with a trailing '/'.Bryan Drewery2016-08-101-1/+2
| | | | | | | | | | | This is a minor nit after r289391 made all installations to a directory always end in a trailing '/'. MFC after: 3 days Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=303928
* Pull a copy of the input string before calling basename() and dirname().Ed Schouten2016-07-281-3/+8
| | | | | | | POSIX allows implementations of these functions to modify their input. Notes: svn path=/head/; revision=303450
* install: When preserving timestamps, also copy the nanoseconds part.Jilles Tjoelker2016-06-092-17/+20
| | | | | | | | | Now that we have utimensat in -legacy, install(1) can use it. This is a revert of r299942 which is itself a revert of r299850. Notes: svn path=/head/; revision=301765
* install: Revert utimensat usage (r299850).Jilles Tjoelker2016-05-162-20/+17
| | | | | | | | | | | | This should fix the build on older stable/10, since install is a bootstrap tool. Pending a decision how to fix this properly, revert utimensat usage. Copies with the -p option will again appear older than the original almost always, but -p is not commonly used. Notes: svn path=/head/; revision=299942
* install: When preserving timestamps, also copy the nanoseconds part.Jilles Tjoelker2016-05-152-17/+20
| | | | Notes: svn path=/head/; revision=299850
* install: Add some tests.Jilles Tjoelker2016-05-083-0/+349
| | | | Notes: svn path=/head/; revision=299244
* META MODE: Remove unneeded libmd.host dependency for xinstall.host.Bryan Drewery2015-11-251-12/+0
| | | | | | | | | This is chasing r291026. Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=291322
* META MODE: Fix 'make bootstrap-tools'.Bryan Drewery2015-11-251-1/+0
| | | | | | | | | | | | | | | | | | The main problem was bitrot after elftoolchain being swapped in for the GNU toolchain. This also reworks how the list of 'host allowed' libraries is determined to only allow INTERNALLIBs, which is needed for libelftc to come in. For usr.bin/readelf use the same hack, as libelf and libdward, to bring in the needed sys/ headers for host builds. This has not yet been a problem due to readelf not being built as a host tool in buildworld. This is possible in the meta build though when building the toolchain. Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=291321
* install: do not follow symlinksBaptiste Daroussin2015-11-201-11/+5
| | | | | | | | | | | | | | | In case the target of install is a dead symlink, install(1) used to not consider it as "existing" because of the usage of stat(2) instead of lstat(2). meaning the old file (the symlink) is not removed before the new file is created. The symlink is being followed and the new file becoming the target of the symlink instead of the target of install(1) Reviewed by: jhb, brooks MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D4191 Notes: svn path=/head/; revision=291091
* Remove unneeded libmd from bootstrap-tools (reverting r246784).Bryan Drewery2015-11-181-2/+0
| | | | | | | | | | | | | | | | | | | The bootstrap-tools are supposed to be host tools, which in most cases, use host headers and libraries. As such, directly including the src tree's headers for libmd here causes the need to link libmd in since it will be built with the new symbols (which /usr/lib/libmd.so) won't have unless it is new enough. During the target build in buildworld the target headers are staged into WORLDTMP and used via --sysroot, allowing the target xinstall to be built with the new/target libmd. The .PATH here was also not doing anything since xinstall does not use libmd source files. Sponsored by: EMC / Isilon Storage Division MFC after: 2 weeks Notes: svn path=/head/; revision=291026
* xinstall: renumber UCB clauses to avoid skipping #3Ed Maste2015-09-252-2/+2
| | | | Notes: svn path=/head/; revision=288231
* short circuit install -l rsBaptiste Daroussin2015-06-261-0/+8
| | | | | | | | | When requesting install(1) to only make relative symlinks, by pass all the done to actually compute the relative symlink if the path given in argument is already a relative path Notes: svn path=/head/; revision=284881
* new dependsSimon J. Gerraty2015-06-161-0/+1
| | | | Notes: svn path=/head/; revision=284481
* Add META_MODE support.Simon J. Gerraty2015-06-132-0/+32
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | Off by default, build behaves normally. WITH_META_MODE we get auto objdir creation, the ability to start build from anywhere in the tree. Still need to add real targets under targets/ to build packages. Differential Revision: D2796 Reviewed by: brooks imp Notes: svn path=/head/; revision=284345
| * dirdeps.mk now sets DEP_RELDIRSimon J. Gerraty2015-06-082-4/+0
| | | | | | | | Notes: svn path=/projects/bmake/; revision=284172