dbus-c++: add acquire_name method to Connection class

Our daemons would like to acquire a D-Bus name, or exit if the
name is not available. This will guarantee that at most one instance
of a daemon is running at any given time. (More precisely: the
guarantee will be that no more than one process of each daemon has
continued past its D-Bus setup code.)

Unfortunately, the existing request_name method doesn't tell
us whether or not our request succeeded. Add a new method that
does.

If our request_name attempt fails, the new method also pings
the current owner of the name. This updates dbus-daemon's
knowledge of whether or not that owner is alive. After this,
we retry request_name once.

The ping and retry should avoid a potential race, where a
name owner has terminated abruptly, and our name request
is processed by dbus-daemon before it realizes the name
owner has exited.

BUG=chromium:356874
TEST=network_TwoShills, manual

Manual test
-----------
- build shill with this patch and CL:195012
- install the new shill and dbus-c++

// when the old shill answers the d-bus ping, the new shill
// aborts.
dut# pid=$(pgrep shill)
dut# (kill -STOP $pid; sleep 10; kill -CONT $pid) & (time /usr/bin/shill --foreground; /usr/local/lib/flimflam/test/list-active-service | head -1)
[...]
[0416/151422:FATAL:dbus_control.cc(94)] Failed to acquire D-Bus name org.chromium.flimflam. Is another shill running?
[...]
real    0m10.041s
user    0m0.008s
sys     0m0.013s
[ /service/1 ]

// if the old shill times out the d-bus ping, the new shill
// still aborts. (the old shill may be hung, but we should
// deal with that some other way.)
dut# kill -STOP $pid & (time /usr/bin/shill --foreground; kill -CONT $pid; /usr/local/lib/flimflam/test/list-active-service | head -1)
[...]
[0416/151554:FATAL:dbus_control.cc(94)] Failed to acquire D-Bus name org.chromium.flimflam. Is another shill running?
real    0m25.086s
user    0m0.015s
sys     0m0.008s
[ /service/1 ]

// if the old shill dies in the middle of the ping, the new
// shill takes over.
Wed Apr 16 16:13:42 PDT 2014
2014-04-16T16:13:42.100291-07:00 localhost shill: [0416/161342:INFO:manager.cc(197)] Manager started.
[ /service/1 ]

Change-Id: I95b10747750bd0c983ca91b9f4fbaf2c8ed3b8cf
Reviewed-on: https://chromium-review.googlesource.com/195002
Tested-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Commit-Queue: mukesh agrawal <quiche@chromium.org>
2 files changed