[Spice-devel] [PATCH GTK 4/4] don't attempt to use libcacard before it's inited

Marc-André Lureau marcandre.lureau at gmail.com
Tue Jul 5 04:05:13 PDT 2011


Hi

On Tue, Jul 5, 2011 at 10:37 AM, Christophe Fergeau <cfergeau at redhat.com> wrote:
> Now that libcacard initialization is run asynchronously,
> the methods to insert/remove a software smartcard need to make
> sure libcacard is initialized before trying to trigger such an
> insertion/removal. When these functions are called too early,
> the insertion/removal attempt is ignored.
> ---
>  gtk/smartcard-manager.c |   14 ++++++++++++++
>  1 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/gtk/smartcard-manager.c b/gtk/smartcard-manager.c
> index 9565840..16029c7 100644
> --- a/gtk/smartcard-manager.c
> +++ b/gtk/smartcard-manager.c
> @@ -59,6 +59,7 @@ struct spice_smartcard_manager {
>      */
>  #ifdef USE_SMARTCARD
>     VReader *software_reader;
> +    gboolean libcacard_inited;
>  #endif
>  };
>
> @@ -389,6 +390,14 @@ gboolean spice_smartcard_reader_is_software(SpiceSmartCardReader *reader)
>     return (strcmp(vreader_get_name((VReader*)reader), SPICE_SOFTWARE_READER_NAME) == 0);
>  }
>
> +static gboolean spice_libcacard_inited(G_GNUC_UNUSED gpointer data)
> +{
> +    SpiceSmartCardManager *manager = spice_smartcard_manager_get();
> +
> +    manager->priv->libcacard_inited = TRUE;
> +    return FALSE;
> +}
> +
>  static gpointer spice_vcard_emul_init_thread(gpointer data)
>  {
>     VCardEmulError error;
> @@ -398,6 +407,7 @@ static gpointer spice_vcard_emul_init_thread(gpointer data)
>     if (error != VCARD_EMUL_OK) {
>         g_critical("vcard_emul_init() failed: %d", error);
>     }
> +    g_idle_add(spice_libcacard_inited, NULL);
>
>     return NULL;
>  }
> @@ -460,6 +470,8 @@ gboolean spice_smartcard_manager_insert_card(SpiceSmartCardManager *manager)
>     VCardEmulError status;
>
>     g_return_val_if_fail(manager->priv->software_reader != NULL, FALSE);
> +    if (!manager->priv->libcacard_inited)
> +        return FALSE;
>
>     status = vcard_emul_force_card_insert(manager->priv->software_reader);
>
> @@ -471,6 +483,8 @@ gboolean spice_smartcard_manager_remove_card(SpiceSmartCardManager *manager)
>     VCardEmulError status;
>
>     g_return_val_if_fail(manager->priv->software_reader != NULL, FALSE);
> +    if (!manager->priv->libcacard_inited)
> +        return FALSE;

We could use a debug message here.

-- 
Marc-André Lureau


More information about the Spice-devel mailing list