History log of /freebsd-9.3-release/usr.bin/find/function.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 264783 22-Apr-2014 brueffer

MFC: r264418

Avoid double free in f_acl().

CID: 1018508
Found with: Coverity Prevent(tm)


# 264699 20-Apr-2014 jilles

MFC r238780,r238948: 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 (original version)
Relnotes: yes


# 264647 18-Apr-2014 jilles

MFC r263244: 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.


# 260651 14-Jan-2014 jilles

MFC r260336,r260355: find: Fix -lname and -ilname:

* Take into account that readlink() does not add a terminating '\0'.

* 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.

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

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

PR: bin/185393
Submitted by: Ben Reser (parts, original version)


# 248681 24-Mar-2013 jilles

MFC r248446: 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.


# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 223035 13-Jun-2011 avatar

Using statfs.f_fstypename rather than statfs.f_type whilst performing fstype
comparsion as nullfs will copy f_type from underlayer FS.

PR: bin/156258
Submitted by: Marcin Wisnicki <mwisnicki+freebsd@gmail.com>
MFC after: 1 month


# 216370 11-Dec-2010 joel

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


# 216106 01-Dec-2010 kevlo

Don't error out while searching for empty directories.

Submitted by: Bakul Shah <bakul at bitblocks dot com>


# 207705 06-May-2010 delphij

Revert r207677 which is considered a violation of style(9).

Pointed out by: bde
Pointy hat to: delphij


# 207677 05-May-2010 delphij

Move SCCS tags to comments as they were already #if 0'ed.


# 203865 14-Feb-2010 gavin

The -newerXB option was being interpreted the same as the -newerXm option
as a check for F_TIME2_B was missing. Fix this.

PR: bin/138245
Submitted by: "David E. Cross" <crossd cs.rpi.edu>
MFC after: 1 month


# 203723 09-Feb-2010 ed

Don't let find(1) depend on struct timeb.

This structure is deprecated and only used by ftime(2), which is part of
libcompat. The second argument of get_date() is unused, which means we
can just remove it entirely.


# 201227 29-Dec-2009 ed

ANSIfy almost all applications that use WARNS=6.

I was considering committing all these patches one by one, but as
discussed with brooks@, there is no need to do this. If we ever
need/want to merge these changes back, it is still possible to do this
per application.


# 196839 04-Sep-2009 trasz

Add NFSv4 ACL support to find(1).

Reviewed by: rwatson


# 193087 30-May-2009 jilles

rm, find -delete: fix removing symlinks with uchg/uappnd set.

Formerly, this tried to clear the flags on the symlink's target
instead of the symlink itself.

As before, this only happens for root or for the unlink(1) variant of rm.

PR: bin/111226 (part of)
Submitted by: Martin Kammerhofer
Approved by: ed (mentor)
MFC after: 3 weeks


# 192381 19-May-2009 avg

find: do not silently disable -L when -delete is used

First of all, current behavior is not documented and confusing,
and it can be very dangerous in the following sequence:
find -L . -type l
find -L . -type l -delete
(the second line is even suggested by find(1)).

Instead simply refuse to proceed when -L and -delete are both used.
A descriptive error message is provided.
The following command can be safely used to remove broken links:
find -L . -type l -print0 | xargs rm -0

To do: update find(1)
PR: bin/90687
Obtained from: Anatoli Klassen <anatoli@aksoft.net>
Approved by: jhb (mentor)


# 176497 23-Feb-2008 imp

The matching in -lname and -ilname are on the contents of the link
itself, not on the type of the file. As such, do a readlink to get
the symbolic link's contents and fail to match if the path isn't a
symbolic link.

Pointed out by: des@


# 176478 23-Feb-2008 imp

Implement a number of primaries present in GNU find, but not present
in our find.

The following are nops because they aren't relevant to our find:
-ignore_readdir_race
-noignore_readdir_race
-noleaf
The following aliaes were created:
-gid -> -group [2]
-uid -> -user [2]
-wholename -> -path
-iwholename -> ipath
-mount -> -xdev
-d -> -depth [1]
The following new primaries were created:
-lname like -name, but matches symbolic links only)
-ilname like -lname but case insensitive
-quit exit(0)
-samefile returns true for hard links to the specified file
-true Always true
I changed one primary to match GNU find since I think our use of it violates
POLA
-false Always false (was an alias for -not!)

Also, document the '+' modifier for -execdir, as well as all of the above.
This was previously implemented.

Document the remaining 7 primaries that are in GNU find, but aren't yet
implemented in find(1)

