Skip to content

Commit

Permalink
better dbus bind handling
Browse files Browse the repository at this point in the history
do a retry count with sleep to bind to dbus and give up after 5 retries.
don't do a assert through g_error in case of binding error
  • Loading branch information
poelzi committed Nov 9, 2011
1 parent d6f0603 commit c5c675f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/core.c
Expand Up @@ -1786,6 +1786,7 @@ int u_dbus_setup();

int core_init() {
// load config
int i;
iteration = 1;
filter_list = NULL;

Expand All @@ -1804,8 +1805,24 @@ int core_init() {


#ifdef ENABLE_DBUS
if(!u_dbus_setup())
g_warning("failed to setup dbus");
for(i = 1; TRUE; i++) {
if(u_dbus_setup())
break;
else {
if(i > U_DBUS_RETRY_COUNT) {
#ifdef DEVELOP_MODE
g_warning("failed to setup dbus");
break;
#else
g_warning("give up requesting dbus name. exit");
exit(1);
#endif
} else {
usleep(U_DBUS_RETRY_WAIT);
}
}

}
#endif

#ifdef POLKIT_FOUND
Expand Down Expand Up @@ -1847,6 +1864,8 @@ int core_init() {
}

void core_unload() {
lua_gc (lua_main_state, LUA_GCCOLLECT, 0);
if(lua_main_state) {
lua_gc (lua_main_state, LUA_GCCOLLECT, 0);
}
}

3 changes: 2 additions & 1 deletion src/dbus.c
Expand Up @@ -764,7 +764,8 @@ gboolean u_dbus_setup() {
}
#else
if (dbus_bus_request_name(c, U_DBUS_SERVICE_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
g_error("daemon already running, can't request: %s", U_DBUS_SERVICE_NAME);
g_warning("daemon already running, can't request: %s", U_DBUS_SERVICE_NAME);
goto fail;
}
#endif

Expand Down

0 comments on commit c5c675f

Please sign in to comment.