Prevent multiple instances of cros-disks from running.
DBus::Connection::request_name() does not indicate whether it
successfully acquires the requested DBus name or not. This CL changes
cros-disks to use newly introduced DBus::Connection::acquire_name()
(CL:195002) to ensure that cros-disks can successfully acquire its DBus
name.
BUG=chromium:364585
TEST=Tested the following:
1. `FEATURES=test emerge-$BOARD platform2`
2. Manually run the following commands in a root shell on the DUT:
- `stop cros-disks` and then `start cros-disks` works
- `restart cros-disks` works
- `/opt/google/cros-disks/disks --foreground` fails to acquire the
DBus name when another instance of cros-disks is already running.
Change-Id: Ifa29fe403e7af78bfbb9e2cfe9e8cfe48b2c54b4
Reviewed-on: https://chromium-review.googlesource.com/195456
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
diff --git a/cros_disks_server.h b/cros_disks_server.h
index de2d4eb..9978d36 100644
--- a/cros_disks_server.h
+++ b/cros_disks_server.h
@@ -29,7 +29,7 @@
// Example Usage:
//
// DBus::Connection server_conn = DBus::Connection::SystemBus();
-// server_conn.request_name("org.chromium.CrosDisks");
+// CHECK(server_conn.acquire_name("org.chromium.CrosDisks"));
// ArchiveManager archive_manager(...);
// DiskManager disk_manager(...);
// FormatManager format_manager;
diff --git a/main.cc b/main.cc
index 0ad1cb5..b705841 100644
--- a/main.cc
+++ b/main.cc
@@ -132,7 +132,9 @@
LOG(INFO) << "Creating the cros-disks server";
DBus::Connection server_conn = DBus::Connection::SystemBus();
- server_conn.request_name(cros_disks::kCrosDisksServiceName);
+ CHECK(server_conn.acquire_name(cros_disks::kCrosDisksServiceName))
+ << "Failed to acquire D-Bus name " << cros_disks::kCrosDisksServiceName;
+
Daemon daemon(&server_conn);
daemon.Initialize();