Commit Graph

231 Commits

Author SHA1 Message Date
Marcelo Araujo
26ac9660a4 Use NULL instead of 0 for pointers.
MFC after:	2 weeks.
2016-04-18 07:05:18 +00:00
Bryan Drewery
bd18fd57db DIRDEPS_BUILD: Regenerate without local dependencies.
These are no longer needed after the recent 'beforebuild: depend' changes
and hooking DIRDEPS_BUILD into a subset of FAST_DEPEND which supports
skipping 'make depend'.

Sponsored by:	EMC / Isilon Storage Division
2016-02-24 17:20:11 +00:00
Jilles Tjoelker
a2925a5ae3 find: Fix segfault with very long path in -exec/-ok ... {} \;.
If the resulting argument is longer than MAXPATHLEN, realloc() was called to
extend the space, but the new pointer was not correctly stored.

Different from what OpenBSD has done, rewrite brace_subst() to calculate the
necessary space first and realloc() at most once.

As before, the e_len fields are not updated in case of a realloc.
Therefore, a following long argument will do another realloc.

PR:		201750
MFC after:	1 week
2015-08-05 21:33:30 +00:00
Simon J. Gerraty
2ef6d5a7b9 new depends 2015-06-16 23:37:19 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
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
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Eitan Adler
6f9b387301 find.1: Add missing whitespace:
Obtained from:	Dragonfly (dee38d02d51cc8316f82b0263158d2546f2398bc)
2015-04-20 02:23:00 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Ed Maste
599df3ef01 Correct scale factor for T terabyte suffix
PR:		194250
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2014-10-08 17:40:58 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Christian Brueffer
2545695e6a Avoid double free in f_acl().
CID:		1018508
Found with:	Coverity Prevent(tm)
MFC after:	1 week
2014-04-13 19:48:51 +00:00
Jilles Tjoelker
b547523eb4 find: Return normal exit status from -quit.
If there was an error, make the exit status reflect this even if -quit
caused the exit. Formerly, -quit always caused exit(0).

GNU find does the same.
2014-04-13 11:47:17 +00:00
Jilles Tjoelker
7a79617cc1 find: Correctly propagate -exec/-execdir ... {} + exit status.
As per POSIX, the -exec ... {} + primary always returns true, but a non-zero
exit status causes find to return a non-zero exit status itself. GNU does
the same, and also for -execdir ... {} +.

It does not make much sense to return false from the primary only when the
child process happens to be run.

The behaviour for -exec/-execdir ... ; remains unchanged: the primary
returns true or false depending on the exit status, and find's exit status
is unaffected.
2014-04-12 22:36:26 +00:00
Jilles Tjoelker
73a0af46b8 find: Treat errno from fts_read() more carefully.
fts_read() leaves errno unchanged on EOF and sets it on error, so set errno
to 0 before calling it. Also, don't trust finish_execplus() to leave errno
unchanged.
2014-04-06 20:04:33 +00:00
Jilles Tjoelker
cf599562fa find: When performing -quit, finish pending -exec ... + command lines.
This avoids unexpected partial processing when a find command uses both
-quit and -exec ... +.

GNU find does the same.

MFC after:	1 week
2014-03-16 14:42:58 +00:00
Jilles Tjoelker
b95de98a6b find: Allow -type d without statting everything.
fts(3) detects directories even in FTS_NOSTAT mode (so it can descend into
them).

No functional change is intended, but find commands that use -type d but no
primaries that still require stat/lstat calls make considerably fewer system
calls.
2014-01-11 21:12:27 +00:00
Jilles Tjoelker
e810bef741 find: Fix two more problems with -lname and -ilname:
* Do not match symlinks that are followed because of -H or -L. This is
  explicitly documented in GNU find's info file and is like -type l.

* Fix matching symlinks in subdirectories when fts changes directories.

Also, avoid some readlink() calls on files that are obviously not symlinks
(because of fts(3) restrictions, not all of them).

