Commit Graph

152 Commits

Author SHA1 Message Date
James Youngman
419e5eff64 Coding style fixes: space after function names.
* lib/buildcmd.c: Insert a space between function name and open
parenthesis.
* lib/dircallback.c: Likewise.
* lib/extendbuf.c: Likewise.
* lib/fdleak.c: Likewise.
* lib/findutils-version.c: Likewise.
* lib/forcefindlib.c: Likewise.
* lib/listfile.c: Likewise.
* lib/printquoted.c: Likewise.
* lib/qmark.c: Likewise.
* lib/regexprops.c: Likewise.
* lib/regextype.c: Likewise.
* lib/savedirinfo.c: Likewise.

Signed-off-by: James Youngman <jay@gnu.org>
2010-04-01 00:06:23 +01:00
James Youngman
4968d14544 Support O_CREAT in open_cloexec.
* lib/fdleak.c: Include <stdarg.h> and "cloexec.h".
(open_cloexec): Support O_CREAT.  Use O_CLOEXEC if it is available.
(O_CLOEXEC): #define to 0 if not already #defined.
* import-gnulib.config (modules): Import modules open (for
PROMOTED_MODE_T) and stdbool (for 'true').
* lib/fdleak.h: Update prototype of open_cloexec to allow mode to
be passed.

Signed-off-by: James Youngman <jay@gnu.org>
2010-03-30 20:34:40 +01:00
James Youngman
fc181262f8 Apply bugfixes and suggestions from Eric's comments.
* configure.ac: Check for <sys/resource.h> and the getrusage
function.
* lib/fdleak.c: Don't #include <sys/resource.h> if we don't have it.
(get_max_fd): If neither /proc/self/fd not getrusage is available,
return _POSIX_OPEN_MAX.
(remember_non_cloexec_fds): Also check for leaks in file
descriptors 0, 1, 2, just in case the caller closed them.
(find_first_leaked_fd): Likewise.
(open_cloexec): Make sure we are not creating a file (for some odd
system where O_CREAT is 0).

Signed-off-by: James Youngman <jay@gnu.org>
2010-03-30 20:34:40 +01:00
James Youngman
4845d6a414 Turn the leak checker on by setting GNU_FINDUTILS_FD_LEAK_CHECK. 2010-03-30 00:51:21 +01:00
James Youngman
6c6a72bb00 Fix file descriptor leaks.
* import-gnulib.config (gnulib_version): Update to more recent
version of gnulib.  Import the cloexec module too.
* lib/fdleak.c: New file; a module for detecting file descriptor
leaks.   Also define an open_cloexec() function.
* lib/fdleak.h: Declare the global functions defined in fdleak.c.
* lib/Makefile.am (libfind_a_SOURCES): Add fdleak.c and fdleak.h.
* find/find.c (main): Call remember_non_cloexec_fds in order to
detect file descriptor leaks.
(main): set FD_CLOEXEC on starting_desc.
(safely_chdir_lstat): Likewise for dotfd.
(safely_chdir_nofollow): Likewise for fd.
* find/ftsfind.c (inside_dir): set FD_CLOEXEC on curr_fd.
(main): Call remember_non_cloexec_fds in order to detect file
descriptor leaks.
(main): set FD_CLOEXEC on starting_desc.
* find/pred.c (launch): before we exec the child, call
complain_about_leaky_fds in order to complain about non-FD_CLOEXEC
file descriptors that weren't open when the program was run.
* find/sharefile.c (sharefile_fopen): Set FD_CLOEXEC on the files
we open.
* gnulib-local/lib/save-cwd.c.diff: Patch gnulib to set FD_CLOEXEC
on the file descriptors opened by save_cwd.
* gnulib-local/modules/save-cwd.diff: Hence the save-cwd module
depends on the cloexec module.
* import-gnulib.sh (run_gnulib_tool): Pass the --local-dir option
in order to apply these patches.

