Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dsme] Avoid recursion during dsmesock disconnecting. JB#38474
Some dsmesock disconnect issues were found from mce code tree. As the
usb-moded code is derived from mce, similar fixes need to be made also
here.

Avoid recursive process watchdog quits during disconnect by doing the
quitting only once / connect after removal of socket io watch.

Drop reconnect attempts on I/O error situations as they are unlikely
to do any good and can lead to further recursive behavior.

Do not initiate new dsmesock connections while device is shutting down.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Apr 26, 2017
1 parent eefc64c commit fba9d87
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/usb_moded-dsme.c
Expand Up @@ -98,7 +98,6 @@ static gboolean dsme_socket_recv_cb (GIOChannel *sou
static bool dsme_socket_is_connected (void);
static bool dsme_socket_connect (void);
static void dsme_socket_disconnect (void);
static void dsme_socket_reconnect (void);

/* ------------------------------------------------------------------------- *
* DSME_DBUS_IPC
Expand Down Expand Up @@ -273,6 +272,9 @@ dsme_state_update(dsme_state_t state)
dsme_shutdown_state = shutdown_state;
log_debug("in shutdown: %s", dsme_shutdown_state ? "true" : "false");

/* Re-evaluate dsmesock connection */
if( !dsme_shutdown_state )
dsme_socket_connect();
}
}

Expand Down Expand Up @@ -324,10 +326,6 @@ dsme_socket_send_message(gpointer msg, const char *request_name)
if( dsmesock_send(dsme_socket_con, msg) == -1) {
log_err("failed to send %s to dsme; %m",
request_name);

/* close and try to re-connect */
dsme_socket_reconnect();
goto EXIT;
}

log_debug("%s sent to DSME", request_name);
Expand Down Expand Up @@ -477,6 +475,14 @@ dsme_socket_connect(void)
{
GIOChannel *iochan = NULL;

/* No new connections during shutdown */
if( dsme_state_is_shutdown() )
goto EXIT;

/* No new connections uness dsme dbus service is available */
if( !dsme_dbus_name_owner_available() )
goto EXIT;

/* Already connected ? */
if( dsme_socket_iowatch )
goto EXIT;
Expand Down Expand Up @@ -521,33 +527,22 @@ dsme_socket_connect(void)
static void
dsme_socket_disconnect(void)
{
if( dsme_socket_is_connected() )
dsme_socket_processwd_quit();

if( dsme_socket_iowatch ) {
log_debug("Removing DSME socket notifier");
g_source_remove(dsme_socket_iowatch);
dsme_socket_iowatch = 0;

/* Still having had a live socket notifier means we have
* initiated the dsmesock disconnect and need to deactivate
* the process watchdog before actually disconnecting */
dsme_socket_processwd_quit();
}

if( dsme_socket_con ) {
log_debug("Closing DSME socket");
dsmesock_close(dsme_socket_con);
dsme_socket_con = 0;
}

// FIXME: should we assume something about the system state?
}

/** Close dsmesock connection and reconnect if/when dsme is available
*/
static void
dsme_socket_reconnect(void)
{
dsme_socket_disconnect();

if( dsme_dbus_name_owner_available() && !dsme_state_is_shutdown() )
dsme_socket_connect();
}

/* ========================================================================= *
Expand Down

0 comments on commit fba9d87

Please sign in to comment.