diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 9469a30aa0..ff4cf3fd00 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -273,7 +273,7 @@ fixup_bundle_environment (int argc, char* argv[]) return; } - global_epa = new EnvironmentalProtectionAgency; + EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency); Glib::ustring exec_path = argv[0]; Glib::ustring dir_path = Glib::path_get_dirname (Glib::path_get_dirname (exec_path)); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index e01fc97470..3e08023fc0 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -1125,12 +1125,14 @@ AudioEngine::connect_to_jack (string client_name) const char *server_name = NULL; EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa (); - EnvironmentalProtectionAgency current_epa; // saves current settings and restores on exit from this scope + EnvironmentalProtectionAgency current_epa (false); /* revert all environment settings back to whatever they were when ardour started */ if (global_epa) { + current_epa.arm (); + current_epa.save (); global_epa->restore (); } diff --git a/libs/pbd/epa.cc b/libs/pbd/epa.cc index 71387b4c23..8665823d77 100644 --- a/libs/pbd/epa.cc +++ b/libs/pbd/epa.cc @@ -29,14 +29,25 @@ using namespace std; EnvironmentalProtectionAgency* EnvironmentalProtectionAgency::_global_epa = 0; -EnvironmentalProtectionAgency::EnvironmentalProtectionAgency () +EnvironmentalProtectionAgency::EnvironmentalProtectionAgency (bool arm) + : _armed (arm) { - save (); + if (_armed) { + save (); + } } EnvironmentalProtectionAgency::~EnvironmentalProtectionAgency() { - restore (); + if (_armed) { + restore (); + } +} + +void +EnvironmentalProtectionAgency::arm () +{ + _armed = true; } void @@ -63,9 +74,9 @@ EnvironmentalProtectionAgency::save () } } void -EnvironmentalProtectionAgency::restore () +EnvironmentalProtectionAgency::restore () const { - for (map::iterator i = e.begin(); i != e.end(); ++i) { + for (map::const_iterator i = e.begin(); i != e.end(); ++i) { cerr << "Restore [" << i->first << "] = " << i->second << endl; setenv (i->first.c_str(), i->second.c_str(), 1); } diff --git a/libs/pbd/pbd/epa.h b/libs/pbd/pbd/epa.h index 39773313ec..b2708fbd4c 100644 --- a/libs/pbd/pbd/epa.h +++ b/libs/pbd/pbd/epa.h @@ -27,16 +27,18 @@ namespace PBD { class EnvironmentalProtectionAgency { public: - EnvironmentalProtectionAgency (); + EnvironmentalProtectionAgency (bool arm=true); ~EnvironmentalProtectionAgency (); - void restore (); + void arm (); void save (); + void restore () const; static EnvironmentalProtectionAgency* get_global_epa () { return _global_epa; } static void set_global_epa (EnvironmentalProtectionAgency* epa) { _global_epa = epa; } private: + bool _armed; std::map e; static EnvironmentalProtectionAgency* _global_epa; };