summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-09-01 02:44:16 +0000
committermillert <millert@openbsd.org>1997-09-01 02:44:16 +0000
commitbc8371e6590057ce03529c50b809303d8db82de0 (patch)
treee14bc835d3821ff92555193c1e6c7c52a1ace20a
parentmissing VAX manual for infnan(3), from 4.4 BSD (diff)
downloadwireguard-openbsd-bc8371e6590057ce03529c50b809303d8db82de0.tar.xz
wireguard-openbsd-bc8371e6590057ce03529c50b809303d8db82de0.zip
Fix problem with ``find -execdir'' not having the correct initial cwd.
Adds a new flag to fts(3).
-rw-r--r--include/fts.h23
-rw-r--r--lib/libc/gen/fts.c36
-rw-r--r--lib/libc/shlib_version2
-rw-r--r--usr.bin/find/function.c19
4 files changed, 47 insertions, 33 deletions
diff --git a/include/fts.h b/include/fts.h
index c6bc5ff74de..6e29bd519c0 100644
--- a/include/fts.h
+++ b/include/fts.h
@@ -49,18 +49,19 @@ typedef struct {
int fts_nitems; /* elements in the sort array */
int (*fts_compar)(); /* compare function */
-#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
-#define FTS_LOGICAL 0x002 /* logical walk */
-#define FTS_NOCHDIR 0x004 /* don't change directories */
-#define FTS_NOSTAT 0x008 /* don't get stat info */
-#define FTS_PHYSICAL 0x010 /* physical walk */
-#define FTS_SEEDOT 0x020 /* return dot and dot-dot */
-#define FTS_XDEV 0x040 /* don't cross devices */
-#define FTS_WHITEOUT 0x080 /* return whiteout information */
-#define FTS_OPTIONMASK 0x0ff /* valid user option mask */
+#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */
+#define FTS_LOGICAL 0x0002 /* logical walk */
+#define FTS_NOCHDIR 0x0004 /* don't change directories */
+#define FTS_NOSTAT 0x0008 /* don't get stat info */
+#define FTS_PHYSICAL 0x0010 /* physical walk */
+#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */
+#define FTS_XDEV 0x0040 /* don't cross devices */
+#define FTS_WHITEOUT 0x0080 /* return whiteout information */
+#define FTS_CHDIRROOT 0x0100 /* chdir to root of tree not orig cwd */
+#define FTS_OPTIONMASK 0x0fff /* valid user option mask */
-#define FTS_NAMEONLY 0x100 /* (private) child names only */
-#define FTS_STOP 0x200 /* (private) unrecoverable error */
+#define FTS_NAMEONLY 0x1000 /* (private) child names only */
+#define FTS_STOP 0x2000 /* (private) unrecoverable error */
int fts_options; /* fts_open options, global flags */
} FTS;
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index ce5d2674f27..a2ac72b17e8 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fts.c,v 1.10 1997/08/29 22:43:08 imp Exp $ */
+/* $OpenBSD: fts.c,v 1.11 1997/09/01 02:44:17 millert Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
#else
-static char rcsid[] = "$OpenBSD: fts.c,v 1.10 1997/08/29 22:43:08 imp Exp $";
+static char rcsid[] = "$OpenBSD: fts.c,v 1.11 1997/09/01 02:44:17 millert Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -167,7 +167,7 @@ fts_open(argv, options, compar)
sp->fts_cur->fts_info = FTS_INIT;
/*
- * If using chdir(2), grab a file descriptor pointing to dot to insure
+ * If using chdir(2), grab a file descriptor pointing to dot to ensure
* that we can get back here; this could be avoided for some paths,
* but almost certainly not worth the effort. Slashes, symbolic links,
* and ".." are all fairly nasty problems. Note, if we can't get the
@@ -366,13 +366,20 @@ next: tmp = p;
free(tmp);
/*
- * If reached the top, return to the original directory, and
- * load the paths for the next root.
+ * If reached the top, return to the original directory (or
+ * the root of the tree), and load the paths for the next root.
*/
if (p->fts_level == FTS_ROOTLEVEL) {
- if (FCHDIR(sp, sp->fts_rfd)) {
- SET(FTS_STOP);
- return (NULL);
+ if ((sp->fts_options & FTS_CHDIRROOT)) {
+ if (chdir(p->fts_accpath)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ } else {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
}
fts_load(sp, p);
return (sp->fts_cur = p);
@@ -426,9 +433,16 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent);
* one directory.
*/
if (p->fts_level == FTS_ROOTLEVEL) {
- if (FCHDIR(sp, sp->fts_rfd)) {
- SET(FTS_STOP);
- return (NULL);
+ if ((sp->fts_options & FTS_CHDIRROOT)) {
+ if (chdir(p->fts_accpath)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ } else {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
}
} else if (p->fts_flags & FTS_SYMFOLLOW) {
if (FCHDIR(sp, p->fts_symfd)) {
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index 730231c38d0..49b346400a8 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,2 +1,2 @@
major=17
-minor=1
+minor=2
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 9f8bccd957c..92d1a5a1c2a 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: function.c,v 1.9 1997/06/30 23:54:07 millert Exp $ */
+/* $OpenBSD: function.c,v 1.10 1997/09/01 02:44:19 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)function.c 8.1 (Berkeley) 6/6/93";*/
-static char rcsid[] = "$OpenBSD: function.c,v 1.9 1997/06/30 23:54:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: function.c,v 1.10 1997/09/01 02:44:19 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -53,6 +53,7 @@ static char rcsid[] = "$OpenBSD: function.c,v 1.9 1997/06/30 23:54:07 millert Ex
#include <fnmatch.h>
#include <fts.h>
#include <grp.h>
+#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -379,18 +380,15 @@ f_execdir(plan, entry)
register int cnt;
pid_t pid;
int status;
- char *file;
-
- /* XXX - if file/dir ends in '/' this will not work -- can it? */
- if ((file = strrchr(entry->fts_path, '/')))
- file++;
- else
- file = entry->fts_path;
+ char base[MAXPATHLEN];
+ /* Substitute basename(path) for {} since cwd is it's parent dir */
+ (void)strncpy(base, basename(entry->fts_path), sizeof(base) - 1);
+ base[sizeof(base) - 1] = '\0';
for (cnt = 0; plan->e_argv[cnt]; ++cnt)
if (plan->e_len[cnt])
brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
- file, plan->e_len[cnt]);
+ base, plan->e_len[cnt]);
/* don't mix output of command with find output */
fflush(stdout);
@@ -425,6 +423,7 @@ c_execdir(argvp)
register char **argv, **ap, *p;
ftsoptions &= ~FTS_NOSTAT;
+ ftsoptions |= FTS_CHDIRROOT;
isoutput = 1;
new = palloc(N_EXECDIR, f_execdir);