| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: function.c,v 1.75.8.2 2018/09/10 15:48:25 martin Exp $ */ | | 1 | /* $NetBSD: function.c,v 1.75.8.3 2023/08/04 13:12:00 martin Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1990, 1993 | | 4 | * Copyright (c) 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Cimarron D. Taylor of the University of California, Berkeley. | | 8 | * Cimarron D. Taylor of the University of California, Berkeley. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #include <sys/cdefs.h> | | 35 | #include <sys/cdefs.h> |
36 | #ifndef lint | | 36 | #ifndef lint |
37 | #if 0 | | 37 | #if 0 |
38 | static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95"; | | 38 | static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95"; |
39 | #else | | 39 | #else |
40 | __RCSID("$NetBSD: function.c,v 1.75.8.2 2018/09/10 15:48:25 martin Exp $"); | | 40 | __RCSID("$NetBSD: function.c,v 1.75.8.3 2023/08/04 13:12:00 martin Exp $"); |
41 | #endif | | 41 | #endif |
42 | #endif /* not lint */ | | 42 | #endif /* not lint */ |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <sys/stat.h> | | 45 | #include <sys/stat.h> |
46 | #include <sys/wait.h> | | 46 | #include <sys/wait.h> |
47 | #include <sys/mount.h> | | 47 | #include <sys/mount.h> |
48 | | | 48 | |
49 | #include <dirent.h> | | 49 | #include <dirent.h> |
50 | #include <err.h> | | 50 | #include <err.h> |
51 | #include <errno.h> | | 51 | #include <errno.h> |
52 | #include <fnmatch.h> | | 52 | #include <fnmatch.h> |
53 | #include <fts.h> | | 53 | #include <fts.h> |
| @@ -631,27 +631,28 @@ f_exec(PLAN *plan, FTSENT *entry) | | | @@ -631,27 +631,28 @@ f_exec(PLAN *plan, FTSENT *entry) |
631 | &plan->e_len[cnt]); | | 631 | &plan->e_len[cnt]); |
632 | if (plan->flags & F_NEEDOK && !queryuser(plan->e_argv)) | | 632 | if (plan->flags & F_NEEDOK && !queryuser(plan->e_argv)) |
633 | return (0); | | 633 | return (0); |
634 | | | 634 | |
635 | /* Don't mix output of command with find output. */ | | 635 | /* Don't mix output of command with find output. */ |
636 | fflush(stdout); | | 636 | fflush(stdout); |
637 | fflush(stderr); | | 637 | fflush(stderr); |
638 | | | 638 | |
639 | switch (pid = vfork()) { | | 639 | switch (pid = vfork()) { |
640 | case -1: | | 640 | case -1: |
641 | err(1, "vfork"); | | 641 | err(1, "vfork"); |
642 | /* NOTREACHED */ | | 642 | /* NOTREACHED */ |
643 | case 0: | | 643 | case 0: |
644 | if (fchdir(dotfd)) { | | 644 | /* change dir back from where we started */ |
| | | 645 | if (!(ftsoptions & FTS_NOCHDIR) && fchdir(dotfd)) { |
645 | warn("chdir"); | | 646 | warn("chdir"); |
646 | _exit(1); | | 647 | _exit(1); |
647 | } | | 648 | } |
648 | execvp(plan->e_argv[0], plan->e_argv); | | 649 | execvp(plan->e_argv[0], plan->e_argv); |
649 | warn("%s", plan->e_argv[0]); | | 650 | warn("%s", plan->e_argv[0]); |
650 | _exit(1); | | 651 | _exit(1); |
651 | } | | 652 | } |
652 | pid = waitpid(pid, &status, 0); | | 653 | pid = waitpid(pid, &status, 0); |
653 | return (pid != -1 && WIFEXITED(status) | | 654 | return (pid != -1 && WIFEXITED(status) |
654 | && !WEXITSTATUS(status)); | | 655 | && !WEXITSTATUS(status)); |
655 | } | | 656 | } |
656 | } | | 657 | } |
657 | | | 658 | |
| @@ -663,27 +664,28 @@ run_f_exec(PLAN *plan) | | | @@ -663,27 +664,28 @@ run_f_exec(PLAN *plan) |
663 | | | 664 | |
664 | /* Ensure arg list is null terminated. */ | | 665 | /* Ensure arg list is null terminated. */ |
665 | plan->ep_bxp[plan->ep_narg] = NULL; | | 666 | plan->ep_bxp[plan->ep_narg] = NULL; |
666 | | | 667 | |
667 | /* Don't mix output of command with find output. */ | | 668 | /* Don't mix output of command with find output. */ |
668 | fflush(stdout); | | 669 | fflush(stdout); |
669 | fflush(stderr); | | 670 | fflush(stderr); |
670 | | | 671 | |
671 | switch (pid = vfork()) { | | 672 | switch (pid = vfork()) { |
672 | case -1: | | 673 | case -1: |
673 | err(1, "vfork"); | | 674 | err(1, "vfork"); |
674 | /* NOTREACHED */ | | 675 | /* NOTREACHED */ |
675 | case 0: | | 676 | case 0: |
676 | if (fchdir(dotfd)) { | | 677 | /* change dir back from where we started */ |
| | | 678 | if (!(ftsoptions & FTS_NOCHDIR) && fchdir(dotfd)) { |
677 | warn("chdir"); | | 679 | warn("chdir"); |
678 | _exit(1); | | 680 | _exit(1); |
679 | } | | 681 | } |
680 | execvp(plan->e_argv[0], plan->e_argv); | | 682 | execvp(plan->e_argv[0], plan->e_argv); |
681 | warn("%s", plan->e_argv[0]); | | 683 | warn("%s", plan->e_argv[0]); |
682 | _exit(1); | | 684 | _exit(1); |
683 | } | | 685 | } |
684 | | | 686 | |
685 | /* Clear out the argument list. */ | | 687 | /* Clear out the argument list. */ |
686 | plan->ep_narg = 0; | | 688 | plan->ep_narg = 0; |
687 | plan->ep_bxp[plan->ep_narg] = NULL; | | 689 | plan->ep_bxp[plan->ep_narg] = NULL; |
688 | /* As well as the argument buffer. */ | | 690 | /* As well as the argument buffer. */ |
689 | plan->ep_p = plan->ep_bbp; | | 691 | plan->ep_p = plan->ep_bbp; |