[spice-server 2/4] Replace spice_printerr() use with red_channel_{debug, warning}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Depending on the context, we want to output a warning or just a debug
log.
---
 server/dcc.c                      |  6 +++--
 server/inputs-channel-client.c    |  3 ++-
 server/inputs-channel.c           |  6 ++---
 server/main-channel-client.c      | 42 ++++++++++++++++++-------------
 server/main-channel.c             | 10 +++++---
 server/red-channel-client.c       | 22 +++++++++-------
 server/smartcard-channel-client.c |  5 ++--
 server/smartcard.c                |  6 +++--
 server/sound.c                    | 21 ++++++++++------
 server/spicevmc.c                 | 15 +++++++----
 10 files changed, 83 insertions(+), 53 deletions(-)

diff --git a/server/dcc.c b/server/dcc.c
index d96f1b2b7..a5d2b344a 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -693,7 +693,8 @@ RedPipeItem *dcc_gl_scanout_item_new(RedChannelClient *rcc, void *data, int num)
     /* FIXME: on !unix peer, start streaming with a video codec */
     if (!red_stream_is_plain_unix(red_channel_client_get_stream(rcc)) ||
         !red_channel_client_test_remote_cap(rcc, SPICE_DISPLAY_CAP_GL_SCANOUT)) {
-        spice_printerr("FIXME: client does not support GL scanout");
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "FIXME: client does not support GL scanout");
         red_channel_client_disconnect(rcc);
         return NULL;
     }
@@ -712,7 +713,8 @@ RedPipeItem *dcc_gl_draw_item_new(RedChannelClient *rcc, void *data, int num)
 
     if (!red_stream_is_plain_unix(red_channel_client_get_stream(rcc)) ||
         !red_channel_client_test_remote_cap(rcc, SPICE_DISPLAY_CAP_GL_SCANOUT)) {
-        spice_printerr("FIXME: client does not support GL scanout");
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "FIXME: client does not support GL scanout");
         red_channel_client_disconnect(rcc);
         return NULL;
     }
