b2530c23048ef8708f0f9a007154d0a4e703fd6d — Simon Ser 3 days ago bfe2f7a
shell/task/simple_command: fix redirections giving EBADF

Closes: https://github.com/emersion/mrsh/issues/131
1 files changed, 1 insertions(+), 2 deletions(-)

M shell/task/simple_command.c
M shell/task/simple_command.c => shell/task/simple_command.c +1 -2
@@ 98,7 98,6 @@ static int run_process(struct mrsh_context *ctx, struct mrsh_simple_command *sc,
 					strerror(errno));
 				exit(1);
 			}
-			close(fd);
 		}
 
 		execv(path, argv);


@@ 119,6 118,7 @@ struct saved_fd {
 
 static bool dup_and_save_fd(int fd, int redir_fd, struct saved_fd *saved) {
 	saved->redir_fd = redir_fd;
+	saved->dup_fd = -1;
 
 	if (fd == redir_fd) {
 		return true;


@@ 136,7 136,6 @@ static bool dup_and_save_fd(int fd, int redir_fd, struct saved_fd *saved) {
 			strerror(errno));
 		return false;
 	}
-	close(fd);
 
 	return true;
 }