From 942fc224af403de0a73511a4e6a5dfe4bfa53b91 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 8 Jun 2015 13:34:08 +0100 Subject: Specify if ShellManager should read output or not using a flag Some program (xclip), will fork a daemon keeping stdout/stderr open, so waiting for them to be closed make kakoune hang. Commands discarding stdout can then just not wait on it. --- src/shell_manager.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/shell_manager.cc') diff --git a/src/shell_manager.cc b/src/shell_manager.cc index ce926ecb..ff483d89 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -24,7 +24,7 @@ ShellManager::ShellManager() std::pair ShellManager::eval( StringView cmdline, const Context& context, StringView input, - ConstArrayView params, const EnvVarMap& env_vars) + Flags flags, ConstArrayView params, const EnvVarMap& env_vars) { int write_pipe[2]; // child stdin int read_pipe[2]; // child stdout @@ -44,6 +44,8 @@ std::pair ShellManager::eval( close(write_pipe[1]); String child_stdout, child_stderr; + int status = 0; + bool terminated = false; { auto pipe_reader = [](String& output) { return [&output](FDWatcher& watcher, EventMode) { @@ -58,15 +60,25 @@ std::pair ShellManager::eval( FDWatcher stdout_watcher{read_pipe[0], pipe_reader(child_stdout)}; FDWatcher stderr_watcher{error_pipe[0], pipe_reader(child_stderr)}; - while (not stdout_watcher.closed() or not stderr_watcher.closed()) + if (not (flags & Flags::ReadOutput)) + { + stdout_watcher.close_fd(); + stderr_watcher.close_fd(); + } + + while (not stdout_watcher.closed() or + not stderr_watcher.closed() or + not terminated) + { EventManager::instance().handle_next_events(EventMode::Urgent); + if (not terminated) + terminated = waitpid(pid, &status, WNOHANG); + } } if (not child_stderr.empty()) write_to_debug_buffer(format("shell stderr: <<<\n{}>>>", child_stderr)); - int status = 0; - waitpid(pid, &status, 0); return { child_stdout, WIFEXITED(status) ? WEXITSTATUS(status) : - 1 }; } else try -- cgit v1.2.3