X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=main.c;h=57c2246dfbf808c573e20c1991d127f6a3558f10;hp=5296631faea3e803f1af9666ce13dcf19dba62f2;hb=663c89819b6990c99427d1cf5b0fcae21e4201bc;hpb=0a8cbe98b0c4b2e8061abb6b1ce4593149024fb3 diff --git a/main.c b/main.c index 5296631..57c2246 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,7 @@ /* * main.c -- config file parsing and main loop for browser-switchboard * - * Copyright (C) 2009 Steven Luo + * Copyright (C) 2009-2010 Steven Luo * Derived from a Python implementation by Jason Simpson and Steven Luo * * This program is free software; you can redistribute it and/or @@ -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 */