summaryrefslogtreecommitdiff
path: root/usr.bin/find/function.c
Commit message (Collapse)AuthorAgeFilesLines
* find(1): deLINTifyEitan Adler2018-07-011-2/+0
| | | | Notes: svn path=/head/; revision=335851
* Allow compiling usr.bin/find on Linux and MacAlex Richardson2018-02-061-1/+17
| | | | | | | | | | | | | | | | When building FreeBSD the makefiles invoke find with various flags such as `-s` that aren't supported in the native /usr/bin/find. To fix this I build the FreeBSD version of find and use that when crossbuilding. Inserting lots if #ifdefs in the code is rather ugly but I don't see a better solution. Reviewed By: brooks (mentor) Approved By: jhb (mentor) Differential Revision: https://reviews.freebsd.org/D13306 Notes: svn path=/head/; revision=328933
* find(1): Fix -newer and -samefile to conform to POSIX[0]Conrad Meyer2017-12-291-2/+12
| | | | | | | | | | | | | | | | | By default, or with the -P flag, find(1) should evaluate paths "physically." For symlinks, this means using the link itself instead of the target. Historically (since the import of BSD 4.4-lite from CSRG), find(1) has failed to refer to the link itself, at least for -newer and -samefile. [0]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html PR: 222698 Reported by: Harald Schmalzbauer <bugzilla.freebsd AT omnilan.de> Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=327362
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | 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
* find(1): Don't treat statfs() error as fatal in f_fstype, which can happenXin LI2017-11-111-2/+7
| | | | | | | | | | | | | | | when a directory is removed in the middle of find. Instead of a full err(), allow find to continue, plus print a warning with exitstatus set when appropriate. Reported by: 100.chksetuid via gordon Reviewed by: jilles MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D13024 Notes: svn path=/head/; revision=325723
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Use NULL instead of 0 for pointers.Marcelo Araujo2016-04-181-1/+1
| | | | | | | MFC after: 2 weeks. Notes: svn path=/head/; revision=298189
* Correct scale factor for T terabyte suffixEd Maste2014-10-081-1/+1
| | | | | | | | | PR: 194250 MFC after: 3 days Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=272762
* Avoid double free in f_acl().Christian Brueffer2014-04-131-1/+0
| | | | | | | | | CID: 1018508 Found with: Coverity Prevent(tm) MFC after: 1 week Notes: svn path=/head/; revision=264418
* find: Return normal exit status from -quit.Jilles Tjoelker2014-04-131-1/+1
| | | | | | | | | | 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. Notes: svn path=/head/; revision=264411
* find: Correctly propagate -exec/-execdir ... {} + exit status.Jilles Tjoelker2014-04-121-1/+7
| | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=264387
* find: When performing -quit, finish pending -exec ... + command lines.Jilles Tjoelker2014-03-161-0/+1
| | | | | | | | | | | | This avoids unexpected partial processing when a find command uses both -quit and -exec ... +. GNU find does the same. MFC after: 1 week Notes: svn path=/head/; revision=263244
* find: Allow -type d without statting everything.Jilles Tjoelker2014-01-111-2/+8
| | | | | | | | | | | | 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. Notes: svn path=/head/; revision=260555
* find: Fix two more problems with -lname and -ilname:Jilles Tjoelker2014-01-051-1/+11
| | | | | | | | | | | | | | | * 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 Notes: svn path=/head/; revision=260355
* find: Fix -lname and -ilname.Jilles Tjoelker2014-01-051-2/+5
| | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=260336
* find: Allow -delete to delete files given as arguments.Jilles Tjoelker2013-08-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=253886
* find: Include nanoseconds when comparing timestamps of files.Jilles Tjoelker2013-03-171-19/+28
| | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=248446
* Add an option for finding sparse files.David Malone2013-03-031-0/+23
| | | | | | | | Reviewed by: iedowse MFC after: 3 weeks Notes: svn path=/head/; revision=247730
* find: Run when cwd cannot be opened, except with -execdir or -delete.Jilles Tjoelker2013-02-101-1/+15
| | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=246628
* find: In -execdir ... {} +, only pass one file per invocation.Jilles Tjoelker2013-02-101-1/+7
| | | | | | | | | | 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. Notes: svn path=/head/; revision=246618
* find: Implement real -ignore_readdir_race.Jilles Tjoelker2012-07-251-0/+19
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=238780
* Using statfs.f_fstypename rather than statfs.f_type whilst performing fstypeTai-hwa Liang2011-06-131-20/+6
| | | | | | | | | | | 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 Notes: svn path=/head/; revision=223035
* Remove the advertising clause from UCB copyrighted files in usr.bin. ThisJoel Dahl2010-12-111-4/+0
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=216370
* Don't error out while searching for empty directories.Kevin Lo2010-12-021-1/+1
| | | | | | | Submitted by: Bakul Shah <bakul at bitblocks dot com> Notes: svn path=/head/; revision=216106
* Revert r207677 which is considered a violation of style(9).Xin LI2010-05-061-2/+6
| | | | | | | | Pointed out by: bde Pointy hat to: delphij Notes: svn path=/head/; revision=207705
* Move SCCS tags to comments as they were already #if 0'ed.Xin LI2010-05-051-6/+2
| | | | Notes: svn path=/head/; revision=207677
* The -newerXB option was being interpreted the same as the -newerXm optionGavin Atkinson2010-02-141-0/+2
| | | | | | | | | | | 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 Notes: svn path=/head/; revision=203865
* Don't let find(1) depend on struct timeb.Ed Schouten2010-02-091-2/+1
| | | | | | | | | 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. Notes: svn path=/head/; revision=203723
* ANSIfy almost all applications that use WARNS=6.Ed Schouten2009-12-291-1/+1
| | | | | | | | | | 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. Notes: svn path=/head/; revision=201227
* Add NFSv4 ACL support to find(1).Edward Tomasz Napierala2009-09-041-25/+35
| | | | | | | Reviewed by: rwatson Notes: svn path=/head/; revision=196839
* rm, find -delete: fix removing symlinks with uchg/uappnd set.Jilles Tjoelker2009-05-301-1/+1
| | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=193087
* find: do not silently disable -L when -delete is usedAndriy Gapon2009-05-191-5/+5
| | | | | | | | | | | | | | | | | | | | | 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) Notes: svn path=/head/; revision=192381
* The matching in -lname and -ilname are on the contents of the linkWarner Losh2008-02-241-5/+10
| | | | | | | | | | | 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@ Notes: svn path=/head/; revision=176497
* Implement a number of primaries present in GNU find, but not presentWarner Losh2008-02-231-3/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=176478
* Add the capability for a trailing scale indicator to cause theKirill Ponomarev2006-05-271-3/+35
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=158986
* Enable numeric arguments and +/- prefixes with -user (-group)Kirill Ponomarev2006-05-251-4/+12
| | | | | | | | | | | options. PR: bin/71513 Submitted by: Andre Albsmeier <Andre.Albsmeier@siemens.com> MFC after: 7 days Notes: svn path=/head/; revision=158919
* The last execution of -exec {} + is not done if the -exec primary isKirill Ponomarev2006-05-141-0/+17
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=158572
* Add -Btime, -Bnewer, -Bmin, -newerB[Bacmt], -newer[acmt]B options toCeri Davies2006-04-031-4/+13
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=157440
* Fixes for gcc4.x.Ollivier Robert2005-08-251-1/+1
| | | | | | | | Submitted by: Divacky Roman <xdivac02@stud.fit.vutbr.cz> PR: bin/84991 Notes: svn path=/head/; revision=149453
* - Make find(1) WARNS?= 6 cleanSuleiman Souhlal2005-01-251-2/+2
| | | | | | | | | - Bump to WARNS?= 6 Approved by: stefanf, grehan (mentor) Notes: svn path=/head/; revision=140810
* Change the 'no terminating ";"' error message to 'no terminating ";" or "+"'Tim J. Robbins2004-07-291-1/+1
| | | | | | | since + is also a valid way to terminate -exec. Notes: svn path=/head/; revision=132815
* Remove partial support for building this on NetBSD.Tim J. Robbins2004-07-291-2/+0
| | | | Notes: svn path=/head/; revision=132814
* - introduce a new primary `-depth n', which tests whetherOliver Eikemeier2004-05-281-7/+47
| | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=129812
* Give find(1) the option -acl to locate files with extendedBosko Milekic2004-04-031-0/+51
| | | | | | | | | | | | | | 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> Notes: svn path=/head/; revision=127796
* Fix all WARNS. Checked with "make WARNS=9". Remove unused file.Mark Murray2003-06-141-190/+62
| | | | Notes: svn path=/head/; revision=116333
* - Introduce a new struct xvfsconf, the userland version of struct vfsconf.Maxime Henrion2002-08-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | - 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. Notes: svn path=/head/; revision=101651
* Account for space used by environment variables in a similar way toTim J. Robbins2002-07-131-8/+12
| | | | | | | xargs(1) when handling -exec ... {} + constructions. Notes: svn path=/head/; revision=99905
* Support the SysV-style -exec utility args.. {} + function, required byTim J. Robbins2002-06-021-8/+69
| | | | | | | SUSv3. This is similar to find foo -print0 | xargs -0 utility args. Notes: svn path=/head/; revision=97736
* Clean up malloc(3)'s argument. Remove casts which do nothing when we'reJuli Mallett2002-05-171-9/+9
| | | | | | | | | | 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). Notes: svn path=/head/; revision=96785
* More consistancy. file system > filesystemTom Rhodes2002-05-161-1/+1
| | | | Notes: svn path=/head/; revision=96704