Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1768599235f9
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 524e28b92c9f
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 7, 2015

  1. Fill in standard IO file descriptors on startup.

    If the process that exec's us had closed file descriptors 0, 1, or 2, we re-open
    them to tmp files so the descriptors are allocated.
    brixen committed May 7, 2015
    Copy the full SHA
    484e652 View commit details
  2. Copy the full SHA
    524e28b View commit details
Showing with 30 additions and 0 deletions.
  1. +3 −0 vm/builtin/io.cpp
  2. +26 −0 vm/environment.cpp
  3. +1 −0 vm/environment.hpp
3 changes: 3 additions & 0 deletions vm/builtin/io.cpp
Original file line number Diff line number Diff line change
@@ -486,6 +486,9 @@ namespace rubinius {
// Invalid descriptor no matter what.
descriptor(state, Fixnum::from(-1));

// Don't close stdin, stdout, stderr descriptors.
if(desc < 3) return cNil;

// If there is a handle for this IO, and it's been promoted into
// a lowlevel RIO struct using fdopen, then we MUST use fclose
// to close it.
26 changes: 26 additions & 0 deletions vm/environment.cpp
Original file line number Diff line number Diff line change
@@ -100,6 +100,8 @@ namespace rubinius {

load_vm_options(argc_, argv_);

check_io_descriptors();

root_vm = shared->new_vm();
root_vm->metrics().init(metrics::eRubyMetrics);
state = new State(root_vm);
@@ -141,6 +143,30 @@ namespace rubinius {
std::set_terminate(cpp_exception_bug);
}

static void assign_io_descriptor(std::string dir, int std_fd, const char* desc) {
std::string path = dir + desc;

int fd = open(path.c_str(), O_CREAT | O_TRUNC | O_RDWR, 0600);
dup2(fd, std_fd);
unlink(path.c_str());
}

void Environment::check_io_descriptors() {
std::string dir = config.system_tmp.value;

if(fcntl(STDIN_FILENO, F_GETFD) < 0 && errno == EBADF) {
assign_io_descriptor(dir, STDIN_FILENO, "stdin");
}

if(fcntl(STDOUT_FILENO, F_GETFD) < 0 && errno == EBADF) {
assign_io_descriptor(dir, STDOUT_FILENO, "stdout");
}

if(fcntl(STDERR_FILENO, F_GETFD) < 0 && errno == EBADF) {
assign_io_descriptor(dir, STDERR_FILENO, "stderr");
}
}

void Environment::start_jit(STATE) {
utilities::thread::SpinLock::LockGuard lg(state->shared().llvm_state_lock());

1 change: 1 addition & 0 deletions vm/environment.hpp
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ namespace rubinius {
std::string system_prefix();
bool verify_paths(std::string prefix);
bool load_signature(std::string dir);
void check_io_descriptors();
void copy_argv(int argc, char** argv);
void log_argv();
void load_vm_options(int argc, char** argv);