Signed-off-by: James Youngman <jay@gnu.org>
2010-03-30 00:51:00 +01:00
James Youngman
265a49c66d Fix Savannah bug#27328, segfault if the initial exec for "find -exec" fails, and Savannah bug #27975: Infinite loop for -exec [..] {} +.
2009-11-29  James Youngman  <jay@gnu.org>

	Fix Savannah bug#27328, segfault if the initial exec for "find
	-exec" fails.  Also bug #27975: Infinite loop for -exec [..] {} +.
	* lib/buildcmd.h (struct buildcmd_state): Introduce
	largest_successful_arg_count and smallest_failed_arg_count in
	order to avoid an assumption that we understand how the operatingn
	system interprets ARG_MAX and the assumption that the compile-time
	ARG_MAX value (or the equivalent from sysconf()) is avtually
	correct.
	(struct buildcmd_control): Change the calling convention of the
	exec callback to allow us to pass the argument list separately.
	(bc_args_exceed_testing_limit): declare this new funciton.
	* lib/buildcmd.c (bc_args_complete): New function, NULL-terminates
 	the argv list.   We use this instead of passing NULL to
	bc_push_arg().
	(update_limit): New function.  Decides how many arguments to
	pass to the invoked command on the next attempt.
	(copy_args): Build an argument list containing all the initial
	arguments plus some of the other args (the number to be used is
	decided by update_limit).
	(bc_do_exec): Avoid special-casing the first call to exec.  Use
	update_limit to decide how many arguments to pass and copy_args to
	build the argument list.  The new form of the loop should fix
	Savannah bug #27328.
	(bc_push_arg): Drop support for passing NULL as an argument (to
	terminate the arg list we just pass in a special argument instead).
	(bc_args_exceed_testing_limit): New function, returns nonzero if
	the argument list exceeds a testing limit (used for failure
	injection by tests).
	(exceeds): New support function, implementing part of
	bc_args_exceed_testing_limit.
	(bc_init_state): Initialise largest_successful_arg_count and
	smallest_failed_arg_count.
	* find/defs.h (struct exec_val): New member last_child_status.
	This stores the status of the most recently completed child.
	* find/pred.c (new_impl_pred_exec): Use last_child_status.
	(launch): Use the new calling convention for the exec callback.
	Set last_child_status.  Call bc_args_exceed_testing_limit() to do
	failure injection for unit tests.
	* find/util.c (do_complete_pending_execdirs): Call bc_do_exec
	rather than calling launch directly in order to allow for breaking
	the argument list up if it's too long.
	* xargs/xargs.c (xargs_do_exec): Update to use the new caling
	convention for the exec callback.

Signed-off-by: James Youngman <jay@gnu.org>
2009-11-29 16:52:01 +00:00
James Youngman
5a8d448792 lib/check-regexprops.sh portability fixes for FreeBSD.
* lib/check-regexprops.sh: Portability fixes for FreeBSD (mktemp
requires an argument, dialect differences in sed regexes).

Signed-off-by: James Youngman <jay@gnu.org>
2009-08-16 16:16:15 +01:00
James Youngman
7d2abda8d4 Move regexprops.texi into git and check the autogenerated version is the same.
* lib/check-regexprops.sh: New test.  Run regexprops as a check,
and compare its output against the contents of doc/regexprops.texi.
If there is a mismatch for regexprops.texi, save the correct version.
* lib/Makefile.am: Run check-regexprops.sh for 'make check'.
* doc/Makefile.am: don't clean regexprops.texi, and don't generate
it automatically.
* doc/regexprops.texi: add into source control.
it automatically.
* doc/.gitignore: don't ignore regexprops.texi
2009-07-05 14:26:22 +01:00
James Youngman
4536a852d4 Remove trailing white space. 2009-04-13 13:33:24 +01:00
James Youngman
2d409557eb Avoid mixing declarations and statements.
* lib/buildcmd.c (bc_do_exec): Declare variables at the top of the
relevant block, in order to avoid mixing declarations and
statements.
* xargs/xargs.c (main): Likewise.