[1] This was done in GNU find for compatibility with FreeBSD, yet they
mixed up command line args and primary args.

[2] -uid/-gid in GNU find ONLY takes a numeric arg, but that arg does the
normal range thing that. GNU find -user and -uid also take a numberic arg,
but don't do the range processing. find(1) does both for -user and -group,
so making -uid and -gid aliases is compatible for all non-error cases used
in GNU find. While not perfect emulation, this seems a reasonable thing
for us.


# 158986 27-May-2006 krion

Add the capability for a trailing scale indicator to cause the
specified size to be read in the more familiar units of kilobytes,
megabytes, gigabytes, terabytes and petabytes.

PR: bin/50988
Submitted by: Matthew Seaman <m.seaman@infracaninophile.co.uk>
MFC after: 7 days


# 158919 25-May-2006 krion

Enable numeric arguments and +/- prefixes with -user (-group)
options.

PR: bin/71513
Submitted by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
MFC after: 7 days


# 158572 14-May-2006 krion

The last execution of -exec {} + is not done if the -exec primary is
not on the top-level -and sequence, e.g. inside of ! or -or.

Create a separate linked list of all active -exec {} + primaries and
do the last execution for all at termination.

PR: bin/79263
Submitted by: Jilles Tjoelker <jilles@stack.nl>
MFC after: 7 days


# 157440 03-Apr-2006 ceri

Add -Btime, -Bnewer, -Bmin, -newerB[Bacmt], -newer[acmt]B options to
work with the st_birthtime field of struct stat.

'B' has been chosen to match the format specifier from stat(1).

Approved by: jhb
MFC after: 2 weeks


# 149453 25-Aug-2005 roberto

Fixes for gcc4.x.

Submitted by: Divacky Roman <xdivac02@stud.fit.vutbr.cz>
PR: bin/84991


# 140810 25-Jan-2005 ssouhlal

- Make find(1) WARNS?= 6 clean
- Bump to WARNS?= 6

Approved by: stefanf, grehan (mentor)


# 132815 29-Jul-2004 tjr

Change the 'no terminating ";"' error message to 'no terminating ";" or "+"'
since + is also a valid way to terminate -exec.


# 132814 29-Jul-2004 tjr

Remove partial support for building this on NetBSD.


# 129812 28-May-2004 eik

