From 7be6c3e91de918152fe58c8e13d08963b7c7fe8a Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 7 Aug 2015 14:32:53 +0200 Subject: [PATCH] Gave up on being able to call more complex commands. Should work without crashes now. --- src/notebook.cc | 1 + src/terminal.cc | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index f33037f..e77e000 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -120,6 +120,7 @@ bool Notebook::save(int page) { Singleton::terminal()->print("File saved to: " +view->file_path+"\n"); //If CMakeLists.txt have been modified: + //TODO: recreate cmake even without directories open? if(boost::filesystem::path(view->file_path).filename().string()=="CMakeLists.txt") { if(directories.cmake && directories.cmake->project_path!="" && boost::filesystem::path(view->file_path)>=directories.cmake->project_path && CMake::create_compile_commands(directories.cmake->project_path.string())) { directories.open_folder(); diff --git a/src/terminal.cc b/src/terminal.cc index 8f7b2b8..7bbf668 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -57,6 +57,7 @@ pid_t popen3(const char *command, int *input_descriptor, int *output_descriptor, close(p_stderr[0]); dup2(p_stderr[1], 2); + //setpgid(0, 0); //TODO: get this working so we can execute without calling exec from sh -c (in that way we can call more complex commands) execl("/bin/sh", "sh", "-c", command, NULL); perror("execl"); exit(1); @@ -240,15 +241,19 @@ void Terminal::async_execute(const std::string &command, const std::string &path void Terminal::kill_executing() { async_and_sync_execute_mutex.lock(); + int status; for(auto &pid: async_execute_descriptors) { - kill(pid.first, SIGTERM); //signal_execl_exit is not always called after kill! Hence the following lines: close(async_execute_descriptors.at(pid.first)[0]); close(async_execute_descriptors.at(pid.first)[1]); close(async_execute_descriptors.at(pid.first)[2]); - int status; - while (waitpid(pid.first, &status, WNOHANG) > 0) {} + kill(pid.first, SIGTERM); //signal_execl_exit is not always called after kill! + while(waitpid(pid.first, &status, WNOHANG) > 0) {} async_execute_status[pid.first]=status; } + /*for(auto &pid: async_execute_descriptors) { + kill(-pid.first, SIGTERM); + while(waitpid(-pid.first, &status, WNOHANG) > 0) {} + }*/ async_and_sync_execute_mutex.unlock(); }