* NEWS: Mention the fix for bug #22708 in the correct section.
2009-04-13 13:10:54 +01:00
Leslie P. Polzer
4a3aa315e6 Merge Leslie Polzer's SOC 2007 changes for better ARG_MAX support
2008-03-23  Leslie Polzer  <leslie.polzer@gmx.net>

	Merge Leslie Polzer's ARG_MAX enhancements to xargs which were
	produced as part of the Google Summer of Code 2007.
	These changes fix Savannah bug #22708.
	* find/pred.c (launch): The struct buildcmd_control* argument is
	no longer const.
	* find/defs.h: Likewise
	* lib/buildcmd.c (bc_do_insert): The struct buildcmd_control*
	argument is no longer const.
	(bc_push_arg): Likewise.
	(cb_exec_noop): Likewise.
	(get_stringv_len): New function; measures the length of
	a NULL-terminated argv sequence.
	(bc_do_exec): Rename from do_exec, and make global.  Modify the
	function to react to exec failing with E2BIG by trying again
	with fewer arguments.
	* xargs/xargs.1: Mention that xargs automatically adopts to the
	situation where exec fails with E2BIG.
	* xargs/xargs.c: (parent): New variable, the PID of the parent
	process.
	(main): initialise the variable 'parent'.   Don't fail immediately
	due to lack of space when the environment is large.  Call
	xargs_do_exec via bc_do_exec.
	(xargs_do_exec): The struct buildcmd_control* argument is no
	longer const.   When exec fails in the child, communicate the
	errno value back to the parent through a pipe which is
	close-on-exec; this allows us to accurately determine the cause of
	the failure and also to distinguish exec failures from all
	possible exit codes in the child.
	(wait_for_proc): If the utility cannot be found or cannot be run,
	we now find out about this by reading an errno value from the
	pipe, so this means that exit codes 126 and 127 in the child no
	longer have a special interpretation.
	* NEWS: mention these changes.
2009-04-13 13:10:53 +01:00
James Youngman
9c94cc62e3 Remove unnecessary include guards.
Remove "lib/wait.h", since gnulib provides <sys/wait.h>.
* lib/Makefile.am (EXTRA_DIST): Remove wait.h, since gnulib
provides it.
* lib/wait.h: Not needed.
* find/pred.c: Include <sys/wait.h> instead of "wait.h".
* lib/waitpid.c: Likewise.
* xargs/xargs.c: Likewise.

Remove unnecessary include guards.
* lib/dircallback.c: gnulib provides <locale.h>, so no need for
include guards.
* locate/locate.c: Likewise.
* lib/listfile.c: Likewise.
* lib/savedirinfo.c: Likewise with <sys/stat.h>
* find/defs.h: gnulib provides <inttypes.h>, so no need for
include guards.
* lib/nextelem.c: Likewise with <string.h> and <stdlib.h>.
* locate/bigram.c: Likewise.
* locate/frcode.c: Likewise.
* lib/buildcmd.c: Likewise with <locale.h> and <wchar.h>
* xargs/xargs.c: Likewise with <locale.h>, <wchar.h> and <stdlib.h>
* import-gnulib.config (modules): Import the mbrtowc and whchar
modules.
* lib/qmark.c (multibyte_qmark_chars):  Don't surround with
HAVE_MBRTOWC, since we now have a replacement for mbrtowc.
Likewise, don't protect inclusion of <string.h> with
HAVE_STRING_H.  Likewise with <wchar.h>.
(multibyte_qmark_chars): Rename to qmark_chars.
(qmark_chars): Remove old version (since it is replaced by the
function that used to be multibyte_qmark_chars).
* lib/printquoted.c: Don't include <wchar.h>, we don't need it.

