dbus: fix cleanup code

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-27 14:54:09 +02:00
parent 3831c84a84
commit 2dffbe9c72
1 changed files with 24 additions and 24 deletions

48
dbus.c
View File

@ -36,6 +36,25 @@ static DBusConnection *dbus_connection_system = NULL;
ev_io dbusio_ses = { .fd = -1 }; ev_io dbusio_ses = { .fd = -1 };
ev_io dbusio_sys = { .fd = -1 }; ev_io dbusio_sys = { .fd = -1 };
static void
a_dbus_cleanup_bus(DBusConnection *dbus_connection, ev_io *dbusio)
{
if(!dbus_connection)
return;
if(dbusio->fd >= 0)
{
ev_ref(EV_DEFAULT_UC);
ev_io_stop(EV_DEFAULT_UC_ dbusio);
dbusio->fd = -1;
}
/* This is a shared connection owned by libdbus
* Do not close it, only unref
*/
dbus_connection_unref(dbus_connection);
}
static int static int
a_dbus_message_iter(DBusMessageIter *iter) a_dbus_message_iter(DBusMessageIter *iter)
{ {
@ -345,7 +364,7 @@ a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
} }
static void static void
a_dbus_process_requests_on_bus(DBusConnection *dbus_connection) a_dbus_process_requests_on_bus(DBusConnection *dbus_connection, ev_io *dbusio)
{ {
DBusMessage *msg; DBusMessage *msg;
int nmsg = 0; int nmsg = 0;
@ -359,7 +378,7 @@ a_dbus_process_requests_on_bus(DBusConnection *dbus_connection)
if(dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected")) if(dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected"))
{ {
a_dbus_cleanup(); a_dbus_cleanup_bus(dbus_connection, dbusio);
dbus_message_unref(msg); dbus_message_unref(msg);
return; return;
} }
@ -380,13 +399,13 @@ a_dbus_process_requests_on_bus(DBusConnection *dbus_connection)
static void static void
a_dbus_process_requests_session(EV_P_ ev_io *w, int revents) a_dbus_process_requests_session(EV_P_ ev_io *w, int revents)
{ {
a_dbus_process_requests_on_bus(dbus_connection_session); a_dbus_process_requests_on_bus(dbus_connection_session, w);
} }
static void static void
a_dbus_process_requests_system(EV_P_ ev_io *w, int revents) a_dbus_process_requests_system(EV_P_ ev_io *w, int revents)
{ {
a_dbus_process_requests_on_bus(dbus_connection_system); a_dbus_process_requests_on_bus(dbus_connection_system, w);
} }
static bool static bool
@ -480,7 +499,7 @@ a_dbus_connect(DBusBusType type, const char *type_name,
else else
{ {
warn("cannot get D-Bus connection file descriptor"); warn("cannot get D-Bus connection file descriptor");
a_dbus_cleanup(); a_dbus_cleanup_bus(dbus_connection, dbusio);
} }
} }
@ -496,25 +515,6 @@ a_dbus_init(void)
&dbusio_sys, a_dbus_process_requests_system); &dbusio_sys, a_dbus_process_requests_system);
} }
static void
a_dbus_cleanup_bus(DBusConnection *dbus_connection, ev_io *dbusio)
{
if(!dbus_connection)
return;
if(dbusio->fd >= 0)
{
ev_ref(EV_DEFAULT_UC);
ev_io_stop(EV_DEFAULT_UC_ dbusio);
dbusio->fd = -1;
}
/* This is a shared connection owned by libdbus
* Do not close it, only unref
*/
dbus_connection_unref(dbus_connection);
}
void void
a_dbus_cleanup(void) a_dbus_cleanup(void)
{ {