From 44dd6dd6520430b677ab97e886e8317490f04355 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 25 Mar 2019 14:44:58 -0700 Subject: find: fix inverted -exec exit status The return value of -exec was the command's exit code, which did not account for the fact that an exit code of zero means success, while in C, zero means failure. From POSIX: > the primary shall evaluate as true if the utility returns a zero > value as exit status This commit flips the return value, and adds two tests. --- tests/find.test | 4 ++++ toys/posix/find.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/find.test b/tests/find.test index de48c5c8..6b0b0a8a 100755 --- a/tests/find.test +++ b/tests/find.test @@ -56,6 +56,10 @@ testing "-type f -user -exec" \ "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" "" testing "-type l -newer -exec" \ "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" "" +testing "-exec true \\; -print" \ + "find dir/file -exec true \\; -print" "dir/file\n" "" "" +testing "-exec false \\; -print" \ + "find dir/file -exec false \\; -print" "" "" "" testing "-perm (exact success)" \ "find perm -type f -perm 0444" "perm/all-read-only\n" "" "" testing "-perm (exact failure)" \ diff --git a/toys/posix/find.c b/toys/posix/find.c index 1c35155b..5cefbf15 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -530,7 +530,7 @@ static int do_find(struct dirtree *new) aa->plus = 1; toys.exitval |= flush_exec(new, aa); } - } else test = flush_exec(new, aa); + } else test = !flush_exec(new, aa); } // Argument consumed, skip the check. -- cgit v1.2.3