aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-06-19 11:32:11 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-06-19 11:32:11 +0200
commit6be3a5242ce4855734a4cdd5770b6ea7adaf2b3d (patch)
treee4903316cbaaaeb7cb0a4396daacb3ec1ff8e467
parent14158b4127dba30466c50147b868a6a89702960b (diff)
downloadbusybox-w32-6be3a5242ce4855734a4cdd5770b6ea7adaf2b3d.tar.gz
busybox-w32-6be3a5242ce4855734a4cdd5770b6ea7adaf2b3d.tar.bz2
busybox-w32-6be3a5242ce4855734a4cdd5770b6ea7adaf2b3d.zip
find: exit code fixes for find -exec
function old new delta func_exec 127 100 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c17
-rwxr-xr-xtestsuite/find.tests26
2 files changed, 35 insertions, 8 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 8ac3da7a0..493f72e61 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -634,6 +634,7 @@ static int do_exec(action_exec *ap, const char *fileName)
634 } else { 634 } else {
635 int j = 0; 635 int j = 0;
636 while (ap->filelist[j]) { 636 while (ap->filelist[j]) {
637 /* 2nd arg here should be ap->subst_count[i], but it is always 1: */
637 *pp++ = xmalloc_substitute_string(arg, 1, "{}", ap->filelist[j]); 638 *pp++ = xmalloc_substitute_string(arg, 1, "{}", ap->filelist[j]);
638 free(ap->filelist[j]); 639 free(ap->filelist[j]);
639 j++; 640 j++;
@@ -669,16 +670,16 @@ ACTF(exec)
669{ 670{
670# if ENABLE_FEATURE_FIND_EXEC_PLUS 671# if ENABLE_FEATURE_FIND_EXEC_PLUS
671 if (ap->filelist) { 672 if (ap->filelist) {
672 int rc = 0; 673 int rc;
673 674
675 ap->filelist = xrealloc_vector(ap->filelist, 8, ap->filelist_idx);
676 ap->filelist[ap->filelist_idx++] = xstrdup(fileName);
677 ap->file_len += strlen(fileName) + sizeof(char*) + 1;
674 /* If we have lots of files already, exec the command */ 678 /* If we have lots of files already, exec the command */
679 rc = 1;
675 if (ap->file_len >= 32*1024) 680 if (ap->file_len >= 32*1024)
676 rc = do_exec(ap, NULL); 681 rc = do_exec(ap, NULL);
677 682 return rc;
678 ap->file_len += strlen(fileName) + sizeof(char*) + 1;
679 ap->filelist = xrealloc_vector(ap->filelist, 8, ap->filelist_idx);
680 ap->filelist[ap->filelist_idx++] = xstrdup(fileName);
681 return rc == 0; /* return 1 if exitcode 0 */
682 } 683 }
683# endif 684# endif
684 return do_exec(ap, fileName); 685 return do_exec(ap, fileName);
@@ -698,8 +699,8 @@ static int flush_exec_plus(void)
698# if ENABLE_FEATURE_FIND_NOT 699# if ENABLE_FEATURE_FIND_NOT
699 if (ap->invert) rc = !rc; 700 if (ap->invert) rc = !rc;
700# endif 701# endif
701 if (rc) 702 if (rc == 0)
702 return rc; 703 return 1;
703 } 704 }
704 } 705 }
705 } 706 }
diff --git a/testsuite/find.tests b/testsuite/find.tests
index 345d1e82e..f041106c3 100755
--- a/testsuite/find.tests
+++ b/testsuite/find.tests
@@ -15,6 +15,32 @@ testing "find -type f" \
15 "./testfile\n" \ 15 "./testfile\n" \
16 "" "" 16 "" ""
17 17
18optional FEATURE_FIND_EXEC
19testing "find -exec exitcode 1" \
20 "cd find.tempdir && find testfile -exec true {} \; 2>&1; echo \$?" \
21 "0\n" \
22 "" ""
23SKIP=
24optional FEATURE_FIND_EXEC_PLUS
25testing "find -exec exitcode 2" \
26 "cd find.tempdir && find testfile -exec true {} + 2>&1; echo \$?" \
27 "0\n" \
28 "" ""
29SKIP=
30# Surprisingly, "-exec false ;" results in exitcode 0! "-exec false +" is different!!!
31optional FEATURE_FIND_EXEC
32testing "find -exec exitcode 3" \
33 "cd find.tempdir && find testfile -exec false {} \; 2>&1; echo \$?" \
34 "0\n" \
35 "" ""
36SKIP=
37optional FEATURE_FIND_EXEC_PLUS
38testing "find -exec exitcode 4" \
39 "cd find.tempdir && find testfile -exec false {} + 2>&1; echo \$?" \
40 "1\n" \
41 "" ""
42SKIP=
43
18# testing "description" "command" "result" "infile" "stdin" 44# testing "description" "command" "result" "infile" "stdin"
19 45
20rm -rf find.tempdir 46rm -rf find.tempdir