MFC after:	1 week
2014-01-05 23:01:28 +00:00
Jilles Tjoelker
3e02329a38 find: Fix -lname and -ilname.
The code did not take into account that readlink() does not add a
terminating '\0', and therefore did not work reliably.

As before, symlinks of length PATH_MAX or more are not handled correctly.
(These can only be created on other operating systems.)

PR:		bin/185393
Submitted by:	Ben Reser (original version)
MFC after:	1 week
2014-01-05 21:44:04 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Jilles Tjoelker
9d6d5a7131 find: Allow -delete to delete files given as arguments.
Formerly, a command like find dir1/dir2 -delete would delete everything
under dir1/dir2 but not dir1/dir2 itself.

When -L is not specified and "." can be opened, the fts(3) code underlying
find(1) is careful to avoid following symlinks or being dropped in different
locations by moving the directory fts is currently traversing. If a
problematic concurrent modification is detected, fts will not enter the
directory or abort. Files found in the search are returned via the current
working directory and a pathname not containing a slash.

For paranoia, find(1) verifies this when -delete is used. However, it is too
paranoid about the root of the traversal. It is already assumed that the
initial pathname does not refer to directories or symlinks that might be
replaced by untrusted users; otherwise, the whole traversal would be unsafe.
Therefore, it is not necessary to do the check for fts_level ==
FTS_ROOTLEVEL.

Deleting the pathnames given as arguments can be prevented without error
messages using -mindepth 1 or by changing directory and passing "." as
argument to find. This works in the old as well as the new version of find.

Tested by:	Kurt Lidl
Reviewed by:	jhb
2013-08-02 14:14:23 +00:00
Ed Schouten
7e659f9491 Add the Clang specific -Wmissing-variable-declarations to WARNS=6.
This compiler flag enforces that that people either mark variables
static or use an external declarations for the variable, similar to how
-Wmissing-prototypes works for functions.

Due to the fact that Yacc/Lex generate code that cannot trivially be
changed to not warn because of this (lots of yy* variables), add a
NO_WMISSING_VARIABLE_DECLARATIONS that can be used to turn off this
specific compiler warning.

Announced on:	toolchain@
2013-04-19 19:45:00 +00:00
Simon J. Gerraty
69e6d7b75e sync from head 2013-04-12 20:48:55 +00:00
Jilles Tjoelker
ddd956b0b7 find: Include nanoseconds when comparing timestamps of files.
When comparing to the timestamp of a given file using -newer, -Xnewer and
-newerXY (where X and Y are one of m, c, a, B), include nanoseconds in the
comparison.

The primaries that compare a timestamp of a file to a given value (-Xmin,
-Xtime, -newerXt) continue to compare times in whole seconds.

Note that the default value 0 of vfs.timestamp_precision almost always
causes the nanoseconds part to be 0. However, touch -d can set a timestamp
to the microsecond regardless of that sysctl.

MFC after:	1 week
2013-03-17 22:51:58 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
David Malone
9ed0c92c91 Add an option for finding sparse files.
Reviewed by:	iedowse
MFC after:	3 weeks
2013-03-03 20:10:56 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Jilles Tjoelker
17ef6d3ab8 find: Run when cwd cannot be opened, except with -execdir or -delete.
fts(3) can run (albeit more slowly and imposing the {PATH_MAX} limit) when
the current directory cannot be opened. Therefore, do not make a failure to
open the current directory (for returning to it later in -exec) fatal.

