Commit Graph

105 Commits

Author SHA1 Message Date
Kyle Evans
6cbda6d943 install(1): Fix relative path calculation with partial common dest/src
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
2019-01-31 05:20:11 +00:00
Kirk McKusick
d81347652c When doing a -S "safe copy", the install command should do an
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)
2018-08-27 15:20:42 +00:00
Alex Richardson
5f40118235 Allow xinstall and makefs to be crossbuilt on Linux and Mac
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
2018-01-16 21:43:46 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
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.
2017-11-20 19:49:47 +00:00
Mateusz Guzik
92b25dcd61 xinstall: plug an infinite loop in directory creation
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
2017-10-12 13:59:23 +00:00
Bryan Drewery
c8a8570cdb Squelch a false-positive Clang static analyzer warning.
MFC after:	1 week
Sponsored by:	EMC / Isilon Storage Division
2016-08-10 18:19:14 +00:00
Bryan Drewery
4a4768d948 Fix -b failure not restoring flags on the destination file.
MFC after:	1 week
Sponsored by:	EMC / Isilon Storage Division
2016-08-10 18:19:11 +00:00
Bryan Drewery
89ad63ad2d Fix -S with -l not being atomic.
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
2016-08-10 18:19:08 +00:00
Bryan Drewery
49cfff9131 Support -v for -l.
MFC after:	1 week
Sponsored by:	EMC / Isilon Storage Division
2016-08-10 18:19:05 +00:00
Bryan Drewery
b81ddc83c9 Fix -S with -b not atomically updating the destination file.
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
2016-08-10 18:19:02 +00:00
Bryan Drewery
e9a4487309 Trim out excessive / with -v when target directory ends with a trailing '/'.
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
2016-08-10 18:18:51 +00:00
Ed Schouten
491cb043bd Pull a copy of the input string before calling basename() and dirname().
POSIX allows implementations of these functions to modify their input.
2016-07-28 16:06:37 +00:00
Jilles Tjoelker
649a3a5626 install: When preserving timestamps, also copy the nanoseconds part.
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.
2016-06-09 21:59:35 +00:00
Jilles Tjoelker
dd53735797 install: Revert utimensat usage (r299850).
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.
2016-05-16 12:56:28 +00:00
Jilles Tjoelker
ecaa1101c3 install: When preserving timestamps, also copy the nanoseconds part. 2016-05-15 13:17:05 +00:00
Baptiste Daroussin
d0b9260683 install: do not follow symlinks
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
2015-11-20 08:45:59 +00:00
Ed Maste
209e744f89 xinstall: renumber UCB clauses to avoid skipping #3 2015-09-25 20:25:18 +00:00
Baptiste Daroussin
9ebcef9a74 short circuit install -l rs
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
2015-06-26 23:55:02 +00:00
Mateusz Guzik
6e633f7297 install: re-check failed mkdir for EEXIST
Since the code stats and mkdirs in 2 separate steps, it is possible that
the directory will be created in the meantime by something else (e.g.
concurrent install).[1]

While here alter the code to properly report stat failure, previously it
would always claim it was mkdir which failed.

Noted by: royger [1]
MFC after:	1 week
2014-09-23 11:41:09 +00:00
Jilles Tjoelker
236a5a7938 install: Use posix_spawnp() for starting strip and improve error messages. 2014-03-08 23:05:28 +00:00
Sean Bruno
c8030037da revert sign changes to buffers used in invocation of digest_update()
Instead, change arguments of internal function digest_update() to accept
signed char arguments.

Remove MAP_FAILED fallback definition and casts of MAP_FAILED.

Thanks to bde@ for looking over this and doing the code analysis.
2013-10-30 18:40:55 +00:00
Sean Bruno
450f41e187 Queisce sign errors by using unsigned char * and casting MAP_FAILED as unsigned
char *

Reviewed by:	brooks@
2013-10-29 20:38:00 +00:00
Brooks Davis
7a06a9247d When in -U mode do avoid setting SUID bits, but do not modify the mode
variable so the intended mode can be logged correctly if -M is specified.

