From f923e95861eb65a29ba9ced2040abaed8add6703 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 27 Dec 2012 07:23:01 +0100 Subject: [PATCH] base-modem: don't set the modem valid if we didn't export the Modem interface If an error occurs early during the initialization (e.g. during port setup), we would be aborting without even having exported the modem interface. So detect that case and skip setting the modem as valid. --- src/mm-base-modem.c | 33 +++++++++++++++++------------ src/mm-broadband-modem.c | 45 +++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index db277097..c66ec53c 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -781,21 +781,28 @@ initialize_ready (MMBaseModem *self, { GError *error = NULL; - if (!mm_base_modem_initialize_finish (self, res, &error)) { - /* Wrong state is returned when modem is found locked */ - if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE)) - mm_dbg ("Couldn't finish initialization in the current state: '%s'", - error->message); - else - mm_warn ("couldn't initialize the modem: '%s'", error->message); - g_error_free (error); - } else + if (mm_base_modem_initialize_finish (self, res, &error)) { mm_dbg ("modem properly initialized"); + mm_base_modem_set_valid (self, TRUE); + return; + } - /* Even with initialization errors, we do set the state to valid, so - * that the modem gets exported and the failure notified to the user. - */ - mm_base_modem_set_valid (self, TRUE); + /* Wrong state is returned when modem is found locked */ + if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE)) { + /* Even with initialization errors, we do set the state to valid, so + * that the modem gets exported and the failure notified to the user. + */ + mm_dbg ("Couldn't finish initialization in the current state: '%s'", + error->message); + g_error_free (error); + mm_base_modem_set_valid (self, TRUE); + return; + } + + /* Really fatal, we cannot even export the failed modem (e.g. error before + * even trying to enable the Modem interface */ + mm_warn ("couldn't initialize the modem: '%s'", error->message); + g_error_free (error); } static inline void diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 2e8dd8f0..11bc279c 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -7643,9 +7643,8 @@ initialization_started_ready (MMBroadbandModem *self, mm_warn ("Couldn't start initialization: %s", error->message); g_error_free (error); - mm_iface_modem_update_state (MM_IFACE_MODEM (self), - MM_MODEM_STATE_FAILED, - MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); + /* There is no Modem interface yet, so just update the variable directly */ + ctx->self->priv->modem_state = MM_MODEM_STATE_FAILED; /* Just jump to the last step */ ctx->step = INITIALIZE_STEP_LAST; @@ -7880,20 +7879,32 @@ initialize_step (InitializeContext *ctx) case INITIALIZE_STEP_LAST: if (ctx->self->priv->modem_state == MM_MODEM_STATE_FAILED) { - /* Fatal SIM failure :-( */ - g_simple_async_result_set_error (ctx->result, - MM_CORE_ERROR, - MM_CORE_ERROR_WRONG_STATE, - "Modem is unusable, " - "cannot fully initialize"); - /* Ensure we only leave the Modem interface around */ - mm_iface_modem_3gpp_shutdown (MM_IFACE_MODEM_3GPP (ctx->self)); - mm_iface_modem_3gpp_ussd_shutdown (MM_IFACE_MODEM_3GPP_USSD (ctx->self)); - mm_iface_modem_cdma_shutdown (MM_IFACE_MODEM_CDMA (ctx->self)); - mm_iface_modem_location_shutdown (MM_IFACE_MODEM_LOCATION (ctx->self)); - mm_iface_modem_messaging_shutdown (MM_IFACE_MODEM_MESSAGING (ctx->self)); - mm_iface_modem_time_shutdown (MM_IFACE_MODEM_TIME (ctx->self)); - mm_iface_modem_simple_shutdown (MM_IFACE_MODEM_SIMPLE (ctx->self)); + + + if (!ctx->self->priv->modem_dbus_skeleton) { + /* Error setting up ports. Abort without even exporting the + * Modem interface */ + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_ABORTED, + "Modem is unusable, " + "cannot fully initialize"); + } else { + /* Fatal SIM failure :-( */ + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_WRONG_STATE, + "Modem is unusable, " + "cannot fully initialize"); + /* Ensure we only leave the Modem interface around */ + mm_iface_modem_3gpp_shutdown (MM_IFACE_MODEM_3GPP (ctx->self)); + mm_iface_modem_3gpp_ussd_shutdown (MM_IFACE_MODEM_3GPP_USSD (ctx->self)); + mm_iface_modem_cdma_shutdown (MM_IFACE_MODEM_CDMA (ctx->self)); + mm_iface_modem_location_shutdown (MM_IFACE_MODEM_LOCATION (ctx->self)); + mm_iface_modem_messaging_shutdown (MM_IFACE_MODEM_MESSAGING (ctx->self)); + mm_iface_modem_time_shutdown (MM_IFACE_MODEM_TIME (ctx->self)); + mm_iface_modem_simple_shutdown (MM_IFACE_MODEM_SIMPLE (ctx->self)); + } initialize_context_complete_and_free (ctx); return; }