+ log_msg("Couldn't get an org.freedesktop.DBus proxy\n");
+ 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)) {
+ log_msg("Couldn't acquire browser-switchboard lock: %s\n",
+ error->message);
+ return 1;
+ }
+ if (reqname_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+ log_msg("Another browser-switchboard already running\n");
+ return 1;
+ }
+
+ /* Get a connection to the D-Bus system bus */
+ ctx.system_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (!ctx.system_bus) {
+ log_msg("Couldn't get a D-Bus system bus connection\n");
+ return 1;
+ }
+ ctx.dbus_system_proxy = dbus_g_proxy_new_for_name(ctx.system_bus,
+ "org.freedesktop.DBus", "/org/freedesktop/DBus",
+ "org.freedesktop.DBus");
+ if (!ctx.dbus_system_proxy) {
+ log_msg("Couldn't get an org.freedesktop.DBus proxy\n");