Sponsored by:	DARPA, AFRL
2013-01-31 16:04:40 +00:00
Brooks Davis
f89d608184 Make "install -l s[ar]" act like "ln -sfh" as intended. This fixes
installation of symbolic links where the target is a link is to an
existing directory.
2013-01-22 16:23:08 +00:00
Brooks Davis
f2b19f9ece Introduce six new options from NetBSD:
* -M <metalog>   Log metadata in mtree format.
 * -D <destdir>   Log paths relative to <destdir>.
 * -h <hash>      Log digest of type <hash>.
 * -T <tags>      Specify which mtree tags to log.
 * -l <linkflag>  Create hard or symbolic links (allows logging).
 * -U             Install without root privileges (owner, group, mode,
                  and flags can be logged via -M

NOTE: In the interest of compatibility with NetBSD and because it is the
obvious letter, the nearly useless -M option (disable mmap) has been
repurposed.

Sponsored by:	DARPA, AFRL
Obtained from:	NetBSD
Reviewed by:	bz
2013-01-18 20:57:50 +00:00
Brooks Davis
a6a1856ea3 Implement the -N <dbdir> option which allows an alternate passwd and
group file to be used.  This is useful for installing on systems where
a user or group does not currently exist.

Sponsored by:	DARPA, AFRL
Obtained from:	NetBSD
MFC after:	5 days
2013-01-11 20:53:28 +00:00
Konstantin Belousov
5a21698e2c Issue proper diagnostic on the short writes, also consider the
case of write reporting 0 bytes as short write.

Reported and tested by:	adreast
MFC after:   1 week
2012-07-02 09:53:57 +00:00
Ed Schouten
15f9b56845 Add missing static keywords to xinstall(1) 2011-11-06 08:19:07 +00:00
Ulrich Spörlein
3dfe8ce942 Teach tools/install.sh the -d directory mode.
Sync up with flags understood by install(1) [1], and make install(1)'s
usage output not hide the clearly documented -M flag.

PR:		misc/154739 [1]
Submitted by:	arundel
2011-02-22 08:07:17 +00:00
Rebecca Cran
6bccea7c2b Fix typos - remove duplicate "the".
PR:	bin/154928
Submitted by:	Eitan Adler <lists at eitanadler.com>
MFC after: 	3 days
2011-02-21 09:01:34 +00:00
Joel Dahl
da52b4caaf Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with:	imp, rwatson
2010-12-11 08:32:16 +00:00
Ulrich Spörlein
8fa03d08ca Fix common misspelling of hierarchy
Pointed out by:		bf1783 at gmail
Approved by:		np (cxgb), kientzle (tar, etc.), philip (mentor)
2010-02-20 10:19:19 +00:00
Xin LI
49ecc22cc7 Style improvements:
- Sort function prototypes;
 - Apply static on all function bodies.  To quote bde@:

> It is a good obfuscation to declare functions as static only in the
> prototype, so that you can't see the static for the actual function.
> The reverse obfuscation (with static only in the function definition)
> would make more sense, but is a constraint error.

Reviewed by:	bde
2009-12-14 16:54:39 +00:00
Xin LI
b4d09565cf xinstall.c does not require ctype functions, so ctype.h is not
necessary here.

Note: this would change the md5 checksum due to change caused
by different register layout.
2009-12-13 03:53:15 +00:00
Xin LI
820aa90f57 Staticify internal functions and make usage() a prototype. 2009-12-13 03:34:19 +00:00
Xin LI
821df508e8 Revert most part of 200420 as requested, as more review and polish is
needed.
2009-12-13 03:14:06 +00:00
Xin LI
6f2d322192 Remove unneeded header includes from usr.bin/ except contributed code.
Tested with:	make universe
2009-12-11 23:35:38 +00:00
Edwin Groothuis
1b61ad6f38 Give a better description when a install of multiple files fails
because of the absence of a destination directory or if the
"destination directory" is not a directory.

PR:		bin/11826
Submitted by:	Denis Eremenko <moonshade@pnhz.kz>
Approved by:	grog@
X-MFC after:	various freezes
2007-12-14 08:46:57 +00:00
David E. O'Brien
858494e461 Add an override (DONTSTRIP) so that one can easily install debugable
binaries when one cannot easily edit a package's Makefiles and/or
configure scripts.
2006-03-06 21:52:59 +00:00
Suleiman Souhlal
e80dde60e3 - Make WARNS?= 6 clean
- Add WARNS?= 6

Approved by:	stefanf, grehan (mentor)
2005-01-25 14:34:57 +00:00
Ruslan Ermilov
0222d5bc2d Improved incorrect usage diagnostics. 2004-03-17 11:06:40 +00:00
Ruslan Ermilov
2dc7343e8e GC unnecessary include file. 2004-03-17 10:51:18 +00:00
Ruslan Ermilov
b08f1446e3 - Demangle usage().
- Require the "directory" argument with the -d option.
2004-02-07 07:22:11 +00:00
Poul-Henning Kamp
b83573ce9e Since (x)install is pretty unhelpfull and just spits out a Usage
for a lot of unrelated error conditions, at least report the line
number where it bailed.

Don't use multiline string literals for Usage, gcc 3.3 doesn't like them.
2003-07-11 20:51:16 +00:00
Bill Fenner
01e7d8319d If both the unlink and the open fail, return the errno from the
unlink (very likely EPERM), since the errno from the open might
 be a confusing ETXTBSY.

Approved by:	re
MFC After:	1 week
2002-11-30 23:12:59 +00:00
Bruce Evans
a408bc3483 #include <sys/time.h> instead of depending on namespace pollution in
<sys/stat.h> for the declaration of struct timeval.

Approved by:	re (rwatson)
2002-11-30 18:59:31 +00:00
Peter Wemm
4001ea8d00 A little bit of anti-foot-shooting. Use utimes(2) rather than
the deprecated utime(3).  utimes(2) uses timeval, but utime(3) uses
time_t's.  If you do bad things (like I did) by mixing up include files
with libc, then install can do strange things if you mismatch the time_t
stuff.  utime() is emulated entirely within libc.

Approved by:  re (jhb)
2002-11-15 22:43:56 +00:00
Ruslan Ermilov
1067b3a3fb Do not change the target file's inode-change-time if -C is
specified, the target file already exists and the files are
the same, and the target's file flags and mode need not to
be changed.
2002-10-31 10:41:51 +00:00
David Malone
f4ac32def2 ANSIify function definitions.
Add some constness to avoid some warnings.
Remove use register keyword.
Deal with missing/unneeded extern/prototypes.
Some minor type changes/casts to avoid warnings.

Reviewed by:	md5
2002-09-04 23:29:10 +00:00
Ruslan Ermilov
33c1de7d1f Ignore -C, -p, and -S options of install(1) when used with the -d
option.  Warn about COPY being phased out.  Restore the old method
of always comparing before installing: INSTALL="install -C".

Requested by:	bde
2002-07-29 08:51:04 +00:00