If -execdir or -delete are used, the expectation is that fts(3) will use
chdir to avoid race conditions (except for -execdir with -L). Do not break
this expectation any more than it already is by still failing if the current
directory cannot be opened.
2013-02-10 18:56:37 +00:00
Jilles Tjoelker
bc62617630 find: In -execdir ... {} +, only pass one file per invocation.
This is inefficient but ensures that -execdir ... {} + does not mix files
from different directories in one invocation; the command could not access
some files. Files from the same directory should really be handled in one
invocation but this is somewhat more complicated.
2013-02-10 13:28:02 +00:00
David E. O'Brien
d9a447559b Sync with HEAD. 2013-02-08 16:10:16 +00:00
Eitan Adler
81b295a17b Use .Nm instead of a self xref
Approved by:	bcr (mentor)
MFC after:	1 week
2012-11-19 15:12:44 +00:00
Eitan Adler
115b335eca Make it clear that amin and friends take + and - options.
PR:		docs/173265
Submitted by:	Anton Shterenlikht <mexas@bristol.ac.uk>
Approved by:	bcr (mentor)
MFC after:	3 days
2012-11-18 16:34:03 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Matthew D Fleming
b424efd5b1 Fix usr.bin/ and usr.sbin/ build with a 64-bit ino_t.
Original code by:	Gleb Kurtsou
2012-09-27 23:31:19 +00:00
Jilles Tjoelker
bedab466ce find: Do not pass fd to save current directory to child processes.
This removes one of the two wrongly passed file descriptors. The other one
appears to be from fts(3).

MFC after:	1 week
2012-09-26 20:16:15 +00:00
Dag-Erling Smørgrav
baf0230645 Note that -quit terminates successfully.
Requested by:	jmg@
2012-09-10 07:56:59 +00:00
Dag-Erling Smørgrav
9168a75a66 Document -quit, four and a half years after it was implemented.
MFC after:	3 days
Pointy hat to:	imp@
2012-09-09 13:18:13 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Jilles Tjoelker
b562679671 find: Remove unnecessary and inconsistent initialization.
Submitted by:	jhb
2012-07-31 16:55:41 +00:00
Jilles Tjoelker
40072dc2b7 find: Implement real -ignore_readdir_race.
If -ignore_readdir_race is present, [ENOENT] errors caused by deleting a
file after find has read its name from a directory are ignored.

Formerly, -ignore_readdir_race did nothing.

PR:		bin/169723
Submitted by:	Valery Khromov and Andrey Ignatov
2012-07-25 21:59:10 +00:00
Jilles Tjoelker
eb55578582 find(1): Move description of -d option to -depth primary.
The nullary -depth primary is standard and the -d option provides little
advantage.

PR:		docs/168885
MFC after:	1 week
2012-06-13 21:53:40 +00:00
Isabell Long
a86224465d Add more description and clarification about the -depth and -d options in
both places where they are mentioned in find(1).

Discussed with:	dougb
PR:		docs/168885
Reported by:	Ronald F. Guilmette (rfg at tristatelogic dot com)
Approved by:	gabor (mentor)
MFC after:	3 days
2012-06-10 22:14:52 +00:00
Eitan Adler
3e0efd2ec4 Fix style nit: don't use leading zero for dates in .Dd
Prompted by:	brueffer
Approved by:	brueffer
MFC after:	3 days
2012-06-05 03:14:39 +00:00
Eitan Adler
5102783b6e Document the limitations of the -delete primary
PR:		bin/166554
Submitted by:	Richard Kettlewell <rjk@greenend.org.uk>
Discussed with:	jilles
Approved by:	bcr
MFC after:	3 days
2012-06-02 03:13:27 +00:00
Baptiste Daroussin
5e2a209a27 Fix world after byacc import:
- old yacc(1) use to magicially append stdlib.h, while new one don't
- new yacc(1) do declare yyparse by itself, fix redundant declaration of
  'yyparse'

Approved by:	des (mentor)
2012-05-22 16:33:10 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Joel Dahl
126b754db4 Remove superfluous paragraph macro. 2012-03-25 09:19:25 +00:00
Ed Schouten
516c8ed9dd Replace char copyright[] by static const char copyright[].
It seems the latter is used throughout the tree.
2011-12-10 18:11:06 +00:00