* import-gnulib.config (modules): Add c-casestr, errno, fdopendir,
fflush, getdelim, gettimeofday, locale, modf, perror, snprintf,
stat, stdarg, stddef, stdio, stdlib, string, strpbrk, sys_time,
sys_wait.
Also add comments about other modules we may also want to use
which would require other code changes (for example dirent-safer).
* find/Makefile.am (LDADD): Add $(LIB_EACCESS) $(LIB_SELINUX)
$(MODF_LIBM) which are needed by gnulib modules we now depend on.
Signed-off-by: James Youngman <jay@gnu.org>
* find/parser.c (estimate_fstype_success_rate): Change the name of
the variable "dir" to "the_root_dir" to emphasise that it doesn't
matter that we're calling stat rather than options.xstat.
* find/ftsfind.c (symlink_loop): Call options.xstat instead of
stat/lstat, because options.xstat takes account of
state.cwd_dir_fd.
Signed-off-by: James Youngman <jay@gnu.org>
* find/pred.c (do_fprintf): Use optionl_stat and optionp_stat
instead of stat and lstat, because the first two functions are
aware of state.cwd_dir_fd.
* find/testsuite/find.gnu/printf-nonlocal-symlink.exp: A new test
case for this bug.
* find/testsuite/find.gnu/printf-nonlocal-symlink.xo: Expected
output for this test.
* find/testsuite/Makefile.am (EXTRA_DIST_EXP): Add the new test
case.
(EXTRA_DIST_XO): Add the expected-output file.
Signed-off-by: James Youngman <jay@gnu.org>
* doc/find-maint.texi: Update the maintenance manual to take into
account the fact that we uniformly use git rather than CVS. Point
out the new version tag format. Mention "make coverage".
README-CVS is now called README-hacking. Update the URL for the
Translation Project.
Signed-off-by: James Youngman <jay@gnu.org>
* lib/extendbuf.c (xextendbuf): New function; extends the buffer,
but calls xalloc_die on failure. On the the other hand, extendbuf
returns NULL on failure.
(decide_size): If wanted>SIZE_MAX/2, return wanted. This means
that for very large buffers, performance on repeated extension
degrades from linear to quadratic (instead of just failing at that
point, as before).
* lib/savedirinfo.c (xsavedir): Use xextendbuf rather than
extendbuf, now that there is a difference in semantics.
* find/fstype.c (get_mounted_filesystems): If extendbuf returns
NULL, fail (by returning NULL ourselves).
(get_mounted_devices): Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
* lib/regexprops.c: Include "progname.h". Update function
defintions to have a newline before the function name (to comply
with the GNU coding standard). Use set_program_name.
* find/defs.h (struct state): Correct type of
already_issued_stat_error_msg from boolean to bool.
* find/util.c (report_file_err): Likewise with parameter
is_target_file.
* find/pred.c: Include "areadlink.h".
(do_fprintf): nonfatal_file_error should be
nonfatal_target_file_error.
(match_lname): Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
* lib/listfile.c: #include "areadlink.h" but not "dircallback.h",
since we no longer need to use get_link_name_at.
(get_link_name_at): Delete.
(get_link_name_cb): Delete.
(get_link_name): Delete.
* lib/listfile.h: Remove declaration of get_link_name_at.
* find/pred.c (match_lname): Use areadlinkat instead of
get_link_name_at.
Signed-off-by: James Youngman <jay@gnu.org>
* find/defs.h (struct state): New member,
already_issued_stat_error_msg, used to de-duplicate error
messages. If it is true, we already issued an error message for
the current target file.
Declare fatal_target_file_error, fatal_nontarget_file_error,
nonfatal_target_file_error, nonfatal_nontarget_file_error.
Between them, they replace fatal_file_error and
nonfatal_file_error. The *target_file_error versions are
de-duplicated and the nontarget_file_error_versions are not.
* find/util.c (nonfatal_nontarget_file_error): Implement.
(fatal_nontarget_file_error): Implement.
(nonfatal_target_file_error): Implement.
(fatal_target_file_error): Implement.
(fatal_file_error): Remove.
(nonfatal_file_error): Remove.
(error_severity): Define error_severity (moved from ftsfind.c)
(get_statinfo): Call nonfatal_target_file_error in order to avoid
a duplicate message. ALso call error_severity after a different
call to error to preserve the constraint that we exit with a
nonzero status if we issue a diagnostic.
(cleanup): Call nonfatal_nontarget_file_error instead of
nonfatal_file_error.
* find/ftsfind.c (error_severity): Move to util.c.
* find/tree.c (build_expression_tree): Initialise
state.already_issued_stat_error_msg.
* find/find.c (main): Initialise state.already_issued_stat_error_msg.
(wd_sanity_check): Call fatal_target_file_error instead of
fatal_file_error.
(chdir_back): Call fatal_nontarget_file_error instead of
fatal_file_error.
(process_path): Initialise state.already_issued_stat_error_msg.
* find/ftsfind.c (consider_visiting): Call
nonfatal_target_file_error instead of calling error directly.
(find): Call error_severity to ensure exit status is nonzero after
a call to error.
(main): Initialise state.already_issued_stat_error_msg.
* find/parser.c (collect_arg_stat_info): Call
fatal_target_file_error instead of fatal_file_error.
(parse_newerXY): Likewise.
(parse_samefile): Likewise.
(parse_samefile): Likewise.
(open_output_file): Call fatal_nontarget_file_error instead of
fatal_file_error.
* find/pred.c (checked_fprintf): Likewise.
(checked_print_quoted): Likewise.
(checked_fwrite): Likewise.
(checked_fflush): Likewise.
* find/sharefile.c (entry_free): Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
Addresses Savannah bug #27213 - https://savannah.gnu.org/bugs/?27213
This used to fail in recent releases:
1. mkdir -p foo/bar
2. chmod a-x foo
3. find foo
4. find foo -ls
Now it will print error messages for the denied permission on foo, but will
not abort completely, and in 3. will even print the name foo/bar, while it
won't do so in 4., as the -ls predicate requires stat information. For now,
4. will print two identical error message. This should get fixed some day.
* import-gnulib.config (modules): Use the getopt-gnu module from
gnulib rather than the (obsolete) getopt module.
Signed-off-by: James Youngman <jay@gnu.org>
* find/defs.h: Don't create typedef "boolean"; use the standard
type bool. Update other declarations accordingly.
* find/find.c: Update declarations and function definitions to use
bool.
* find/ftsfind.c: Likewise.
* find/parser.c: Likewise.
* find/pred.c: Likewise.
* find/tree.c: Likewise.
* find/util.c: Likewise.
* locate/locate.c: Likewise.
* xargs/xargs.c: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
Fix open_cloexec on hosts which ignore O_CLOEXEC (i.e. old kernels).
* lib/fdleak.c (o_cloexec_works): New function, detects whether
the open flag O_CLOEXEC has any effect.
(open_cloexec): Call o_cloexec_works, just once, to find out
whether O_CLOEXEC is effective. If not, set the close-on-exec
flag on fds by calling set_cloexec_flag.
Signed-off-by: James Youngman <jay@gnu.org>
Signed-off-by: James Youngman <jay@gnu.org>
* find/testsuite/config/unix.exp (optimisation_levels_to_test):
New function, decides which optimisation levels we shuld run find
at for the current test. Set $OPTIMISATION_LEVELS to control
this.
(find_start): Call optimisation_levels_to_test to determine which
optimisation levels to run find at.
* find/testsuite/find.posix/exec-nogaps.exp: Run the test only at
-O3 (but for both oldfind and ftsfind).
Signed-off-by: James Youngman <jay@gnu.org>
* lib/fdleak.h: Correct the format of the copyright statement.
* po/vi.po: Likewise.
* lib/safe-atoi.h: Likewise.
* locate/locate.c: Likewise.
* po/ca.po: Likewise.
* po/gl.po: Likewise.
* po/fi.po: Likewise.
* po/it.po: Likewise.
* po/findutils.pot: Fill in the boilerplate in the header.
Signed-off-by: James Youngman <jay@gnu.org>
* import-gnulib.config (maintainer_modules): Separate out the
modules primarily useful for maintainer activities. Add
'update-copyright' to this.
* build-aux/.cvsignore: Ignore update-copyright, since it's
installed by gnulib.
* build-aux/.gitignore: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
* cfg.mk: Append the names of checks to skip to
local-checks-to-skip rather than inventing 7 new variables.
Signed-off-by: James Youngman <jay@gnu.org>
Avoid using magic numbers as exit statuses.
* cfg.mk (skip_defer): Enable sc_prohibit_magic_number_exit.
* doc/find-maint.texi (Security): Avoid error (1, ...) in the
example patch.
* find/find.c (main): Use exit status EXIT_FAILURE instead of 1.
(wd_sanity_check): Likewise.
(safely_chdir_lstat): Likewise.
(process_dir): Likewise.
* find/fstype.c (must_read_fs_list): Likewise.
* find/ftsfind.c (main): Likewise.
(main): Likewise.
* find/parser.c (check_option_combinations): Use exit status
EXIT_FAILURE instead of 1.
(parse_group): Likewise.
(parse_help): Use exit status EXIT_SUCCESS instead of 0.
(parse_version): Likewise.
(fnmatch_sanitycheck): Use exit status EXIT_FAILURE instead of 1.
(insert_depthspec): Likewise.
(parse_newerXY): Likewise.
(non_posix_mode): Likewise.
(parse_perm): Likewise.
(insert_regex): Likewise.
(parse_size): Likewise.
(parse_show_control_chars): Likewise.
(parse_used): Likewise.
(parse_user): Likewise.
(parse_context): Likewise.
(insert_type): Likewise.
(insert_fprintf): Likewise.
(make_segment): Likewise.
(check_path_safety): Likewise.
(new_insert_exec_ok): Likewise.
(get_relative_timestamp): Likewise.
(parse_time): Likewise.
* find/tree.c (get_expr): Use exit status EXIT_FAILURE instead of 1.
(scan_rest): Likewise.
(get_pred_cost): Likewise.
(get_pred_cost): Likewise.
(build_expression_tree): Likewise.
(get_new_pred_chk_op): Likewise.
* find/pred.c (launch): Use exit status EXIT_FAILURE instead of 1.
* find/util.c (process_debug_options): Use exit status
EXIT_SUCCESS instead of 0.
(process_optimisation_option): Use exit status EXIT_FAILURE
instead of 1.
(set_option_defaults): Likewise.
* lib/buildcmd.c (exceeds): Likewise.
(bc_do_exec): Likewise.
(bc_push_arg): Likewise.
* lib/nextelem.c: Remove test code.
* lib/safe-atoi.c (safe_atoi): Use exit status EXIT_FAILURE
instead of 1.
* lib/regextype.c (get_regex_type): Use exit status EXIT_FAILURE
instead of 1. Include <stdlib.h>, for EXIT_FAILURE.
* locate/locate.c (set_max_db_age): Use exit status EXIT_FAILURE
instead of 1.
(set_max_db_age): Likewise.
(toolong): Likewise.
(visit_locate02_format): Likewise.
(search_one_database): Likewise.
(drop_privs): Likewise.
* locate/frcode.c (get_seclevel): Use exit status EXIT_FAILURE
instead of 1.
(outerr): Likewise.
(main): Likewise.
* locate/code.c (inerr): Use exit status EXIT_FAILURE instead of
1.
(outerr): Likewise.
* locate/word_io.c (getword): Use exit status EXIT_FAILURE instead of 1.
Use named constants for xargs exit codes.
* xargs/xargs.c (child_error): Use EXIT_SUCCESS instead of 0.
(enum XargsStatusValues): introduce named constants for the
various things that cause speicific exit codes.
(enum ClientStatusValues): Also introduce named constants for the
child's exit status.
(get_char_oct_or_hex_escape): Use EXIT_FAILURE instead of 1.
(get_input_delimiter): Likewise.
(main): Likewise.
(read_line): Likewise.
(read_string): Likewise.
(print_args): Likewise.
(xargs_do_exec): Likewise.
(wait_for_proc): Likewise.
(wait_for_proc): Use enum XargsStatusValues for exit codes.
(parse_num): Use EXIT_FAILURE instead of 1.
Signed-off-by: James Youngman <jay@gnu.org>
* lib/fdleak.c (get_proc_max_fd): Use safe_atoi to do string to
int conversion, instead of sscanf. Skip '.' and '..'.
* find/util.c (set_option_defaults): Avoid false positive with
sc_prohibit_atoi_atof.
(check_nofollow): Likewise.
* cfg.mk (skip_defer): Enable the sc_prohibit_atoi_atof check.
Signed-off-by: James Youngman <jay@gnu.org>
* po/POTFILES.in: Remove dircallback.c, listfile.c.
* lib/listfile.c: Don't include libintl, since there are no
translated messages in this file.
* lib/dircallback.c: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
* find/parser.c: Include "safe-atoi.h". Remove the body of safe_atoi.
(parse_group): pass options.err_quoting_style to safe_atoi.
(insert_depthspec): Likewise.
(parse_user): Likewise.
* lib/safe-atoi.h: New file.
* lib/safe-atoi.c: New file. Add parameter for quoting style (to
avoid an external reference to the "options"struct).
* lib/Makefile.am (libfind_a_SOURCES): Add safe-atoi.c and
safe-atoi.h.
Signed-off-by: James Youngman <jay@gnu.org>
* doc/find.texi (Updating A Timestamp File): Work around a syntax
check designed to prevent the use of "test X -a Y".
* find/find.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
Eliminate some unused function result warnings.
* lib/unused-result.h: New file, defines function attribute macro
__attribute_warn_unused_result__.
* lib/Makefile.am (EXTRA_DIST): Add unused-result.h.
* find/ftsfind.c (find): Issue a diagnostic if fts_close fails,
change return type to bool and return false for this case. Add
__warn_unused_result__ attribute.
(process_all_startpoints): Likewise (except no need for second
diagnostic).
(main): If process_all_startpoints failed, don't do the cleanup
operations because we don't know what subdirectory we're in.
* find/util.c (fd_leak_check_is_enabled): Avoid implicit
pointer-to-int conversion.
* lib/buildcmd.c: #include <stdlib.h> for declaration of free.
Signed-off-by: James Youngman <jay@gnu.org>
syntax check right now, since the perm.texi file uses
@acronym{GNU} but we try to keep that in sync. with coreutils.
Signed-off-by: James Youngman <jay@gnu.org>