Skip to content

Commit

Permalink
Merge branch 'jb38474_dsmesock_disconnect' into 'master'
Browse files Browse the repository at this point in the history
Avoid recursion during dsmesock disconnecting

See merge request !27
  • Loading branch information
spiiroin committed May 5, 2017
2 parents eefc64c + fba9d87 commit 5d012cd
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 5d012cd

Please sign in to comment.