Merge lp:~thomas-voss/dbus-cpp/adjust-fixture-to-correctly-replace-dbus-env-vars into lp:dbus-cpp

Proposed by Thomas Voß
Status: Merged
Approved by: Loïc Minier
Approved revision: 76
Merged at revision: 76
Proposed branch: lp:~thomas-voss/dbus-cpp/adjust-fixture-to-correctly-replace-dbus-env-vars
Merge into: lp:dbus-cpp
Diff against target: 64 lines (+36/-4)
1 file modified
src/core/dbus/fixture.cpp.in (+36/-4)
To merge this branch: bzr merge lp:~thomas-voss/dbus-cpp/adjust-fixture-to-correctly-replace-dbus-env-vars
Reviewer Review Type Date Requested Status
Loïc Minier Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+234942@code.launchpad.net

Commit message

Factor out dbus-specific environment variable names into compile-time constants.
Make sure that environment variables are unset prior to setting.

Description of the change

Factor out dbus-specific environment variable names into compile-time constants.
Make sure that environment variables are unset prior to setting.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/dbus/fixture.cpp.in'
2--- src/core/dbus/fixture.cpp.in 2014-06-29 05:29:15 +0000
3+++ src/core/dbus/fixture.cpp.in 2014-09-17 10:25:25 +0000
4@@ -23,6 +23,29 @@
5 #include <core/posix/exec.h>
6 #include <core/posix/this_process.h>
7
8+namespace
9+{
10+static constexpr const char* dbus_session_bus_address
11+{
12+ "DBUS_SESSION_BUS_ADDRESS"
13+};
14+
15+static constexpr const char* dbus_system_bus_address
16+{
17+ "DBUS_SYSTEM_BUS_ADDRESS"
18+};
19+
20+static constexpr const char* dbus_starter_address
21+{
22+ "DBUS_STARTER_ADDRESS"
23+};
24+
25+static constexpr const char* dbus_starter_bus_type
26+{
27+ "DBUS_STARTER_BUS_TYPE"
28+};
29+}
30+
31 struct core::dbus::Fixture::Private
32 {
33 struct Session
34@@ -56,9 +79,15 @@
35 if (address.empty())
36 throw std::runtime_error("Session: Could not read address of bus instance.");
37
38- core::posix::this_process::env::set_or_throw("DBUS_SESSION_BUS_ADDRESS", address);
39- core::posix::this_process::env::set_or_throw("DBUS_STARTER_ADDRESS", address);
40- core::posix::this_process::env::set_or_throw("DBUS_STARTER_BUS_TYPE", "session");
41+ // We clean up the env prior to injecting the new addresses.
42+ std::error_code ec; // And just ignore all error codes.
43+ core::posix::this_process::env::unset(dbus_session_bus_address, ec);
44+ core::posix::this_process::env::unset(dbus_starter_address, ec);
45+ core::posix::this_process::env::unset(dbus_starter_bus_type, ec);
46+
47+ core::posix::this_process::env::set_or_throw(dbus_session_bus_address, address);
48+ core::posix::this_process::env::set_or_throw(dbus_starter_address, address);
49+ core::posix::this_process::env::set_or_throw(dbus_starter_bus_type, "session");
50 }
51
52 ~Session()
53@@ -108,7 +137,10 @@
54 if (address.empty())
55 throw std::runtime_error("System: Could not read address of bus instance.");
56
57- core::posix::this_process::env::set_or_throw("DBUS_SYSTEM_BUS_ADDRESS", address);
58+ // We clean up the env prior to injecting the new addresses.
59+ std::error_code ec; // And just ignore all error codes.
60+ core::posix::this_process::env::unset(dbus_system_bus_address, ec);
61+ core::posix::this_process::env::set_or_throw(dbus_system_bus_address, address);
62 }
63
64 ~System()

Subscribers

People subscribed via source and target branches