diff --git a/server/inputs-channel-client.c b/server/inputs-channel-client.c
index 25ad64a62..5fd818a17 100644
--- a/server/inputs-channel-client.c
+++ b/server/inputs-channel-client.c
@@ -49,7 +49,8 @@ inputs_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
                                         uint16_t type, uint32_t size)
 {
     if (size > RECEIVE_BUF_SIZE) {
-        spice_printerr("error: too large incoming message");
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "error: too large incoming message");
         return NULL;
     }
 
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index 3f6fae812..e01bb7d0f 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -606,7 +606,7 @@ static SpiceKbdInstance* inputs_channel_get_keyboard(InputsChannel *inputs)
 int inputs_channel_set_keyboard(InputsChannel *inputs, SpiceKbdInstance *keyboard)
 {
     if (inputs->keyboard) {
-        spice_printerr("already have keyboard");
+        red_channel_warning(RED_CHANNEL(inputs), "already have keyboard");
         return -1;
     }
     inputs->keyboard = keyboard;
@@ -622,7 +622,7 @@ static SpiceMouseInstance* inputs_channel_get_mouse(InputsChannel *inputs)
 int inputs_channel_set_mouse(InputsChannel *inputs, SpiceMouseInstance *mouse)
 {
     if (inputs->mouse) {
-        spice_printerr("already have mouse");
+        red_channel_warning(RED_CHANNEL(inputs), "already have mouse");
         return -1;
     }
     inputs->mouse = mouse;
@@ -638,7 +638,7 @@ static SpiceTabletInstance* inputs_channel_get_tablet(InputsChannel *inputs)
 int inputs_channel_set_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet)
 {
     if (inputs->tablet) {
-        spice_printerr("already have tablet");
+        red_channel_warning(RED_CHANNEL(inputs), "already have tablet");
         return -1;
     }
     inputs->tablet = tablet;
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 6617f1393..b1e5a3e8b 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -528,9 +528,10 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping,
         mcc->priv->net_test_id = 0;
         if (roundtrip <= mcc->priv->latency) {
             // probably high load on client or server result with incorrect values
-            spice_printerr("net test: invalid values, latency %" PRIu64
-                           " roundtrip %" PRIu64 ". assuming high"
-                           "bandwidth", mcc->priv->latency, roundtrip);
+            red_channel_debug(red_channel_client_get_channel(rcc),
+                              "net test: invalid values, latency %" PRIu64
+                              " roundtrip %" PRIu64 ". assuming high"
+                              "bandwidth", mcc->priv->latency, roundtrip);
             mcc->priv->latency = 0;
             mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID;
             red_channel_client_start_connectivity_monitoring(rcc,
@@ -540,19 +541,21 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping,
         mcc->priv->bitrate_per_sec = (uint64_t)(NET_TEST_BYTES * 8) * 1000000
             / (roundtrip - mcc->priv->latency);
         mcc->priv->net_test_stage = NET_TEST_STAGE_COMPLETE;
-        spice_printerr("net test: latency %f ms, bitrate %"PRIu64" bps (%f Mbps)%s",
-                       (double)mcc->priv->latency / 1000,
-                       mcc->priv->bitrate_per_sec,
-                       (double)mcc->priv->bitrate_per_sec / 1024 / 1024,
-                       main_channel_client_is_low_bandwidth(mcc) ? " LOW BANDWIDTH" : "");
+        red_channel_debug(red_channel_client_get_channel(rcc),
+                          "net test: latency %f ms, bitrate %"PRIu64" bps (%f Mbps)%s",
+                          (double)mcc->priv->latency / 1000,
+                          mcc->priv->bitrate_per_sec,
+                          (double)mcc->priv->bitrate_per_sec / 1024 / 1024,
+                          main_channel_client_is_low_bandwidth(mcc) ? " LOW BANDWIDTH" : "");
         red_channel_client_start_connectivity_monitoring(rcc,
                                                          CLIENT_CONNECTIVITY_TIMEOUT);
         break;
     default:
-        spice_printerr("invalid net test stage, ping id %d test id %d stage %d",
-                       ping->id,
-                       mcc->priv->net_test_id,
-                       mcc->priv->net_test_stage);
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "invalid net test stage, ping id %d test id %d stage %d",
+                            ping->id,
+                            mcc->priv->net_test_id,
+                            mcc->priv->net_test_stage);
         mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID;
     }
 }
@@ -561,13 +564,15 @@ void main_channel_client_handle_migrate_end(MainChannelClient *mcc)
 {
     RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc));
     if (!red_client_during_migrate_at_target(client)) {
-        spice_printerr("unexpected SPICE_MSGC_MIGRATE_END");
+        red_channel_warning(red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc)),
+                            "unexpected SPICE_MSGC_MIGRATE_END");
         return;
     }
     if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc),
                                             SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE)) {
-        spice_printerr("unexpected SPICE_MSGC_MIGRATE_END, "
-                   "client does not support semi-seamless migration");
+        red_channel_warning(red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc)),
+                            "unexpected SPICE_MSGC_MIGRATE_END, "
+                            "client does not support semi-seamless migration");
             return;
     }
     red_client_semi_seamless_migrate_complete(client);
@@ -966,9 +971,10 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
     if (!mcc->priv->init_sent &&
         !mcc->priv->seamless_mig_dst &&
         base->type != RED_PIPE_ITEM_TYPE_MAIN_INIT) {
-        spice_printerr("Init msg for client %p was not sent yet "
-                       "(client is probably during semi-seamless migration). Ignoring msg type %d",
-                       red_channel_client_get_client(rcc), base->type);
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "Init msg for client %p was not sent yet "
+                            "(client is probably during semi-seamless migration). Ignoring msg type %d",
+                            red_channel_client_get_client(rcc), base->type);
         return;
     }
     switch (base->type) {
diff --git a/server/main-channel.c b/server/main-channel.c
index 4afc9b0e3..f866fb4ae 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -66,8 +66,9 @@ static void main_channel_push_channels(MainChannelClient *mcc)
 {
     RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc);
     if (red_client_during_migrate_at_target(red_channel_client_get_client(rcc))) {
-        spice_printerr("warning: ignoring unexpected SPICE_MSGC_MAIN_ATTACH_CHANNELS"
-                   "during migration");
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "warning: ignoring unexpected SPICE_MSGC_MAIN_ATTACH_CHANNELS"
+                            "during migration");
         return;
     }
     red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_MAIN_CHANNELS_LIST);
