[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Findutils-patches] [PATCH] Bug 21039: Turn off warnings in POSIXLY_CORR
From: |
James Youngman |
Subject: |
[Findutils-patches] [PATCH] Bug 21039: Turn off warnings in POSIXLY_CORRECT mode. |
Date: |
Sat, 17 Nov 2007 13:56:47 +0000 |
If the POSIXLY_CORRECT environment variable is set, turn off warnings.
Also give an error for some POSIX-incompatible uses of -perm.
All non-POSIX predicates remain on.
---
find/defs.h | 6 ++
find/find.c | 3 +
find/parser.c | 73 +++++++++++++++----------
find/testsuite/Makefile.am | 1 +
find/testsuite/find.gnu/posix-perminvalid.exp | 17 ++++++
find/util.c | 12 ++++-
6 files changed, 82 insertions(+), 30 deletions(-)
diff --git a/find/defs.h b/find/defs.h
index bf67687..d886fa2 100644
--- a/find/defs.h
+++ b/find/defs.h
@@ -558,6 +558,12 @@ struct options
*/
boolean warnings;
+ /* If true, avoid POSIX-incompatible behaviours
+ * (this functionality is currently incomplete
+ * and at the moment affects mainly warning messages).
+ */
+ boolean posixly_correct;
+
struct timespec start_time; /* Time at start of execution.
*/
/* Seconds between 00:00 1/1/70 and either one day before now
diff --git a/find/find.c b/find/find.c
index b1178fb..bc6f8e9 100644
--- a/find/find.c
+++ b/find/find.c
@@ -1088,6 +1088,9 @@ issue_loop_warning(const char *name, const char
*pathname, int level)
error(0, 0,
_("Symbolic link %s is part of a loop in the directory hierarchy;
we have already visited the directory to which it points."),
safely_quote_err_filename(0, pathname));
+ /* XXX: POSIX appears to require that the exit status be non-zero if a
+ * diagnostic is issued.
+ */
}
else
{
diff --git a/find/parser.c b/find/parser.c
index d46127f..18d26cc 100644
--- a/find/parser.c
+++ b/find/parser.c
@@ -239,23 +239,23 @@ static struct parser_table const parse_entry_newerXY =
static struct parser_table const parse_table[] =
{
- PARSE_PUNCTUATION("!", negate),
+ PARSE_PUNCTUATION("!", negate), /* POSIX */
PARSE_PUNCTUATION("not", negate), /* GNU */
- PARSE_PUNCTUATION("(", openparen),
- PARSE_PUNCTUATION(")", closeparen),
+ PARSE_PUNCTUATION("(", openparen), /* POSIX */
+ PARSE_PUNCTUATION(")", closeparen), /* POSIX */
PARSE_PUNCTUATION(",", comma), /* GNU */
- PARSE_PUNCTUATION("a", and),
+ PARSE_PUNCTUATION("a", and), /* POSIX */
PARSE_TEST ("amin", amin), /* GNU */
PARSE_PUNCTUATION("and", and), /* GNU */
PARSE_TEST ("anewer", anewer), /* GNU */
- {ARG_TEST, "atime", parse_time, pred_atime},
+ {ARG_TEST, "atime", parse_time, pred_atime}, /* POSIX
*/
PARSE_TEST ("cmin", cmin), /* GNU */
PARSE_TEST ("cnewer", cnewer), /* GNU */
- {ARG_TEST, "ctime", parse_time, pred_ctime},
+ {ARG_TEST, "ctime", parse_time, pred_ctime}, /* POSIX
*/
PARSE_POSOPT ("daystart", daystart), /* GNU */
PARSE_ACTION ("delete", delete), /* GNU, Mac OS, FreeBSD
*/
PARSE_OPTION ("d", d), /* Mac OS X, FreeBSD, NetBSD,
OpenBSD, but deprecated in favour of -depth */
- PARSE_OPTION ("depth", depth),
+ PARSE_OPTION ("depth", depth), /* POSIX */
PARSE_TEST ("empty", empty), /* GNU */
{ARG_ACTION, "exec", parse_exec, pred_exec}, /* POSIX */
{ARG_TEST, "executable", parse_accesscheck,
pred_executable}, /* GNU, 4.3.0+ */
@@ -267,7 +267,7 @@ static struct parser_table const parse_table[] =
{ARG_ACTION, "fprintf", parse_fprintf, pred_fprintf}, /* GNU */
PARSE_TEST ("fstype", fstype), /* GNU, Unix */
PARSE_TEST ("gid", gid), /* GNU */
- PARSE_TEST ("group", group),
+ PARSE_TEST ("group", group), /* POSIX */
PARSE_OPTION ("ignore_readdir_race", ignore_race), /* GNU */
PARSE_TEST ("ilname", ilname), /* GNU */
PARSE_TEST ("iname", iname), /* GNU */
@@ -275,35 +275,35 @@ static struct parser_table const parse_table[] =
PARSE_TEST ("ipath", ipath), /* GNU, deprecated in
favour of iwholename */
PARSE_TEST_NP ("iregex", iregex), /* GNU */
PARSE_TEST_NP ("iwholename", iwholename), /* GNU */
- PARSE_TEST ("links", links),
+ PARSE_TEST ("links", links), /* POSIX */
PARSE_TEST ("lname", lname), /* GNU */
PARSE_ACTION ("ls", ls), /* GNU, Unix */
PARSE_OPTION ("maxdepth", maxdepth), /* GNU */
PARSE_OPTION ("mindepth", mindepth), /* GNU */
PARSE_TEST ("mmin", mmin), /* GNU */
PARSE_OPTION ("mount", xdev), /* Unix */
- {ARG_TEST, "mtime", parse_time, pred_mtime},
+ {ARG_TEST, "mtime", parse_time, pred_mtime}, /* POSIX
*/
PARSE_TEST ("name", name),
#ifdef UNIMPLEMENTED_UNIX
PARSE(ARG_UNIMPLEMENTED, "ncpio", ncpio), /* Unix */
#endif
- PARSE_TEST ("newer", newer),
- {ARG_TEST, "atime", parse_time, pred_atime},
+ PARSE_TEST ("newer", newer), /* POSIX */
+ {ARG_TEST, "atime", parse_time, pred_atime}, /* POSIX
*/
PARSE_OPTION ("noleaf", noleaf), /* GNU */
- PARSE_TEST ("nogroup", nogroup),
- PARSE_TEST ("nouser", nouser),
+ PARSE_TEST ("nogroup", nogroup), /* POSIX */
+ PARSE_TEST ("nouser", nouser), /* POSIX */
PARSE_OPTION ("noignore_readdir_race", noignore_race), /* GNU */
PARSE_POSOPT ("nowarn", nowarn), /* GNU */
- PARSE_PUNCTUATION("o", or),
+ PARSE_PUNCTUATION("o", or), /* POSIX */
PARSE_PUNCTUATION("or", or), /* GNU */
- PARSE_ACTION ("ok", ok),
+ PARSE_ACTION ("ok", ok), /* POSIX */
PARSE_ACTION ("okdir", okdir), /* GNU (-execdir is BSD)
*/
PARSE_TEST ("path", path), /* GNU, HP-UX, RMS prefers
wholename, but anyway soon POSIX */
- PARSE_TEST ("perm", perm),
- PARSE_ACTION ("print", print),
+ PARSE_TEST ("perm", perm), /* POSIX */
+ PARSE_ACTION ("print", print), /* POSIX */
PARSE_ACTION ("print0", print0), /* GNU */
{ARG_ACTION, "printf", parse_printf, NULL}, /* GNU */
- PARSE_ACTION ("prune", prune),
+ PARSE_ACTION ("prune", prune), /* POSIX */
PARSE_ACTION ("quit", quit), /* GNU */
{ARG_TEST, "readable", parse_accesscheck, pred_readable},
/* GNU, 4.3.0+ */
PARSE_TEST ("regex", regex), /* GNU */
@@ -312,15 +312,15 @@ static struct parser_table const parse_table[] =
#if 0
PARSE_OPTION ("show-control-chars", show_control_chars), /* GNU,
4.3.0+ */
#endif
- PARSE_TEST ("size", size),
- PARSE_TEST ("type", type),
+ PARSE_TEST ("size", size), /* POSIX */
+ PARSE_TEST ("type", type), /* POSIX */
PARSE_TEST ("uid", uid), /* GNU */
PARSE_TEST ("used", used), /* GNU */
- PARSE_TEST ("user", user),
+ PARSE_TEST ("user", user), /* POSIX */
PARSE_OPTION ("warn", warn), /* GNU */
PARSE_TEST_NP ("wholename", wholename), /* GNU, replaced
-path, but anyway -path will soon be in POSIX */
{ARG_TEST, "writable", parse_accesscheck,
pred_writable}, /* GNU, 4.3.0+ */
- PARSE_OPTION ("xdev", xdev),
+ PARSE_OPTION ("xdev", xdev), /* POSIX */
PARSE_TEST ("xtype", xtype), /* GNU */
#ifdef UNIMPLEMENTED_UNIX
/* It's pretty ugly for find to know about archive formats.
@@ -1714,6 +1714,17 @@ parse_wholename (const struct parser_table* entry, char
**argv, int *arg_ptr)
return parse_path (entry, argv, arg_ptr);
}
+static void
+non_posix_mode(const char *mode)
+{
+ if (options.posixly_correct)
+ {
+ error (1, 0, _("Mode %s is not valid when POSIXLY_CORRECT is on."),
+ quotearg_n_style(0, options.err_quoting_style, mode));
+ }
+}
+
+
static boolean
parse_perm (const struct parser_table* entry, char **argv, int *arg_ptr)
{
@@ -1748,7 +1759,12 @@ parse_perm (const struct parser_table* entry, char
**argv, int *arg_ptr)
* it is incompatible with POSIX in some cases, but we
* still support uses of it that are not incompatible with
* POSIX.
+ *
+ * Example: POSIXLY_CORRECT=y find -perm +a+x
*/
+ non_posix_mode(perm_expr);
+
+ /* support the previous behaviour. */
mode_start = 1;
kind = PERM_ANY;
rate = 0.3;
@@ -1764,11 +1780,12 @@ parse_perm (const struct parser_table* entry, char
**argv, int *arg_ptr)
break;
case '/': /* GNU extension */
- mode_start = 1;
- kind = PERM_ANY;
- havekind = true;
- rate = 0.3;
- break;
+ non_posix_mode(perm_expr);
+ mode_start = 1;
+ kind = PERM_ANY;
+ havekind = true;
+ rate = 0.3;
+ break;
default:
/* For example, '-perm 0644', which is valid and matches
diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am
index c1033d4..089820e 100644
--- a/find/testsuite/Makefile.am
+++ b/find/testsuite/Makefile.am
@@ -145,6 +145,7 @@ find.gnu/perm-slash.exp \
find.gnu/posix-dflt.exp \
find.gnu/posix-h.exp \
find.gnu/posix-l.exp \
+find.gnu/posix-perminvalid.exp \
find.gnu/printfHdfl.exp \
find.gnu/printf.exp \
find.gnu/printf.exp \
diff --git a/find/testsuite/find.gnu/posix-perminvalid.exp
b/find/testsuite/find.gnu/posix-perminvalid.exp
new file mode 100644
index 0000000..7463a4a
--- /dev/null
+++ b/find/testsuite/find.gnu/posix-perminvalid.exp
@@ -0,0 +1,17 @@
+# tests for non-POSIX-compliant argument to -perm
+# Remember any previous value of POSIXLY_CORRECT (if there was one)
+if [info exists env(POSIXLY_CORRECT)] {
+ set oldval env(POSIXLY_CORRECT)
+}
+
+# Set POSIXLY_CORRECT and perform the test
+set env(POSIXLY_CORRECT) 1
+find_start f {. -perm +a+x}
+
+# Set POSIXLY_CORRECT to its previous value
+if [info exists oldval] {
+ set env(POSIXLY_CORRECT) $oldval
+} else {
+ unset env(POSIXLY_CORRECT)
+}
+
diff --git a/find/util.c b/find/util.c
index 8cd7ef9..388f9fc 100644
--- a/find/util.c
+++ b/find/util.c
@@ -888,6 +888,11 @@ now(void)
void
set_option_defaults(struct options *p)
{
+ if (getenv("POSIXLY_CORRECT"))
+ p->posixly_correct = true;
+ else
+ p->posixly_correct = false;
+
/* We call check_nofollow() before setlocale() because the numbers
* for which we check (in the results of uname) definitiely have "."
* as the decimal point indicator even under locales for which that
@@ -912,7 +917,10 @@ set_option_defaults(struct options *p)
p->warnings = false;
p->literal_control_chars = false; /* may change */
}
-
+ if (p->posixly_correct)
+ {
+ p->warnings = false;
+ }
p->do_dir_first = true;
p->maxdepth = p->mindepth = -1;
@@ -922,7 +930,7 @@ set_option_defaults(struct options *p)
p->stay_on_filesystem = false;
p->ignore_readdir_race = false;
- if (getenv("POSIXLY_CORRECT"))
+ if (p->posixly_correct)
p->output_block_size = 512;
else
p->output_block_size = 1024;
--
1.5.3.5
- [Findutils-patches] [PATCH] Bug 21039: Turn off warnings in POSIXLY_CORRECT mode.,
James Youngman <=