Permalink
Browse files

Fixed setting process title.

There's a very important comment in ruby_init_setproctitle. I'll just
quote it verbatim:

  /*
   * NB: This assumes that argv has already been copied out of the
   * way. This is true for sshd, but may not be true for other
   * programs. Beware.
   */

Nothing was saving argv and since this code does this:

  argv[1] = NULL;

it was causing a segv on Mavericks when the Agent init code was
iterating argv. Why this was not segv'ing on Linux (ie running
the CI specs on Travis) is unknown.
  • Loading branch information...
1 parent 319bba4 commit 293c8a9a835aeeb6c233181b98e50f4fea077ba2 @brixen brixen committed Jan 14, 2014
Showing with 21 additions and 3 deletions.
  1. +20 −3 vm/environment.cpp
  2. +1 −0 vm/environment.hpp
View
@@ -80,7 +80,7 @@ namespace rubinius {
Environment::Environment(int argc, char** argv)
: argc_(argc)
- , argv_(argv)
+ , argv_(0)
, signature_(0)
, version_(0)
, signal_handler_(NULL)
@@ -96,6 +96,9 @@ namespace rubinius {
VM::init_stack_size();
+ copy_argv(argc, argv);
+ ruby_init_setproctitle(argc, argv);
+
shared = new SharedState(this, config, config_parser);
load_vm_options(argc_, argv_);
@@ -135,6 +138,11 @@ namespace rubinius {
VM::discard(state, root_vm);
SharedState::discard(shared);
delete state;
+
+ for(int i = 0; i < argc_; i++) {
+ delete argv_[i];
+ }
+ delete argv_;
}
void cpp_exception_bug() {
@@ -344,6 +352,17 @@ namespace rubinius {
finalizer_handler_ = new FinalizerHandler(state);
}
+ void Environment::copy_argv(int argc, char** argv) {
+ argv_ = new char* [argc+1];
+ argv_[argc] = 0;
+
+ for(int i = 0; i < argc; i++) {
+ size_t size = strlen(argv[i]) + 1;
+ argv_[i] = new char[size];
+ strncpy(argv_[i], argv[i], size);
+ }
+ }
+
void Environment::load_vm_options(int argc, char**argv) {
/* Parse -X options from RBXOPT environment variable. We parse these
* first to permit arguments passed directly to the VM to override
@@ -440,8 +459,6 @@ namespace rubinius {
state->vm()->set_const("ARGV", ary);
- ruby_init_setproctitle(argc, argv);
-
// Now finish up with the config
if(config.print_config > 1) {
std::cout << "========= Configuration =========\n";
View
@@ -93,6 +93,7 @@ namespace rubinius {
std::string system_prefix();
bool verify_paths(std::string prefix);
bool load_signature(std::string dir);
+ void copy_argv(int argc, char** argv);
void load_vm_options(int argc, char** argv);
void load_argv(int argc, char** argv);
void load_kernel(std::string root);

0 comments on commit 293c8a9

Please sign in to comment.