red-channel: Initialize statistic node correctly

Doing a memset(0) on a SpiceStatNode does not create an empty/unattached
node, but instead creates a node '0'. This node could be non-existing,
or totally unrelated.
This patch creates a default '0' node as soon as the file is created.
This will make the behaviour of 0-filled nodes more in line with what
one would expect.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Frediano Ziglio 2017-03-30 13:42:25 +01:00
parent bc5326b1ce
commit 5d046d9b2d
2 changed files with 23 additions and 0 deletions

View File

@ -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;

View File

@ -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();
}