summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Voelker <mail@bernhard-voelker.de>2017-08-10 08:45:56 +0200
committerBernhard Voelker <mail@bernhard-voelker.de>2017-08-10 08:45:56 +0200
commit50a7c5d1f572d50d6c9d43d04e9c9fd55d66b466 (patch)
treee1d09fdf324069691951a44b41fe74e3a3caa61f
parent808d8aa612971a843432aee663a3c3fffd1a2df4 (diff)
downloadfindutils-50a7c5d1f572.tar.gz
find: avoid usage() in more error cases
When the user passes a bad command line, then find(1) outputs the error message followed by a short usage() text, e.g. (wrapped): $ find . -name a* b* find: paths must precede expression: bfile Usage: find [-H] [-L] [-P] [-Olevel] \ [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] Omit the usage() text in more cases like this in order to make the error diagnostic more eye-catching. * find/tree.c (build_expression_tree): Exit with EXIT_FAILURE immediately in more cases, i.e., without outputting also a short usage() text. While at it, add quotes around the offending argument in one another place. * NEWS (Improvements): Mention the fix. Reported in https://savannah.gnu.org/bugs/?51711
-rw-r--r--NEWS3
-rw-r--r--find/tree.c17
2 files changed, 8 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 2f263aa..61269c1 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ of the - yet more portable - '( -type l -o -type d )'.
find now diagnoses failures returned by readdir(). This bug was inherent
in the use of FTS.
+find now exits in more cases immediately after the error diagnostic, i.e.,
+without the following usage text, to make the former more eye-catching.
+
xargs now supports the -o, --open-tty option to reopen stdin as /dev/tty
in the child process before executing the command; useful to run an
interactive application. Added for compatibility with BSD.
diff --git a/find/tree.c b/find/tree.c
index 2bbfbe5..ee466ea 100644
--- a/find/tree.c
+++ b/find/tree.c
@@ -1275,18 +1275,14 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options)
{
state.already_issued_stat_error_msg = false;
if (!looks_like_expression (argv[i], false))
- {
- error (0, 0, _("paths must precede expression: %s"), argv[i]);
- usage (EXIT_FAILURE);
- }
+ error (EXIT_FAILURE, 0, _("paths must precede expression: `%s'"), argv[i]);
predicate_name = argv[i];
parse_entry = find_parser (predicate_name);
if (parse_entry == NULL)
{
/* Command line option not recognized */
- error (0, 0, _("unknown predicate `%s'"), predicate_name);
- usage (EXIT_FAILURE);
+ error (EXIT_FAILURE, 0, _("unknown predicate `%s'"), predicate_name);
}
/* We have recognised a test of the form -foo. Eat that,
@@ -1306,21 +1302,18 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options)
/* The special parse function spat out the
* predicate. It must be invalid, or not tasty.
*/
- error (0, 0, _("invalid predicate `%s'"), predicate_name);
- usage (EXIT_FAILURE);
+ error (EXIT_FAILURE, 0, _("invalid predicate `%s'"), predicate_name);
}
else
{
- error (0, 0, _("invalid argument `%s' to `%s'"),
+ error (EXIT_FAILURE, 0, _("invalid argument `%s' to `%s'"),
argv[i], predicate_name);
- usage (EXIT_FAILURE);
}
}
else
{
/* Command line option requires an argument */
- error (0, 0, _("missing argument to `%s'"), predicate_name);
- usage (EXIT_FAILURE);
+ error (EXIT_FAILURE, 0, _("missing argument to `%s'"), predicate_name);
}
}
else