summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-10-03 19:07:36 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-10-03 19:07:36 +0000
commite11b72aa88ac493b18bffc222b22540f38be8b4b (patch)
treeee4f75f81abf3f3288f820938414e584fa9f7aed /usr.bin
parent5249c70598d7a7ff666c7f0724b315b0500d47e5 (diff)
Do not use FTS_CHDIRROOT flag as it is fatally flawed. Instead,
do the chdir ourselves. This fixes a problem with the -execdir option with multiple relative directories.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/find/find.c22
-rw-r--r--usr.bin/find/function.c5
2 files changed, 19 insertions, 8 deletions
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c
index 20efeaca741..85034ad53e9 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: find.c,v 1.5 1997/06/30 23:54:07 millert Exp $ */
+/* $OpenBSD: find.c,v 1.6 1999/10/03 19:07:35 millert Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -38,7 +38,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)find.c 8.1 (Berkeley) 6/6/93";*/
-static char rcsid[] = "$OpenBSD: find.c,v 1.5 1997/06/30 23:54:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: find.c,v 1.6 1999/10/03 19:07:35 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -163,7 +163,7 @@ find_execute(plan, paths)
err(1, "ftsopen");
while ((entry = fts_read(tree))) {
- switch(entry->fts_info) {
+ switch (entry->fts_info) {
case FTS_D:
if (isdepth)
continue;
@@ -185,13 +185,25 @@ find_execute(plan, paths)
warnx("%s: illegal path", entry->fts_path);
continue;
}
+
+ /*
+ * Since fts does not chdir for the root node we
+ * have to do this ourselves to make -execdir work.
+ */
+ if (entry->fts_level == FTS_ROOTLEVEL)
+ chdir(entry->fts_accpath);
/*
- * call all the functions in the execution plan until one is
+ * Call all the functions in the execution plan until one is
* false or all have been executed. This is where we do all
* the work specified by the user on the command line.
*/
- for (p = plan; p && (p->eval)(p, entry); p = p->next);
+ for (p = plan; p && (p->eval)(p, entry); p = p->next)
+ ;
+
+ /* Undo the chdir above to make fts happy. */
+ if (entry->fts_level == FTS_ROOTLEVEL)
+ fchdir(tree->fts_rfd);
}
(void)fts_close(tree);
}
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 0237c2a3a37..8b7df0d5d04 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: function.c,v 1.13 1999/03/17 17:36:30 espie Exp $ */
+/* $OpenBSD: function.c,v 1.14 1999/10/03 19:07:35 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.13 1999/03/17 17:36:30 espie Exp $";
+static char rcsid[] = "$OpenBSD: function.c,v 1.14 1999/10/03 19:07:35 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -486,7 +486,6 @@ c_execdir(argvp)
register char **argv, **ap, *p;
ftsoptions &= ~FTS_NOSTAT;
- ftsoptions |= FTS_CHDIRROOT;
isoutput = 1;
new = palloc(N_EXECDIR, f_execdir);