Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dbus] Block suspend while sending or dispatching D-Bus messages. Con…
…tributes to JB#32462

There are no guarantees that dbus messages sent to/from mce are actually
delivered before the device suspends.

Make the possibility of hiccups smaller by blocking suspend
a) while dispatching incoming dbus messages internally
b) for one second after sending outgoing dbus messages
  • Loading branch information
spiiroin committed Oct 9, 2015
1 parent 1b5a256 commit 7e0f6f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .depend
Expand Up @@ -145,6 +145,7 @@ mce-dbus.o:\
mce-dbus.h\
mce-lib.h\
mce-log.h\
mce-wakelock.h\
mce.h\

mce-dbus.pic.o:\
Expand All @@ -154,6 +155,7 @@ mce-dbus.pic.o:\
mce-dbus.h\
mce-lib.h\
mce-log.h\
mce-wakelock.h\
mce.h\

mce-dsme.o:\
Expand Down
15 changes: 15 additions & 0 deletions mce-dbus.c
Expand Up @@ -26,6 +26,7 @@
#include "mce.h"
#include "mce-log.h"
#include "mce-lib.h"
#include "mce-wakelock.h"

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -37,6 +38,9 @@

#include <mce/dbus-names.h>

/** How long to block late suspend when mce is sending dbus messages */
#define MCE_DBUS_SEND_SUSPEND_BLOCK_MS 1000

static bool introspectable_signal(const char *interface, const char *member);

/** Placeholder for any basic dbus data type */
Expand Down Expand Up @@ -438,6 +442,8 @@ gboolean dbus_send_message(DBusMessage *const msg)
{
gboolean status = FALSE;

mce_wakelock_obtain("dbus_send", MCE_DBUS_SEND_SUSPEND_BLOCK_MS);

if (dbus_connection_send(dbus_connection, msg, NULL) == FALSE) {
mce_log(LL_CRIT,
"Out of memory when sending D-Bus message");
Expand Down Expand Up @@ -475,6 +481,8 @@ dbus_send_message_with_reply_handler(DBusMessage *const msg,
if( !msg )
goto EXIT;

mce_wakelock_obtain("dbus_send", MCE_DBUS_SEND_SUSPEND_BLOCK_MS);

if( !dbus_connection_send_with_reply(dbus_connection, msg, &pc, -1) ) {
mce_log(LL_CRIT, "Out of memory when sending D-Bus message");
goto EXIT;
Expand Down Expand Up @@ -1792,6 +1800,8 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection,
(void)connection;
(void)user_data;

mce_wakelock_obtain("dbus_recv", -1);

guint status = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
int type = dbus_message_get_type(msg);

Expand Down Expand Up @@ -1857,6 +1867,9 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection,
mce_dbus_squeeze_slist(&dbus_handlers);

EXIT:

mce_wakelock_release("dbus_recv");

return status;
}

Expand Down Expand Up @@ -3534,6 +3547,8 @@ mce_dbus_nameowner_query_req(const char *name)
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);

mce_wakelock_obtain("dbus_send", MCE_DBUS_SEND_SUSPEND_BLOCK_MS);

if( !dbus_connection_send_with_reply(dbus_connection, req, &pc, -1) )
goto EXIT;

Expand Down

0 comments on commit 7e0f6f9

Please sign in to comment.