summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-06-25 14:07:19 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-06-25 14:07:19 -0400
commit8ea91a14b24714517e8aafcd59fd774ed7354ecb (patch)
tree5eaa574ec54a502e40bba4f9c086870f4ed01598
parentfcd95bfc4801037d747328911d2201a81cca5534 (diff)
downloadbfs-8ea91a14b24714517e8aafcd59fd774ed7354ecb.tar.xz
exec: Don't assume bfs_exec_debug() doesn't change errno
-rw-r--r--exec.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/exec.c b/exec.c
index d1503fe..2b18ce8 100644
--- a/exec.c
+++ b/exec.c
@@ -446,13 +446,14 @@ static bool bfs_exec_args_remain(const struct bfs_exec *execbuf) {
/** Execute the pending command from a BFS_EXEC_MULTI execbuf. */
static int bfs_exec_flush(struct bfs_exec *execbuf) {
- int ret = 0;
+ int ret = 0, error = 0;
size_t orig_argc = execbuf->argc;
while (bfs_exec_args_remain(execbuf)) {
execbuf->argv[execbuf->argc] = NULL;
ret = bfs_exec_spawn(execbuf);
- if (ret == 0 || errno != E2BIG) {
+ error = errno;
+ if (ret == 0 || error != E2BIG) {
break;
}
@@ -466,8 +467,6 @@ static int bfs_exec_flush(struct bfs_exec *execbuf) {
size_t new_argc = execbuf->argc;
size_t new_size = execbuf->arg_size;
- int error = errno;
-
for (size_t i = execbuf->tmpl_argc - 1; i < new_argc; ++i) {
free(execbuf->argv[i]);
}