summaryrefslogtreecommitdiffstats
path: root/usr.bin/find
diff options
context:
space:
mode:
authorkrion <krion@FreeBSD.org>2006-05-14 20:23:01 +0000
committerkrion <krion@FreeBSD.org>2006-05-14 20:23:01 +0000
commit1076011263cd5794f112caf825f49bdf11027532 (patch)
tree349cde92880cada6ae50eb2f1d12fbfd74df1464 /usr.bin/find
parente2f88f3971f0d26f104b1b97f27675f57c6182b9 (diff)
downloadFreeBSD-src-1076011263cd5794f112caf825f49bdf11027532.zip
FreeBSD-src-1076011263cd5794f112caf825f49bdf11027532.tar.gz
The last execution of -exec {} + is not done if the -exec primary is
not on the top-level -and sequence, e.g. inside of ! or -or. Create a separate linked list of all active -exec {} + primaries and do the last execution for all at termination. PR: bin/79263 Submitted by: Jilles Tjoelker <jilles@stack.nl> MFC after: 7 days
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/extern.h1
-rw-r--r--usr.bin/find/find.c5
-rw-r--r--usr.bin/find/find.h2
-rw-r--r--usr.bin/find/function.c17
4 files changed, 21 insertions, 4 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index 2ee8510..a6f09f4 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -49,6 +49,7 @@ struct stat;
void printlong(char *, char *, struct stat *);
int queryuser(char **);
OPTION *lookup_option(const char *);
+void finish_execplus(void);
creat_f c_Xmin;
creat_f c_Xtime;
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c
index 0486e8b..cc2d797 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -231,10 +231,7 @@ find_execute(PLAN *plan, char *paths[])
*/
for (p = plan; p && (p->execute)(p, entry); p = p->next);
}
- /* Finish any pending -exec ... {} + functions. */
- for (p = plan; p != NULL; p = p->next)
- if (p->execute == f_exec && p->flags & F_EXECPLUS)
- (p->execute)(p, NULL);
+ finish_execplus();
if (errno)
err(1, "fts_read");
return (rval);
diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h
index 7f1acaf..c7366fa 100644
--- a/usr.bin/find/find.h
+++ b/usr.bin/find/find.h
@@ -105,6 +105,7 @@ typedef struct _plandata {
int _e_psize; /* number of bytes of args. */
int _e_pbsize; /* base num. of bytes of args */
int _e_psizemax; /* max num. of bytes of args */
+ struct _plandata *_e_next;/* next F_EXECPLUS in tree */
} ex;
char *_a_data[2]; /* array of char pointers */
char *_c_data; /* char pointer */
@@ -135,6 +136,7 @@ typedef struct _plandata {
#define e_psize p_un.ex._e_psize
#define e_pbsize p_un.ex._e_pbsize
#define e_psizemax p_un.ex._e_psizemax
+#define e_next p_un.ex._e_next
typedef struct _option {
const char *name; /* option name */
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 38bf813..f1c473e 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -76,6 +76,8 @@ static char *nextarg(OPTION *, char ***);
extern char **environ;
+static PLAN *lastexecplus = NULL;
+
#define COMPARE(a, b) do { \
switch (plan->flags & F_ELG_MASK) { \
case F_EQUAL: \
@@ -711,6 +713,8 @@ c_exec(OPTION *option, char ***argvp)
new->e_psizemax = argmax;
new->e_pbsize = 0;
cnt += new->e_pnummax + 1;
+ new->e_next = lastexecplus;
+ lastexecplus = new;
}
if ((new->e_argv = malloc(cnt * sizeof(char *))) == NULL)
err(1, NULL);
@@ -754,6 +758,19 @@ done: *argvp = argv + 1;
return new;
}
+/* Finish any pending -exec ... {} + functions. */
+void
+finish_execplus()
+{
+ PLAN *p;
+
+ p = lastexecplus;
+ while (p != NULL) {
+ (p->execute)(p, NULL);
+ p = p->e_next;
+ }
+}
+
int
f_flags(PLAN *plan, FTSENT *entry)
{
OpenPOWER on IntegriCloud