From 32801150ac9ad614f3d530cdc9200d4fd5d6964e Mon Sep 17 00:00:00 2001 From: Steven Luo Date: Sun, 14 Feb 2010 23:26:16 -0800 Subject: [PATCH 1/1] Ensure that only one browser-switchboard is active at any time When launching MicroB, during the window between the time we let go of com.nokia.osso_browser and the time MicroB picks it up, it's possible that some process issues a request for the interface, which causes D-Bus to attempt to start another copy of browser-switchboard; the results are confusing at best and (in the Fremantle case) disastrous at worst. Prevent this by trying to acquire the name org.maemo.garage.browser-switchboard from D-Bus on startup, in a manner that succeeds if and only if no one else already owns the name. This is important because the Fremantle hildon-desktop appears to sometimes insist on having a process to own com.nokia.osso_browser at all times; when it decides this is necessary, it picks up our release of the name and immediately asks D-Bus to launch another browser-switchboard, which gets in the way of our MicroB launching procedure. --- main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main.c b/main.c index 5296631..2dfe439 100644 --- a/main.c +++ b/main.c @@ -103,6 +103,7 @@ int main() { OssoBrowser *obj_osso_browser, *obj_osso_browser_req; GMainLoop *mainloop; GError *error = NULL; + int reqname_result; read_config(0); @@ -146,6 +147,27 @@ int main() { return 1; } + /* Get the org.maemo.garage.browser-switchboard name from D-Bus, as + a form of locking to ensure that not more than one + browser-switchboard process is active at any time. With + DBUS_NAME_FLAG_DO_NOT_QUEUE set and DBUS_NAME_FLAG_REPLACE_EXISTING + not set, getting the name succeeds if and only if no other + process owns the name. */ + if (!dbus_g_proxy_call(ctx.dbus_proxy, "RequestName", &error, + G_TYPE_STRING, "org.maemo.garage.browser-switchboard", + G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, + G_TYPE_INVALID, + G_TYPE_UINT, &reqname_result, + G_TYPE_INVALID)) { + printf("Couldn't acquire browser-switchboard lock: %s\n", + error->message); + return 1; + } + if (reqname_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + printf("Another browser-switchboard already running\n"); + return 1; + } + dbus_request_osso_browser_name(&ctx); /* Register ourselves to handle the osso_browser D-Bus methods */ -- 1.7.9.5