summaryrefslogtreecommitdiffstats
path: root/exec.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-07-08 19:19:18 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-07-08 19:27:10 -0400
commite991bc786af40623ae118eab9d400d6cd391d8c6 (patch)
tree446ad27d225293271a73f5bd970dbeddea62dceb /exec.c
parent2a3eab05901f32aeabf0e4b45d5b50fdf056e23d (diff)
downloadbfs-e991bc786af40623ae118eab9d400d6cd391d8c6.tar.xz
exec: Clear errno when a multi-exec doesn't fail
This fixes strange "Inappropriate ioctl for device" errors when using -exec ... + with output redirection. errno was set to ENOTTY by the isatty() call during startup for color auto-detection, and never cleared before eval_exec() wants to check if anything went wrong.
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/exec.c b/exec.c
index 5f3a804..3178dbe 100644
--- a/exec.c
+++ b/exec.c
@@ -449,6 +449,8 @@ static int bfs_exec_flush(struct bfs_exec *execbuf) {
}
}
+ int error = errno;
+
bfs_exec_closewd(execbuf, NULL);
for (size_t i = execbuf->placeholder; i < last_path; ++i) {
@@ -457,6 +459,7 @@ static int bfs_exec_flush(struct bfs_exec *execbuf) {
execbuf->argc = execbuf->placeholder;
execbuf->arg_size = 0;
+ errno = error;
return ret;
}
@@ -544,7 +547,9 @@ out:
int bfs_exec(struct bfs_exec *execbuf, const struct BFTW *ftwbuf) {
if (execbuf->flags & BFS_EXEC_MULTI) {
- if (bfs_exec_multi(execbuf, ftwbuf) != 0) {
+ if (bfs_exec_multi(execbuf, ftwbuf) == 0) {
+ errno = 0;
+ } else {
execbuf->ret = -1;
}
// -exec ... + never returns false