stripe/einhorn — pull request #9 by ebroder (2012-08-20 00:04:24+00:00)
Title: Store the environment at startup and restore it before reexecing

This makes sure that pre-loaded code isn't able to change the
environment in ways that impact subsequent restarts of einhorn (for
instance by repointing bundler to look at a different Gemfile).

Fixes einhorn issue #7

reviewer: @gdb

I'd love to add tests for this, but I'm not really sure how to set it all up, given the number of moving parts involved. To test by hand, the following script will throw during preloading when run without my patch:

```ruby
require 'einhorn/client'

raise "Environment changes were preserved" if ENV.include?("SPECIAL_EINHORN_TEST_ENV")
# This should go away the next time einhorn is reloaded
ENV["SPECIAL_EINHORN_TEST_ENV"] = "hello"

def einhorn_main
# Sit around doing nothing, then trigger an upgrade
IO.select([], [], [], 1)

client = Einhorn::Client.for_path(ENV['EINHORN_SOCK_PATH'])
client.command({'command' => 'upgrade'})
end
```