Signed-off-by: James Youngman <jay@gnu.org>
2009-04-12 11:26:52 +01:00
James Youngman
6ba6fbaa96 Enabled GCC warnings for declarations after statements.
Enabled GCC warnings for declarations after statements.
* import-gnulib.config: Import the gnulib module 'warnings'
* configure.ac: Add GCC warning -Wdeclaration-after-statement.
* Makefile.am: Add AM_CFLAGS and set it to $(WARN_CFLAGS).
* find/Makefile.am, doc/Makefile.am, lib/Makefile.am: Likewise.
* locate/Makefile.am, xargs/Makefile.am: Likewise.

Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 11:07:50 +00:00
James Youngman
5dce9f443c Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.

Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
James Youngman
bece71c9b0 Update gnulib version; follow gnulib-tool's Makefile.am edit suggestions.
Update gnulib version.
* import-gnulib.config (gpl3_update_files): No longer need to
update the licenses of build-aux/mdate-sh, build-aux/texinfo.tex
or build-aux/ylwrap as they are already GPLv3+.
(modules): Use the strdup-posix module instead of strdup, and stop
using the obsolete modules memcmp and memset, since we now assume
those functions will already be present on the host system.
* import-gnulib.sh (rehack): Be more verbose about which files
actually needed a license edit and which did not.