@@ -115,7 +116,8 @@ static bool main_channel_handle_migrate_data(RedChannelClient *rcc,
     spice_assert(red_channel_get_n_clients(channel) == 1);
 
     if (size < sizeof(SpiceMigrateDataHeader) + sizeof(SpiceMigrateDataMain)) {
-        spice_printerr("bad message size %u", size);
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "bad message size %u", size);
         return FALSE;
     }
     if (!migration_protocol_validate_header(header,
@@ -367,7 +369,7 @@ int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
     RedChannelClient *rcc;
 
     if (!red_channel_get_clients(RED_CHANNEL(main_chan))) {
-        spice_printerr("no peer connected");
+        red_channel_warning(RED_CHANNEL(main_chan), "no peer connected");
         return 0;
     }
 
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 63b3b5b43..92880fc5f 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -696,7 +696,8 @@ static void red_channel_client_ping_timer(void *opaque)
 
         /* retrieving the occupied size of the socket's tcp snd buffer (unacked + unsent) */
         if (ioctl(rcc->priv->stream->socket, SIOCOUTQ, &so_unsent_size) == -1) {
-            spice_printerr("ioctl(SIOCOUTQ) failed, %s", strerror(errno));
+            red_channel_warning(red_channel_client_get_channel(rcc),
+                                "ioctl(SIOCOUTQ) failed, %s", strerror(errno));
         }
         if (so_unsent_size > 0) {
             /* tcp snd buffer is still occupied. rescheduling ping */
@@ -957,7 +958,9 @@ static gboolean red_channel_client_initable_init(GInitable *initable,
 
 cleanup:
     if (local_error) {
-        g_warning("Failed to create channel client: %s", local_error->message);
+        red_channel_warning(red_channel_client_get_channel(self),
+                            "Failed to create channel client: %s",
+                            local_error->message);
         g_propagate_error(error, local_error);
     }
     return local_error == NULL;
@@ -1095,7 +1098,7 @@ static void red_channel_client_handle_outgoing(RedChannelClient *rcc)
                 red_channel_client_disconnect(rcc);
                 return;
             default:
-                spice_printerr("%s", strerror(errno));
+                red_channel_warning(red_channel_client_get_channel(rcc), "%s", strerror(errno));
                 red_channel_client_disconnect(rcc);
                 return;
             }
@@ -1220,7 +1223,7 @@ static void red_channel_client_handle_incoming(RedChannelClient *rcc)
             if (!buffer->msg) {
                 buffer->msg = red_channel_client_alloc_msg_buf(rcc, msg_type, msg_size);
                 if (buffer->msg == NULL) {
-                    spice_printerr("ERROR: channel refused to allocate buffer.");
+                    red_channel_warning(channel, "ERROR: channel refused to allocate buffer.");
                     red_channel_client_disconnect(rcc);
                     return;
                 }
@@ -1248,7 +1251,7 @@ static void red_channel_client_handle_incoming(RedChannelClient *rcc)
                                           msg_type,
                                           &parsed_size, &parsed_free);
         if (parsed == NULL) {
-            spice_printerr("failed to parse message type %d", msg_type);
+            red_channel_warning(channel, "failed to parse message type %d", msg_type);
             red_channel_client_release_msg_buf(rcc,
                                                msg_type, msg_size,
                                                buffer->msg);
@@ -1314,7 +1317,8 @@ void red_channel_client_push(RedChannelClient *rcc)
 
     if (!red_channel_client_no_item_being_sent(rcc) && !red_channel_client_is_blocked(rcc)) {
         red_channel_client_set_blocked(rcc);
-        spice_printerr("ERROR: an item waiting to be sent and not blocked");
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "ERROR: an item waiting to be sent and not blocked");
     }
 
     while ((pipe_item = red_channel_client_pipe_item_get(rcc))) {
@@ -1445,7 +1449,7 @@ bool red_channel_client_handle_message(RedChannelClient *rcc, uint16_t type,
     switch (type) {
     case SPICE_MSGC_ACK_SYNC:
         if (size != sizeof(uint32_t)) {
-            spice_printerr("bad message size");
+            red_channel_warning(red_channel_client_get_channel(rcc), "bad message size");
             return FALSE;
         }
         rcc->priv->ack_data.client_generation = *(uint32_t *)(message);
@@ -1475,7 +1479,7 @@ bool red_channel_client_handle_message(RedChannelClient *rcc, uint16_t type,
         red_channel_client_handle_pong(rcc, message);
         break;
     default:
-        spice_printerr("invalid message type %u", type);
+        red_channel_warning(red_channel_client_get_channel(rcc), "invalid message type %u", type);
         return FALSE;
     }
     return TRUE;
@@ -1494,7 +1498,7 @@ void red_channel_client_begin_send_message(RedChannelClient *rcc)
 
     // TODO - better check: type in channel_allowed_types. Better: type in channel_allowed_types(channel_state)
     if (rcc->priv->send_data.header.get_msg_type(&rcc->priv->send_data.header) == 0) {
-        spice_printerr("BUG: header->type == 0");
+        red_channel_warning(red_channel_client_get_channel(rcc), "BUG: header->type == 0");
         return;
     }
 
diff --git a/server/smartcard-channel-client.c b/server/smartcard-channel-client.c
index a0c1d8aa6..1ae3ae3ed 100644
--- a/server/smartcard-channel-client.c
+++ b/server/smartcard-channel-client.c
@@ -318,8 +318,9 @@ bool smartcard_channel_client_handle_message(RedChannelClient *rcc,
 
     /* todo: fix */
     if (vheader->reader_id >= smartcard_get_n_readers()) {
-        spice_printerr("ERROR: received message for non existing reader: %d, %d, %d", vheader->reader_id,
-                       vheader->type, vheader->length);
+        red_channel_warning(red_channel_client_get_channel(rcc),
+                            "ERROR: received message for non existing reader: %d, %d, %d",
+                            vheader->reader_id, vheader->type, vheader->length);
         return FALSE;
     }
     spice_assert(scc->priv->write_buf->buf == msg);
diff --git a/server/smartcard.c b/server/smartcard.c
index e9cb32e03..2cb68e066 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -220,7 +220,9 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
     }
     /* We pass any VSC_Error right now - might need to ignore some? */
     if (dev->priv->reader_id == VSCARD_UNDEFINED_READER_ID && vheader->type != VSC_Init) {
-        spice_printerr("error: reader_id not assigned for message of type %d", vheader->type);
+        red_channel_warning(red_channel_client_get_channel(RED_CHANNEL_CLIENT(dev->priv->scc)),
+                            "error: reader_id not assigned for message of type %d",
+                            vheader->type);
     }
     if (dev->priv->scc) {
         sent_header = g_memdup(vheader, sizeof(*vheader) + vheader->length);
@@ -529,7 +531,7 @@ static void smartcard_connect_client(RedChannel *channel, RedClient *client,
     if (char_device) {
         smartcard_char_device_attach_client(char_device, scc);
     } else {
-        spice_printerr("char dev unavailable");
+        red_channel_warning(channel, "char dev unavailable");
     }
 }
 
diff --git a/server/sound.c b/server/sound.c
index ba7b4d4b2..8cdb7d713 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -364,12 +364,15 @@ record_channel_handle_message(RedChannelClient *rcc, uint16_t type, uint32_t siz
                                      SND_CODEC_DECODE) == SND_CODEC_OK) {
                     record_client->mode = mode->mode;
                 } else {
-                    spice_printerr("create decoder failed");
+                    red_channel_warning(red_channel_client_get_channel(rcc),
+                                        "create decoder failed");
                     return false;
                 }
             }
             else {
-                spice_printerr("unsupported mode %d", record_client->mode);
+                red_channel_warning(red_channel_client_get_channel(rcc),
+                                    "unsupported mode %d",
+                                    record_client->mode);
                 return false;
             }
         }
@@ -609,7 +612,7 @@ static bool snd_playback_send_write(PlaybackChannelClient *playback_client)
         if (snd_codec_encode(playback_client->codec, (uint8_t *) frame->samples,
                                     snd_codec_frame_size(playback_client->codec) * sizeof(frame->samples[0]),
                                     playback_client->encode_buf, &n) != SND_CODEC_OK) {
-            spice_printerr("encode failed");
+            red_channel_warning(red_channel_client_get_channel(rcc), "encode failed");
             red_channel_client_disconnect(rcc);
             return false;
         }
@@ -696,7 +699,8 @@ static void playback_channel_send_item(RedChannelClient *rcc, G_GNUC_UNUSED RedP
             if (snd_playback_send_write(playback_client)) {
                 break;
             }
-            spice_printerr("snd_send_playback_write failed");
+            red_channel_warning(red_channel_client_get_channel(rcc),
+                                "snd_send_playback_write failed");
         }
         if (client->command & SND_CTRL_MASK) {
             client->command &= ~SND_CTRL_MASK;
@@ -779,7 +783,8 @@ static bool snd_channel_client_config_socket(RedChannelClient *rcc)
     if (setsockopt(stream->socket, SOL_SOCKET, SO_PRIORITY, (void*)&priority,
                    sizeof(priority)) == -1) {
         if (errno != ENOTSUP) {
-            spice_printerr("setsockopt failed, %s", strerror(errno));
+            red_channel_warning(red_channel_client_get_channel(rcc),
+                                "setsockopt failed, %s", strerror(errno));
         }
     }
 #endif
@@ -787,7 +792,9 @@ static bool snd_channel_client_config_socket(RedChannelClient *rcc)
     tos = IPTOS_LOWDELAY;
     if (setsockopt(stream->socket, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) == -1) {
         if (errno != ENOTSUP) {
-            spice_printerr("setsockopt failed, %s", strerror(errno));
+            red_channel_warning(red_channel_client_get_channel(rcc),
+                                "setsockopt failed, %s",
+                                strerror(errno));
         }
     }
 
@@ -1070,7 +1077,7 @@ playback_channel_client_constructed(GObject *object)
                              SND_CODEC_ENCODE) == SND_CODEC_OK) {
             playback_client->mode = desired_mode;
         } else {
-            spice_printerr("create encoder failed");
+            red_channel_warning(red_channel, "create encoder failed");
         }
     }
 
diff --git a/server/spicevmc.c b/server/spicevmc.c
index 5ff564a37..c2de5037f 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -424,7 +424,10 @@ static void spicevmc_char_dev_send_tokens_to_client(RedCharDevice *self,
                                                     RedClient *client,
                                                     uint32_t tokens)
 {
-    spice_printerr("Not implemented!");
+    RedCharDeviceSpiceVmc *vmc = RED_CHAR_DEVICE_SPICEVMC(self);
+    RedVmcChannel *channel = RED_VMC_CHANNEL(vmc->channel);
+
+    red_channel_warning(RED_CHANNEL(channel), "%s: Not implemented!", G_STRFUNC);
 }
 
 static void spicevmc_char_dev_remove_client(RedCharDevice *self,
@@ -454,8 +457,9 @@ static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
         if (red_char_device_client_exists(channel->chardev, client)) {
             red_char_device_client_remove(channel->chardev, client);
         } else {
-            spice_printerr("client %p have already been removed from char dev %p",
-                           client, channel->chardev);
+            red_channel_warning(RED_CHANNEL(channel),
+                                "client %p have already been removed from char dev %p",
+                                client, channel->chardev);
         }
     }
 
@@ -768,8 +772,9 @@ static void spicevmc_connect(RedChannel *channel, RedClient *client,
     sin = vmc_channel->chardev_sin;
 
     if (vmc_channel->rcc) {
-        red_channel_printerr(channel, "channel client (%p) already connected, refusing second connection",
-                             vmc_channel->rcc);
+        red_channel_warning(RED_CHANNEL(channel),
+                            "channel client (%p) already connected, refusing second connection",
+                            vmc_channel->rcc);
         // TODO: notify client in advance about the in use channel using
         // SPICE_MSG_MAIN_CHANNEL_IN_USE (for example)
         red_stream_free(stream);
-- 
2.17.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]