[PATCH spice-server v3] red-channel: Initialize statistic node correctly

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

 



The default memset(0) on the node did not init it correctly.
This patch create the 0 node as soon as the file is created
to use as default memset(0) compatible node.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/reds.c                 |  4 ++++
 server/tests/test-stat-file.c | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)

Changes since v2:
- this patch create an additional node making 0 a valid node.
  This also make clear that the counters under it apply to a channel.

diff --git a/server/reds.c b/server/reds.c
index 0b6ca12..839ffe7 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3500,6 +3500,10 @@ SPICE_GNUC_VISIBLE SpiceServer *spice_server_new(void)
     reds->config->exit_on_disconnect = FALSE;
 #ifdef RED_STATISTICS
     reds->stat_file = stat_file_new(REDS_MAX_STAT_NODES);
+    /* Create an initial node. This will be the 0 node making easier
+     * to initialize node references.
+     */
+    stat_file_add_node(reds->stat_file, INVALID_STAT_REF, "default_channel", TRUE);
 #endif
     reds->listen_socket = -1;
     reds->secure_listen_socket = -1;
diff --git a/server/tests/test-stat-file.c b/server/tests/test-stat-file.c
index 63a2a2b..901985a 100644
--- a/server/tests/test-stat-file.c
+++ b/server/tests/test-stat-file.c
@@ -89,11 +89,30 @@ static void stat_file(void)
     stat_file_free(stat_file);
 }
 
+/* make sure first node is node 0 */
+static void stat_file_start(void)
+{
+    RedStatFile *stat_file;
+    StatNodeRef ref;
+
+    /* create */
+    stat_file = stat_file_new(10);
+    g_assert_nonnull(stat_file);
+
+    ref = stat_file_add_node(stat_file, INVALID_STAT_REF, "ZERO", TRUE);
+    g_assert_cmpuint(ref,==,0);
+
+    stat_file_unlink(stat_file);
+    stat_file_free(stat_file);
+}
+
+
 int main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
 
     g_test_add_func("/server/stat-file", stat_file);
+    g_test_add_func("/server/stat-file-start", stat_file_start);
 
     return g_test_run();
 }
-- 
2.9.3

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




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