Follow gnulib-tool's Makefile.am edit suggestions.
* find/Makefile.am (LDADD): Use $(LIBINTL) instead of @INTLLIBS@
and use $(LIB_CLOCK_GETTIME) instead of @LIB_CLOCK_GETTIME@.
* lib/Makefile.am: Likewise.
* locate/Makefile.am: Likewise.
* xargs/Makefile.am: Likewise.
* import-gnulib.sh (hack_gnulib_tool_output): Add
m4/gnulib-cache.m4 to EXTRA_DIST in gnulib/Makefile.am, as
gnulib-tool suggests.
2009-02-21 14:55:56 +00:00
Jim Meyering
10a9219ff2 find: avoid warning about unused local, remove unnecessary include.
* find/pred.c (scan_for_digit_differences): Remove declaration of
unused local, "ok".
(do_time_format): Remove decl of "done"; replace sole use with a
constant, "true".  Initialize "i" and "n".
* lib/dircallback.c: Don't include unistd.h.  Not needed.
2009-02-21 13:36:49 +00:00
James Youngman
e2b1bc2ac9 Update version of gnulib in order to pull in Jim Meyering's performance imporvements to fts 2008-11-08 14:26:32 +00:00
James Youngman
447dee1b43 Applied patch from Jim Meyering; rename dirfd to dir_fd to avoid shadowing problem 2008-03-10 09:39:29 +00:00
James Youngman
b99109f921 Applied tiny change from Ralf Wildenhues and updated the gnulib version 2008-02-13 23:52:04 +00:00
James Youngman
4af5f5eed5 Backed out the positional parameter change because it was too error prone and over-complex 2007-12-20 21:53:55 +00:00
James Youngman
f7dc6a9f0b Enhancements to format strings in hman-readable messages intended to allow better translation 2007-12-19 21:16:33 +00:00
James Youngman
f183ab2db9 Support the generation of regexprops-generic.texi. 2007-11-29 11:17:14 +00:00
Eric Blake
dc16c62ec4 Update to recent gnulib addition of idcache.h.
* lib/listfile.c (getuser, getgroup): Use header rather than
declaring things ourself.
* po/POTFILES.in (locate/frcode.c): Add missing file.
2007-08-23 02:33:31 +00:00
Eric Blake
578ead6ff1 Fix Savannah bug #20751.
* lib/listfile.c (list_file): Accomodate gnulib change of 3 Jul
2006.
* NEWS: Document this.
Reported by Nigel Stepp.
* THANKS: Sort and update.
* AUTHORS: Add myself.
2007-08-19 15:31:38 +00:00
Eric Blake
756cecd45b Allow choice of default arg size, Savannah bug #20594.
* configure.ac (DEFAULT_ARG_SIZE): Check environment for a default
size override.
* lib/buildcmd.c (bc_use_sensible_arg_max): Use default size from
configure, if requested.
* README (DEFAULT_ARG_SIZE): Mention the ability to tune this at
configure time.
* NEWS: Document the change.
2007-08-01 03:39:57 +00:00
James Youngman
1bd53425e8 Fixed Savannah bug #20547, version information not compliant with GNU coding standard 2007-07-22 13:08:22 +00:00
James Youngman
1c43fc92b5 Migrated from GPL version 2 to GPL version 3 2007-07-02 08:25:45 +00:00
James Youngman
f7671dc609 Fix Savannah bug #20263 (compilation err on DEC OSF/1. Include <sys/stat.h> in files where where we use struct stat. Removed some dead code following some calls to assert(0), which are now backed up by abort calls. Use assert (0) rather than assert (false). Make sure we include the space. 2007-06-26 08:24:19 +00:00
James Youngman
6e06a9fc28 Ignore the usually-ignored files in git 2007-06-24 16:47:40 +00:00
James Youngman
5a7e83f1d7 Fixed various lint complaints pointed out by build-aux/src-sniff.py 2007-06-21 23:41:08 +00:00
James Youngman
992bf3fd7e Applied patch for Savannah bug #20210 by Eric Blake 2007-06-19 22:28:03 +00:00
James Youngman
c47b198b43 Added some extra information about more obscure file types. 2007-05-27 10:34:03 +00:00
James Youngman
a0ab43812d Correctly detect and diagnose I/O errors in print-related predicates. This fixed Savannah bug #19416 2007-05-06 12:35:07 +00:00
James Youngman
dc4a7adf94 Bugfixes for Savannah bugs #19768 and #19766 2007-05-01 09:46:30 +00:00
James Youngman
cd1f15947f Use const char* parameters for pathnames 2007-04-29 23:28:50 +00:00
James Youngman
20102fc931 Minor changes relating to conditional includes that no longer need the conditional, and fixing some out of date comments 2007-04-29 01:27:56 +00:00
James Youngman
5f288d46f4 Avoid calling stat for pred_delete. Instead, try the unlink assuming the target is a file and then try again with the AT_REMOVEDIR flag if errno gets set to EISDIR 2007-04-28 17:51:14 +00:00
James Youngman
3d2128d30c Simplifythe calculation of the defautl value of xargs's -s option. Avoid an assertion failure on AIX when _SC_ARG_MAX is larger than LINE_MAX 2007-04-28 14:27:40 +00:00
James Youngman
52360fa978 Call gnulib's mbsstr() instead of a locally-defined mbsstr() 2007-04-25 09:26:10 +00:00
James Youngman
455a3be584 Added SOC guidance comments 2007-04-24 22:08:36 +00:00
James Youngman
d86012a34d Removed unused code. 2007-04-23 09:19:21 +00:00
James Youngman
e6adb9061f Fixes to ensure that 'make distcheck' works 2007-04-15 14:46:39 +00:00
James Youngman
b46b0d8938 Support fts() in FTS_CWDFD mode. Also work around Savannah bug #18466 (with a performance penalty). 2007-04-14 21:41:59 +00:00
James Youngman
70f1a3d1ea New method of checking out and configuring gnulib - define which version we need to use, and remember which version we used 2007-02-28 23:55:47 +00:00
James Youngman
c7ca8e10f2 Eliminated a few compiler warnings 2007-02-25 12:05:51 +00:00
James Youngman
cdf4370ad4 Applied trivial patch from supriya kannery <supriyak@in.ibm.com> which fixes a memory leak. 2007-02-24 10:01:54 +00:00
James Youngman
f198887c2e Fixed typo 2007-01-22 10:34:02 +00:00
James Youngman
c3cdc1bec8 define find_blocksize() and provide a declaration for get_link_name() 2006-12-29 19:32:10 +00:00
James Youngman
77c2709e77 Work around Savannah bug #17877, which manifests on systems which use
the same inode number for more than one file (smbfs, FAT, sometimes
some FUSE-based ones).  This happens for unreferenced files.  Fix
suggested by Jim Meyering.
2006-11-20 22:32:08 +00:00
James Youngman
7bdf3f39e5 Fixed Svannah bug #17782 ('./' prefix added at start of arg while it should be added at the start of the expansion of {}) 2006-11-08 07:11:43 +00:00