diff --git a/vm/auxiliary_threads.cpp b/vm/auxiliary_threads.cpp index 2f2f24eebb..f364c7b5c8 100644 --- a/vm/auxiliary_threads.cpp +++ b/vm/auxiliary_threads.cpp @@ -1,4 +1,7 @@ +#include "vm.hpp" #include "prelude.hpp" +#include "environment.hpp" + #include "auxiliary_threads.hpp" namespace rubinius { @@ -36,6 +39,8 @@ namespace rubinius { ++i) { (*i)->before_exec(state); } + + state->shared().env()->before_exec(state); } void AuxiliaryThreads::after_exec(STATE) { @@ -47,6 +52,8 @@ namespace rubinius { (*i)->after_exec(state); } + state->shared().env()->after_exec(state); + exec_in_progress_ = false; } diff --git a/vm/console.cpp b/vm/console.cpp index 2e04d21849..43cd6abec7 100644 --- a/vm/console.cpp +++ b/vm/console.cpp @@ -111,6 +111,15 @@ namespace rubinius { response_path_ = path + "-response"; request_list_ = new RequestList; + + Module* mod = as(G(rubinius)->get_const(state, "Console")); + Class* cls = as(mod->get_const(state, "Server")); + console_.set(cls->send(state, 0, state->symbol("new"))); + + cls->set_const(state, state->symbol("RequestPath"), + String::create(state, request_path_.c_str())); + cls->set_const(state, state->symbol("ResponsePath"), + String::create(state, response_path_.c_str())); } static int open_file(std::string path) { @@ -123,25 +132,18 @@ namespace rubinius { return fd; } - void Console::start(STATE) { - initialize(state); - - Module* mod = as(G(rubinius)->get_const(state, "Console")); - Class* cls = as(mod->get_const(state, "Server")); - console_.set(cls->send(state, 0, state->symbol("new"))); - - cls->set_const(state, state->symbol("RequestPath"), - String::create(state, request_path_.c_str())); - cls->set_const(state, state->symbol("ResponsePath"), - String::create(state, response_path_.c_str())); - + void Console::setup_files(STATE) { request_fd_ = open_file(request_path_); response_fd_ = open_file(response_path_); FSEvent* fsevent = FSEvent::create(state); fsevent->watch_file(state, request_fd_, request_path_.c_str()); fsevent_.set(fsevent); + } + void Console::start(STATE) { + initialize(state); + setup_files(state); start_threads(state); } @@ -217,9 +219,11 @@ namespace rubinius { void Console::before_exec(STATE) { stop_threads(state); + cleanup(true); } void Console::after_exec(STATE) { + setup_files(state); start_threads(state); } diff --git a/vm/console.hpp b/vm/console.hpp index 45444746e2..c067c1fe39 100644 --- a/vm/console.hpp +++ b/vm/console.hpp @@ -54,6 +54,7 @@ namespace rubinius { void start(STATE); void initialize(STATE); + void setup_files(STATE); void run(STATE); void start_threads(STATE); diff --git a/vm/environment.cpp b/vm/environment.cpp index 3d5bc3255c..5bcc532c1c 100644 --- a/vm/environment.cpp +++ b/vm/environment.cpp @@ -314,7 +314,7 @@ namespace rubinius { path << "rbx-" << getlogin() << "-" << getpid(); shared->fsapi_path.assign(path.str()); - mkdir(shared->fsapi_path.c_str(), 0755); + create_fsapi(state); } void Environment::load_argv(int argc, char** argv) { @@ -472,6 +472,24 @@ namespace rubinius { delete cf; } + void Environment::before_exec(STATE) { + remove_fsapi(state); + } + + void Environment::after_exec(STATE) { + create_fsapi(state); + } + + void Environment::create_fsapi(STATE) { + mkdir(shared->fsapi_path.c_str(), 0755); + } + + void Environment::remove_fsapi(STATE) { + if(rmdir(shared->fsapi_path.c_str()) < 0) { + utilities::logger::error("%s: unable to remove FSAPI path", strerror(errno)); + } + } + void Environment::halt_and_exit(STATE) { halt(state); int code = exit_code(state); @@ -510,9 +528,7 @@ namespace rubinius { NativeMethod::cleanup_thread(state); - if(rmdir(shared->fsapi_path.c_str()) < 0) { - utilities::logger::error("%s: unable to remove FSAPI path", strerror(errno)); - } + remove_fsapi(state); } /** diff --git a/vm/environment.hpp b/vm/environment.hpp index d6d190002c..a5d6040bbd 100644 --- a/vm/environment.hpp +++ b/vm/environment.hpp @@ -108,10 +108,16 @@ namespace rubinius { void run_from_filesystem(); void boot_vm(); + void before_exec(STATE); + void after_exec(STATE); + void halt(STATE); void halt_and_exit(STATE); int exit_code(STATE); + void create_fsapi(STATE); + void remove_fsapi(STATE); + void start_signals(); void start_finalizer(); void start_agent(int port);