From fba9d870386ab32e8c804c7a6fa65bfc12d8e252 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Wed, 26 Apr 2017 20:32:16 +0300 Subject: [PATCH] [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 --- src/usb_moded-dsme.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/usb_moded-dsme.c b/src/usb_moded-dsme.c index d8ed906..579593b 100644 --- a/src/usb_moded-dsme.c +++ b/src/usb_moded-dsme.c @@ -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 @@ -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(); } } @@ -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); @@ -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; @@ -521,13 +527,15 @@ 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 ) { @@ -535,19 +543,6 @@ dsme_socket_disconnect(void) 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(); } /* ========================================================================= *