Fri Aug 4 13:12:00 2023 UTC ()
Pull up following revision(s) (requested by riastradh in ticket #1879):

	usr.bin/find/main.c: revision 1.32
	usr.bin/find/function.c: revision 1.80

PR/57313: Timo Buhrmester: Don't bail if "." cannot be opened. From FreeBSD


(martin)
diff -r1.75.8.2 -r1.75.8.3 src/usr.bin/find/function.c
diff -r1.31 -r1.31.22.1 src/usr.bin/find/main.c

cvs diff -r1.75.8.2 -r1.75.8.3 src/usr.bin/find/function.c (expand / switch to unified diff)

--- src/usr.bin/find/function.c 2018/09/10 15:48:25 1.75.8.2
+++ src/usr.bin/find/function.c 2023/08/04 13:12:00 1.75.8.3
@@ -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
38static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95"; 38static 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;

cvs diff -r1.31 -r1.31.22.1 src/usr.bin/find/main.c (expand / switch to unified diff)

--- src/usr.bin/find/main.c 2013/01/24 17:50:08 1.31
+++ src/usr.bin/find/main.c 2023/08/04 13:12:00 1.31.22.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.31 2013/01/24 17:50:08 christos Exp $ */ 1/* $NetBSD: main.c,v 1.31.22.1 2023/08/04 13:12:00 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993, 1994 4 * Copyright (c) 1990, 1993, 1994
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.
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
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
38static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; 38static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
39#else 39#else
40__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\ 40__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\
41 The Regents of the University of California. All rights reserved."); 41 The Regents of the University of California. All rights reserved.");
42__RCSID("$NetBSD: main.c,v 1.31 2013/01/24 17:50:08 christos Exp $"); 42__RCSID("$NetBSD: main.c,v 1.31.22.1 2023/08/04 13:12:00 martin Exp $");
43#endif 43#endif
44#endif /* not lint */ 44#endif /* not lint */
45 45
46#include <sys/types.h> 46#include <sys/types.h>
47#include <sys/stat.h> 47#include <sys/stat.h>
48 48
49#include <err.h> 49#include <err.h>
50#include <errno.h> 50#include <errno.h>
51#include <fcntl.h> 51#include <fcntl.h>
52#include <fts.h> 52#include <fts.h>
53#include <locale.h> 53#include <locale.h>
54#include <stdio.h> 54#include <stdio.h>
55#include <stdlib.h> 55#include <stdlib.h>
@@ -139,26 +139,26 @@ main(int argc, char *argv[]) @@ -139,26 +139,26 @@ main(int argc, char *argv[])
139 if (argv[0][0] == '-') 139 if (argv[0][0] == '-')
140 break; 140 break;
141 if ((argv[0][0] == '!' || argv[0][0] == '(') && 141 if ((argv[0][0] == '!' || argv[0][0] == '(') &&
142 argv[0][1] == '\0') 142 argv[0][1] == '\0')
143 break; 143 break;
144 } 144 }
145 145
146 if (p == start) 146 if (p == start)
147 usage(); 147 usage();
148 148
149 *p = NULL; 149 *p = NULL;
150 150
151 if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) 151 if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1)
152 err(1, "."); 152 ftsoptions |= FTS_NOCHDIR;
153 153
154 exit(find_execute(find_formplan(argv), start)); 154 return find_execute(find_formplan(argv), start);
155} 155}
156 156
157static void 157static void
158usage(void) 158usage(void)
159{ 159{
160 160
161 (void)fprintf(stderr, "Usage: %s [-H | -L | -P] [-dEhsXx] [-f file] " 161 (void)fprintf(stderr, "Usage: %s [-H | -L | -P] [-dEhsXx] [-f file] "
162 "file [file ...] [expression]\n", getprogname()); 162 "file [file ...] [expression]\n", getprogname());
163 exit(1); 163 exit(1);
164} 164}