[Spice-devel] [PATCH] server/smartcard: register channel only when hardware is available

Alon Levy alevy at redhat.com
Wed Jun 29 05:14:07 PDT 2011


---
 server/reds.c      |    4 ----
 server/smartcard.c |   11 +++++++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index e917a7c..7dc4252 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3533,10 +3533,6 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
     reds->main_channel = NULL;
     inputs_init();
 
-#ifdef USE_SMARTCARD
-    smartcard_channel_init();
-#endif
-
     reds->mouse_mode = SPICE_MOUSE_MODE_SERVER;
     atexit(reds_exit);
     return 0;
diff --git a/server/smartcard.c b/server/smartcard.c
index f948e5b..49bf3cb 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -81,6 +81,7 @@ static void smartcard_on_message_from_device(
     SmartCardChannel *smartcard_channel, VSCMsgHeader *vheader);
 static SmartCardDeviceState* smartcard_device_state_new();
 static void smartcard_device_state_free(SmartCardDeviceState* st);
+static void smartcard_register_channel(void);
 
 void smartcard_char_device_wakeup(SpiceCharDeviceInstance *sin)
 {
@@ -166,6 +167,7 @@ static int smartcard_char_device_add_to_readers(SpiceCharDeviceInstance *char_de
     }
     state->reader_id = g_smartcard_readers.num;
     g_smartcard_readers.sin[g_smartcard_readers.num++] = char_device;
+    smartcard_register_channel();
     return 0;
 }
 
@@ -534,10 +536,16 @@ static void smartcard_migrate(Channel *channel)
 {
 }
 
-void smartcard_channel_init(void)
+static void smartcard_register_channel(void)
 {
     Channel *channel;
+    static int registered = 0;
 
+    if (registered) {
+        return;
+    }
+    red_printf("registering smartcard channel");
+    registered = 1;
     channel = spice_new0(Channel, 1);
     channel->type = SPICE_CHANNEL_SMARTCARD;
     channel->link = smartcard_link;
@@ -545,4 +553,3 @@ void smartcard_channel_init(void)
     channel->migrate = smartcard_migrate;
     reds_register_channel(channel);
 }
-
-- 
1.7.5.4



More information about the Spice-devel mailing list