From 43b72770ec5ef15723b0ee5c1901a39e23039de8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 28 Jun 2018 22:56:50 +1000 Subject: Fix wrong logic for moving filedescriptors leading to closed stdin With this fix, tests can now use /dev/null as stdin. Fixes #2165 --- src/shell_manager.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/shell_manager.cc') diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 3615567e..6aa2b31d 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -167,7 +167,12 @@ std::pair ShellManager::eval( Pipe child_stdin{not input.empty()}, child_stdout, child_stderr; pid_t pid = spawn_shell(m_shell.c_str(), cmdline, shell_context.params, kak_env, [&child_stdin, &child_stdout, &child_stderr] { - auto move = [](int oldfd, int newfd) { dup2(oldfd, newfd); close(oldfd); }; + auto move = [](int oldfd, int newfd) + { + if (oldfd == newfd) + return; + dup2(oldfd, newfd); close(oldfd); + }; if (child_stdin.read_fd() != -1) { -- cgit v1.2.3