From: Mikko Rasa Date: Sat, 19 Dec 2009 14:54:33 +0000 (+0000) Subject: Prompt to terminate target process in exit command if it's still running X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2f49929fc383eab718b5fb64d966535b753e7024;p=gldbg.git Prompt to terminate target process in exit command if it's still running --- diff --git a/source/commandinterpreter.cpp b/source/commandinterpreter.cpp index 9660aaa..abc9dda 100644 --- a/source/commandinterpreter.cpp +++ b/source/commandinterpreter.cpp @@ -6,6 +6,7 @@ Distributed under the GPL */ #include +#include #include #include #include @@ -155,7 +156,20 @@ void CommandInterpreter::cmd_kill(const string &) void CommandInterpreter::cmd_exit(const string &) { - gldbg.quit(); + if(gldbg.get_process().get_state()!=Process::INACTIVE) + { + IO::print("Program is still running. Kill it?\n"); + char *answer = readline("[y/n] "); + if(answer[0]=='y') + { + gldbg.get_process().kill(); + gldbg.quit(true); + } + else + IO::print("Not confirmed.\n"); + } + else + gldbg.quit(false); } void CommandInterpreter::cmd_trace(const string &args) diff --git a/source/gldbg.cpp b/source/gldbg.cpp index d2ca85e..34e616f 100644 --- a/source/gldbg.cpp +++ b/source/gldbg.cpp @@ -66,9 +66,9 @@ void GlDbg::launch() close(fds[1]); } -void GlDbg::quit() +void GlDbg::quit(bool force) { - if(process.get_state()!=Process::INACTIVE) + if(!force && process.get_state()!=Process::INACTIVE) throw InvalidState("Program is still running"); exit(0); } diff --git a/source/gldbg.h b/source/gldbg.h index ff84451..5654715 100644 --- a/source/gldbg.h +++ b/source/gldbg.h @@ -39,7 +39,7 @@ public: GlState &get_glstate() { return glstate; } Process &get_process() { return process; } void launch(); - void quit(); + void quit(bool); private: void tick(); void check_child();