- introduce a new primary `-depth n', which tests whether
the depth of the current file relative to the starting
point of the traversal is n. The usual +/- modifiers
to the argument apply.

- while I'm here, fix -maxdepth in the case of a depth-first
traversal

Print the top ten maintainers of python module ports
(works with p5-* too):

find /usr/ports -depth 2 \! -name 'py-*' -prune -o \
-depth 3 -name Makefile -execdir make -VMAINTAINER \; \
| sort | uniq -c | sort -nr | head

PR: 66667
Reviewed by: ru, joerg
Approved by: joerg
MFC after: 2 weeks


# 127796 03-Apr-2004 bmilekic

Give find(1) the option -acl to locate files with extended
ACLs. This is similar to what ls(1) can do. It is handy to
have it so that it can be used in conjunction with
"-exec setfacl {} \;" (to find(1)), among others.

This is the submitter's patch, but slightly modified.

PR: bin/65016
Submitted by: Christian S.J. Peron <maneo@bsdpro.com>


# 116333 14-Jun-2003 markm

Fix all WARNS. Checked with "make WARNS=9". Remove unused file.


# 101651 10-Aug-2002 mux

- Introduce a new struct xvfsconf, the userland version of struct vfsconf.
- Make getvfsbyname() take a struct xvfsconf *.
- Convert several consumers of getvfsbyname() to use struct xvfsconf.
- Correct the getvfsbyname.3 manpage.
- Create a new vfs.conflist sysctl to dump all the struct xvfsconf in the
kernel, and rewrite getvfsbyname() to use this instead of the weird
existing API.
- Convert some {set,get,end}vfsent() consumers to use the new vfs.conflist
sysctl.
- Convert a vfsload() call in nfsiod.c to kldload() and remove the useless
vfsisloadable() and endvfsent() calls.
- Add a warning printf() in vfs_sysctl() to tell people they are using
an old userland.

After these changes, it's possible to modify struct vfsconf without
breaking the binary compatibility. Please note that these changes don't
break this compatibility either.

When bp will have updated mount_smbfs(8) with the patch I sent him, there
will be no more consumers of the {set,get,end}vfsent(), vfsisloadable()
and vfsload() API, and I will promptly delete it.


# 99905 13-Jul-2002 tjr

Account for space used by environment variables in a similar way to
xargs(1) when handling -exec ... {} + constructions.


# 97736 02-Jun-2002 tjr

Support the SysV-style -exec utility args.. {} + function, required by
SUSv3. This is similar to find foo -print0 | xargs -0 utility args.


# 96785 17-May-2002 jmallett

Clean up malloc(3)'s argument. Remove casts which do nothing when we're
using sizeof() anyway. Use slightly more consistent (per-file) error
reporting for malloc(3) returning NULL. If "malloc failed" was being printed,
don't use err(3). If a NULL format is being used, use err(3). In one case
errx(3) was being used with strerror(3), so just use err(3).


# 96704 16-May-2002 trhodes

More consistancy. file system > filesystem


# 93644 02-Apr-2002 markm

There is breakage in parsedate, so revert to get_date until this can be
resolved.

Reported by: paul


# 93628 02-Apr-2002 jmallett

Fix find -exec with no command specified (i.e.: find . -exec ';')

PR: bin/36521
Submitted by: Simon 'corecode' Schubert <corecode@corecode.ath.cx>
Reviewed by: mike
MFC after: 3 days


# 93604 01-Apr-2002 obrien

Fix SCM IDs.


# 93212 26-Mar-2002 charnier

spelling


# 92904 21-Mar-2002 markm

Restructure for own parsedate (replacement for get_date from CVS).

Fix up parsedate.y for WARNS=4.

Reviewd by: bde (except for parsedate.y diffs)


# 92786 20-Mar-2002 markm

Remove __P().


# 91400 27-Feb-2002 dwmalone

1) Remove -Wall from Makefile.
2) WARNs fixes (rename option to lookup_option to avoid shadowing, rename
argv to argv1 to avoid shadowing, const stuff, prototypes, __unused).
3) Remove "register"s.


# 83451 14-Sep-2001 ru

Simplify f_Xtime().


# 83450 14-Sep-2001 ru

Bloat find(1) even more, and introduce the concept
of time units to be used with -[acm]time primaries.

Based on patch from Nils M Holm <nmh@t3x.org>.

PR: bin/29165, bin/30309


# 82972 04-Sep-2001 ru

The implementation of -flags was broken and did not match the (poorly)
documented behavior. Only a certain set of file flags were recognized,
and "no" flags did not match files that have corresponding flags bits
turned off.

Fix and extend the -flags functionality as follows:

: -flags [-|+]<flags>,<notflags>
: The flags are specified using symbolic names (see chflags(1)).
: Those with the "no" prefix (except "nodump") are said to be
: <notflags>. Flags in <flags> are checked to be set, and flags in
: <notflags> are checked to be not set. Note that this is different
: from -perm, which only allows the user to specify mode bits that
: are set.
:
: If flags are preceded by a dash (``-''), this primary evaluates
: to true if at least all of the bits in <flags> and none of the bits
: in <notflags> are set in the file's flags bits. If flags are pre-
: ceded by a plus (``+''), this primary evaluates to true if any of
: the bits in <flags> is set in the file's flags bits, or any of the
: bits in <notflags> is not set in the file's flags bits. Otherwise,
: this primary evaluates to true if the bits in <flags> exactly match
: the file's flags bits, and none of the <flags> bits match those of
: <notflags>.

MFC after: 2 weeks


# 82569 30-Aug-2001 ru

Restore the `-perm +mode' feature.

Broken in the "close a PR" race, in revision 1.30.
Note that the patch in the PR did not have this bug!


# 80291 24-Jul-2001 obrien

Remove emalloc and expand to the malloc + error checking it was, where used.


# 76250 03-May-2001 phk

They add the following commands:
-anewer
-cnewer
-mnewer
-okdir
-newer[acm][acmt]

With it, you can form queries like

find . -newerct '1 minute ago' -print

As an extra bonus, the program is ANSI-fied - the original version
relies on some obscure features of K&R C.

(This PR was submitted in 1999, and the submittor has kept the patch
updated ever since, hats off for him guys, and how about you close a PR ??)

PR: 9374
Submitted by: Martin Birgmeier <Martin.Birgmeier@aon.at>


# 72945 23-Feb-2001 knu

Implement the following options and primaries:

