View | Details | Raw Unified | Return to bug 166056 | Differences between
and this patch

Collapse All | Expand All

(-)function.c (-3 / +26 lines)
Lines 50-55 Link Here
50
#include <dirent.h>
50
#include <dirent.h>
51
#include <err.h>
51
#include <err.h>
52
#include <errno.h>
52
#include <errno.h>
53
#include <fcntl.h>
53
#include <fnmatch.h>
54
#include <fnmatch.h>
54
#include <fts.h>
55
#include <fts.h>
55
#include <grp.h>
56
#include <grp.h>
Lines 595-601 Link Here
595
int
596
int
596
f_exec(PLAN *plan, FTSENT *entry)
597
f_exec(PLAN *plan, FTSENT *entry)
597
{
598
{
598
	int cnt;
599
	int cnt, path_fd;
599
	pid_t pid;
600
	pid_t pid;
600
	int status;
601
	int status;
601
	char *file;
602
	char *file;
Lines 644-652 Link Here
644
		/* NOTREACHED */
645
		/* NOTREACHED */
645
	case 0:
646
	case 0:
646
		/* change dir back from where we started */
647
		/* change dir back from where we started */
647
		if (!(plan->flags & F_EXECDIR) && fchdir(dotfd)) {
648
		if (!(plan->flags & F_EXECDIR) && \
648
			warn("chdir");
649
		    !(tree->fts_options & FTS_NOCHDIR) && \
650
		    fchdir(dotfd)) {
649
			_exit(1);
651
			_exit(1);
652
		/* 
653
		 * if no entry, we are finishing. without F_NOCHDIR this would
654
		 * happen to be in pwd, so don't chdir. We use tree->fts_options
655
		 * instead of ftsoptions, as FTS_LOGICAL sets FTS_NOCHDIR on
656
		 * fts_open(3)
657
		 */
658
		} else if (entry != NULL && entry->fts_level > 0 && \
659
		    (plan->flags & F_EXECDIR) && \
660
		    (tree->fts_options & FTS_NOCHDIR)) {
661
			/* 
662
			 * "Truncate" by NUL at name boundary, we cannot use
663
			 * entry->fts_parent here as it is not reliably set
664
			 * unless we have called fts_children(3), which we have
665
			 * not.
666
			 */
667
			entry->fts_path[entry->fts_pathlen - entry->fts_namelen] = '\0';
668
			if ((path_fd = open(entry->fts_path, O_RDONLY, 0)) < 0 \
669
			    || fchdir(path_fd) || close(path_fd)) {
670
				warn("chdir");
671
				_exit(1);
672
			} 
650
		}
673
		}
651
		execvp(plan->e_argv[0], plan->e_argv);
674
		execvp(plan->e_argv[0], plan->e_argv);
652
		warn("%s", plan->e_argv[0]);
675
		warn("%s", plan->e_argv[0]);
(-)find.c (-1 / +1 lines)
Lines 179-185 Link Here
179
179
180
	tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL));
180
	tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL));
181
	if (tree == NULL)
181
	if (tree == NULL)
182
		err(1, "ftsopen");
182
		err(1, "fts_open");
183
183
184
	for (rval = 0; (entry = fts_read(tree)) != NULL;) {
184
	for (rval = 0; (entry = fts_read(tree)) != NULL;) {
185
		if (maxdepth != -1 && entry->fts_level >= maxdepth) {
185
		if (maxdepth != -1 && entry->fts_level >= maxdepth) {
(-)main.c (-3 / +5 lines)
Lines 63-69 Link Here
63
63
64
time_t now;			/* time find was run */
64
time_t now;			/* time find was run */
65
int dotfd;			/* starting directory */
65
int dotfd;			/* starting directory */
66
int ftsoptions;			/* options for the ftsopen(3) call */
66
int ftsoptions;			/* options for the fts_open(3) call */
67
int isdeprecated;		/* using deprecated syntax */
67
int isdeprecated;		/* using deprecated syntax */
68
int isdepth;			/* do directories on post-order visit */
68
int isdepth;			/* do directories on post-order visit */
69
int isoutput;			/* user specified output operator */
69
int isoutput;			/* user specified output operator */
Lines 150-157 Link Here
150
		usage();
150
		usage();
151
	*p = NULL;
151
	*p = NULL;
152
152
153
	if ((dotfd = open(".", O_RDONLY, 0)) < 0)
153
	if ((dotfd = open(".", O_RDONLY, 0)) < 0) {
154
		err(1, ".");
154
		warn(".");
155
		ftsoptions |= FTS_NOCHDIR;
156
	}
155
157
156
	exit(find_execute(find_formplan(argv), start));
158
	exit(find_execute(find_formplan(argv), start));
157
}
159
}

Return to bug 166056