From a91e8878a9e52f7321fc44dba6f4be0e599bf37d Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 17 Jan 2005 21:12:04 +0000 Subject: [PATCH] Fixed savannah bug #11625 Wrong return status for -exec ... \; when command fails; also execute any pending commands when doing -quit --- find/defs.h | 1 + find/find.c | 20 +++++++++++++++++--- find/pred.c | 21 ++++++++++++++++++--- find/testsuite/Makefile.am | 8 ++++++++ find/testsuite/config/unix.exp | 2 +- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/find/defs.h b/find/defs.h index 169d3e4..2295a82 100644 --- a/find/defs.h +++ b/find/defs.h @@ -366,6 +366,7 @@ enum SymlinkOption extern enum SymlinkOption symlink_handling; /* defined in find.c. */ void set_follow_state PARAMS((enum SymlinkOption opt)); +void cleanup(void); /* fstype.c */ char *filesystem_type PARAMS((const struct stat *statp)); diff --git a/find/find.c b/find/find.c index 294e636..8227d9d 100644 --- a/find/find.c +++ b/find/find.c @@ -91,7 +91,7 @@ struct predicate *predicates; struct predicate *last_pred; /* The root of the evaluation tree. */ -static struct predicate *eval_tree; +static struct predicate *eval_tree = NULL; struct options options; @@ -269,6 +269,20 @@ set_follow_state(enum SymlinkOption opt) options.xstat = debug_stat; #endif /* !DEBUG_STAT */ } + + +/* Complete any outstanding commands. + */ +void +cleanup(void) +{ + if (eval_tree) + { + complete_pending_execs(eval_tree); + complete_pending_execdirs(eval_tree); + } +} + int @@ -287,6 +301,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); atexit (close_stdout); + if (isatty(0)) { @@ -503,8 +518,7 @@ main (int argc, char **argv) * partially-full command lines which have been built, * but which are not yet complete. Execute those now. */ - complete_pending_execs(eval_tree); - + cleanup(); return state.exit_status; } diff --git a/find/pred.c b/find/pred.c index 4b835d1..f7b8f7e 100644 --- a/find/pred.c +++ b/find/pred.c @@ -1606,7 +1606,16 @@ launch (const struct buildcmd_control *ctl, { error (0, 0, _("%s terminated by signal %d"), buildstate->cmd_argv[0], WTERMSIG (wait_status)); - state.exit_status = 1; + + if (execp->multiple) + { + /* -exec \; just returns false if the invoked command fails. + * -exec {} + returns true if the invoked command fails, but + * sets the program exit status. + */ + state.exit_status = 1; + } + return 1; /* OK */ } @@ -1616,8 +1625,14 @@ launch (const struct buildcmd_control *ctl, } else { - - state.exit_status = 1; + if (execp->multiple) + { + /* -exec \; just returns false if the invoked command fails. + * -exec {} + returns true if the invoked command fails, but + * sets the program exit status. + */ + state.exit_status = 1; + } return 0; /* FAIL */ } diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am index e23a220..35b54fa 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -18,6 +18,14 @@ EXTRA_DIST = config/unix.exp \ find.gnu/prune-default-print.xo \ find.posix/sv-bug-11175.exp \ find.posix/sv-bug-11175.xo + find.gnu/exec-many-rtn-failure.exp \ + find.gnu/exec-many-rtn-failure.xo \ + find.gnu/exec-many-rtn-success.exp \ + find.gnu/exec-many-rtn-success.xo \ + find.gnu/exec-one-rtn-fail.exp \ + find.gnu/exec-one-rtn-fail.xo \ + find.gnu/exec-one-rtn-success.exp \ + find.gnu/exec-one-rtn-success.xo CLEANFILES = *.log *.sum site.exp site.bak diff --git a/find/testsuite/config/unix.exp b/find/testsuite/config/unix.exp index 79500c9..572224e 100644 --- a/find/testsuite/config/unix.exp +++ b/find/testsuite/config/unix.exp @@ -119,6 +119,6 @@ proc find_start { passfail options {infile ""}} { # Called by runtest. # Clean up (remove temporary files) before runtest exits. proc find_exit {} { - catch "exec rm -f find.out" + # catch "exec rm -f find.out" exec echo hello } -- 2.11.4.GIT