-E Interpret regular expressions followed by -regex and -iregex op-
tions as extended (modern) regular expressions rather than basic
regular expressions (BRE's). The re_format(7) manual page fully
describes both formats.

-iname pattern
Like -name, but the match is case insensitive.

-ipath pattern
Like -path, but the match is case insensitive.

-regex pattern
True if the whole path of the file matches pattern using regular
expression. To match a file named ``./foo/xyzzy'', you can use
the regular expression ``.*/[xyz]*'' or ``.*/foo/.*'', but not
``xyzzy'' or ``/foo/''.

-iregex pattern
Like -regex, but the match is case insensitive.

These are meant to be compatible with other find(1) implementations
such as GNU's or NetBSD's except regexp library differences.

Reviewed by: sobomax, dcs, and some other people on -current


# 71422 23-Jan-2001 peter

Add the -empty flag, from OpenBSD. It returns true if the directory
is empty. There doesn't appear to be another easy way to do this.

mobile# mkdir foo
mobile# mkdir foo/bar
mobile# mkdir bar
mobile# find . -empty
./foo/bar
./bar


# 63969 28-Jul-2000 eivind

Make passing unknown fstypes to -fstype result in a warning instead of
an error. As it was, which find command lines that would work (be
accepted at all) was dependent on the presently running kernel, making
script writing and porting hard.


# 61749 17-Jun-2000 joe

Switch over to using the new fflagstostr and strtofflags library calls.


# 61651 14-Jun-2000 roberto

Make find -Wall -Wredundant-decls clean.

Submitted by: nrahlstr


# 61575 12-Jun-2000 roberto

This patch adds the -mindepth and -maxdepth options to find(1), which
behave as in GNU find (and of course as described in the manual page
diff included). I think these options would be useful for some people.

Some missing $FreeBSD$ tags are also added.

The patch was slightly modified (send-pr mangling of TABS).

PR: bin/18941
Submitted by: Ben Smithurst <ben@scientia.demon.co.uk>


# 61573 12-Jun-2000 roberto

The find -perm option currently supports an exact match,
or if the mode is preceded by a '-', it checks for a match
in at least the bits specified on the command line. It is
often desirable to find things with any execute or setuid or
setgid bits set.

PR: bin/10169
Submitted by: Monte Mitzelfelt <monte@gonefishing.org>


# 57003 05-Feb-2000 joe

Revert part of the last commit, remove {g|s}etflags from the libc
interface, and statically link them to the programs using them.
These functions, upon reflection and discussion, are too generically
named for a library interface with such specific functionality.
Also the api that they use, whilst ok for private use, isn't good
enough for a libc function.

Additionally there were complications with the build/install-world
process. It depends heavily upon xinstall, which got broken by
the change in api, and caused bootstrap problems and general mayhem.

There is work in progress to address future problems that may be
caused by changes in install-chain tools, and better names for
{g|s}etflags can be derived when some future program requires them.
For now the code has been left in src/lib/libc/gen (it started off
in src/bin/ls).

It's important to provide library functions for manipulating file
flag strings if we ever want this interface to be adopted outside
of the source tree, but now isn't necessarily the right moment
with 4.0-release just around the corner.

Approved: jkh


# 56692 27-Jan-2000 joe

Historically file flags (schg, uschg, etc) have been converted from
string to u_long and back using two functions, flags_to_string and
string_to_flags, which co-existed with 'ls'. As time has progressed
more and more other tools have used these private functions to
manipulate the file flags.

Recently I moved these functions from /usr/src/bin/ls to libutil,
but after some discussion with bde it's been decided that they
really ought to go in libc.

There are two already existing libc functions for manipulating file
modes: setmode and getmode. In keeping with these flags_to_string
has been renamed getflags and string_to_flags to setflags.

The manual page could probably be improved upon ;)


# 54828 19-Dec-1999 roberto

Second part of bin/3648: add -flags to search for specific flags.
I added $FreeBSD$ whicle I was here. The patch wasn't usable anymore
due to its age so I adapted it.

PR: bin/3648
Submitted by: Martin Birgmeier <mbirg@austria.ds.philips.com>


# 51037 06-Sep-1999 billf

-Wall: remove unused variable, initialize variable to avoid gcc stupidity.


# 41846 16-Dec-1998 imp

Return memory from setmode.

Obtained from: OpenBSD


# 40301 13-Oct-1998 des

Calls one or more of malloc(), warn(), err(), syslog(), execlp() or
execvp() in the child branch of a vfork(). Changed to use fork()
instead.

Some of these (mv, find, apply, xargs) might benefit greatly from
being rewritten to use vfork() properly.

PR: Loosely related to bin/8252
Approved by: jkh and bde


# 32402 10-Jan-1998 jb

