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]); |