Skip to content

Commit

Permalink
Clean up FSAPI before exec().
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Sep 2, 2014
1 parent eabd8e1 commit 0bbc4ed
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
7 changes: 7 additions & 0 deletions vm/auxiliary_threads.cpp
@@ -1,4 +1,7 @@
#include "vm.hpp"
#include "prelude.hpp"
#include "environment.hpp"

#include "auxiliary_threads.hpp"

namespace rubinius {
Expand Down Expand Up @@ -36,6 +39,8 @@ namespace rubinius {
++i) {
(*i)->before_exec(state);
}

state->shared().env()->before_exec(state);
}

void AuxiliaryThreads::after_exec(STATE) {
Expand All @@ -47,6 +52,8 @@ namespace rubinius {
(*i)->after_exec(state);
}

state->shared().env()->after_exec(state);

exec_in_progress_ = false;
}

Expand Down
28 changes: 16 additions & 12 deletions vm/console.cpp
Expand Up @@ -111,6 +111,15 @@ namespace rubinius {
response_path_ = path + "-response";

request_list_ = new RequestList;

Module* mod = as<Module>(G(rubinius)->get_const(state, "Console"));
Class* cls = as<Class>(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) {
Expand All @@ -123,25 +132,18 @@ namespace rubinius {
return fd;
}

void Console::start(STATE) {
initialize(state);

Module* mod = as<Module>(G(rubinius)->get_const(state, "Console"));
Class* cls = as<Class>(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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions vm/console.hpp
Expand Up @@ -54,6 +54,7 @@ namespace rubinius {

void start(STATE);
void initialize(STATE);
void setup_files(STATE);
void run(STATE);

void start_threads(STATE);
Expand Down
24 changes: 20 additions & 4 deletions vm/environment.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions vm/environment.hpp
Expand Up @@ -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);
Expand Down

0 comments on commit 0bbc4ed

Please sign in to comment.