A partial frontal lobotomy for find if using the NetBSD libc which
doesn't know about getvfsbyname() and the vfsconf structure. This
disables the -fstype option if compiled with a pre-processor that
defines __NetBSD__. With the FreeBSD built pre-processor, find can only
be built with the FreeBSD libc. So when running with a NetBSD kernel,
FreeBSD's libc will have to return ENOSYS for things that NetBSD
doesn't support. That's life in a hybrid world.


# 30395 13-Oct-1997 wosch

Add the primaries -mmin, -amin, -cmin to find, similar to the GNU find.


# 28914 29-Aug-1997 imp

Add -execdir which will execute the exec command in the dir of the file
in question. This change and the fts changes should be merged into 2.2-stable
as soon as they are vetted in -current. This should allow cleaning of files
in /tmp to be reneabled.
Obtained from: OpenBSD


# 24313 27-Mar-1997 peter

Fix "-fstype local" that was broken by another bugfix in the Lite2 merge.

Submitted by: Dmitrij Tejblum <dima@tejblum.dnttm.rssi.ru>, PR#3076


# 23695 11-Mar-1997 peter

Merge from Lite2 - use new getvfsbyname() and related changes.
understand whiteouts (FTS_W from fts()).


# 22066 28-Jan-1997 wosch

The option "fstype" does not handle the argument "msdos" correctly.
This error results from changing the name for the msdos file system
from "pcfs" to "msdos". Close PR #1105

submitted by: Thomas Wintergerst <thomas@lemur.nord.de>,
Slaven Rezic <eserte@cs.tu-berlin.de>


# 18720 05-Oct-1996 peter

With -delete, don't complain about non-empty directories. Otherwise
"cd /tmp; find . -mtime +7 -delete" is excessively noisy.


# 18713 05-Oct-1996 peter

For the -delete option, emulate the behavior of "rm -f" when dealing with
user-immutable files.

Requested by: ache


# 18681 04-Oct-1996 peter

Implement a -delete option to find. The code is extremely paranoid and
goes to a fair degree of trouble to enable something like this to
be safe: cd /tmp && find . -mtime +7 -delete

It removes both files and directories. It does not attempt to remove
immutable files (an earlier version I showed to a few people did a chflags
and tried to blow away even immutable files. Too risky..)

It is thought to be safe because it forces the fts(3) driven descent to
only do "minimal risk" stuff. specifically, -follow is disabled, it does
checking to see that it chdir'ed to the directory it thought it was
going to, it will *not* pass a pathname with a '/' character in it to
unlink(), so it should be totally immune to symlink tree races. If it runs
into something "fishy", it bails out rather than blunder ahead.. It's better
to do that if somebody is trying to compromise security rather than risk
giving them an opportunity. Since the unlink()/rmdir() is being called
from within the current working directory during the tree descent, there
are no fork/exec overheads or races.

As a side effect of this paranoia, you cannot do a
"find /somewhere/dir -delete", as the last argument to rmdir() is
"/somewhere/dir", and the checking won't allow it. Besides, one would use
rm -rf for that case anyway. :-)

Reviewed by: pst (some time ago, but I've removed the immutable file
deletion code that he complained about since he last saw it)


# 15102 07-Apr-1996 bde

Use strtoq() instead of strtol() so that large inums, and sizes can be
specified.

Not fixed: specification of large uids and gids; silent truncation of
unrepresentable values.


# 11538 16-Oct-1995 wollman

Don't use printf() for simple strings because it is slow. Closes PR 783.

Submitted by: Wolfram Schneider <wosch@freebsd.first.gmd.de>


# 10704 12-Sep-1995 nate

Simpler fix to the find bug reported by Terry Lambert <terry@lambert.org>

[ Find to a file vs. to stdout ] produces different output because find
does not flush stdout when doing a -print.

Submitted by: Jeffrey Hsu <hsu@freefall.freebsd.org>


# 9987 07-Aug-1995 wollman

Delete bogus referneces to timezone code internal header file `tzfile.h',
which is no longer bogusly installed in /usr/include.


# 8874 30-May-1995 rgrimes

Remove trailing whitespace.


# 8389 09-May-1995 wollman

Add GNU-style `-print0' primary. This exists so that one can safely
do `find some-nasty-expression -print0 | perl -n0e unlink' and have all
the files actuallly get deleted. (Using `xargs' and `rm' is not safe.)


# 1591 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1590,
which included commits to RCS files with non-trunk default branches.


# 1590 27-May-1994 rgrimes

BSD 4.4 Lite Usr.bin Sources