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.
This commit is contained in:
Aleksander Morgado
2012-12-27 07:23:01 +01:00
parent 4ffa871228
commit f923e95861
2 changed files with 48 additions and 30 deletions

View File

@@ -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;
}
/* 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

View File

@@ -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,6 +7879,17 @@ initialize_step (InitializeContext *ctx)
case INITIALIZE_STEP_LAST:
if (ctx->self->priv->modem_state == MM_MODEM_STATE_FAILED) {
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,
@@ -7894,6 +7904,7 @@ initialize_step (InitializeContext *ctx)
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;
}