Commit Graph

15 Commits

Author SHA1 Message Date
Frediano Ziglio
80bb7eb774 stat-file: Use proper macro for container computation
This is currently more style patch as the "value" field is the
first field of SpiceStatNode structure, so has offset 0. However
to compute the containing structure it better to use the proper
macro to avoid confusion.
If the offset won't be 0 the subtraction would compute the
wrong pointer as the offset is expressed in bytes but the
element size are uint64_t.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-22 08:53:23 +01:00
Frediano Ziglio
524acca643 windows: Disable code not working on Windows
- global signals;
- CLOEXEC flag;
- mmap and statistics;
- IPTOS_LOWDELAY flag;
- Unix sockets;
- sharing file descriptors through Unix sockets;
- TCP_CORK flag.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:22 +01:00
Frediano Ziglio
ed68d491fd Do not check for HAVE_CONFIG_H
This should always be defined and including config.h is a requirement.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-04-30 09:26:55 +01:00
Frediano Ziglio
486aea984b stat-file: Exit earlier to reduce indentation
Just style change. Invert the if to exit earlier.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe de Dinechin <dinechin@redhat.com>
2018-06-25 13:12:04 +01:00
Frediano Ziglio
bde8ef5a4e stat-file: Protect flags field with atomic operation
Coverity complaint that this field should be protected by
a mutex as other accesses are with the mutex locked.
Use atomic operation. Not in an hot path in any case.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2017-12-19 12:18:56 +00:00
Frediano Ziglio
a99043771a Start using GLib memory allocation
Start reducing the usage of spice_new*/spice_malloc allocations.
They were designed in a similar way to GLib ones.
Now that we use GLib make sense to remove them.
However the versions we support for GLib can use different memory
allocators so we have to match g_free with GLib allocations
and spice_* ones (which uses always malloc allocator) with free().
This patch remove some easy ones.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-09-19 16:17:10 +01:00
Frediano Ziglio
6be1c2f839 stat-file: Avoid compiler warning
Some gcc version reports this error:

stat-file.c: In function 'stat_file_add_node':
stat-file.c:180:15: error: 'node' may be used uninitialized in this function
[-Werror=maybe-uninitialized]
     g_strlcpy(node->name, name, sizeof(node->name));
               ^~~~
cc1: all warnings being treated as errors

This warning is a false positive as this loop:
    for (ref = 0; ref <= stat_file->max_nodes; ref++) {
        node = &stat_file->stat->nodes[ref];
        ...
    }
will always iterate at least once.

This patch rewrite the loop in order to make more compilers
understand that node variable is always initialized.

There are two checks apparently removed in the patch:
- check for stat_file->stat not being NULL. This was worthless as the
  field was already used in the function. Also this field is never
  NULL (unless memory corruption happened);
- stat_file->stat->num_of_nodes >= stat_file->max_nodes. It's implicit
  in the loop. If num_of_nodes >= max_nodes means that there are no
  free nodes so all nodes should have SPICE_STAT_NODE_FLAG_ENABLED set,
  loop will exit and function will return INVALID_STAT_REF.

Reported-by: Christophe Fergeau <cfergeau@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-03 18:13:22 +00:00
Frediano Ziglio
a29afab028 stat-file: Fix off by one buffer overflow
The stat file contains an array of max_nodes elements
so we must stay in [0, max_nodes) range, not [0, max_nodes].

There are no spice path that lead to these overflows but
it's better to have them fixed before creating one.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-03 09:48:46 +00:00
Frediano Ziglio
f73e8319c6 Move some include from header to source
Now that RedStatFile is private there is no need
to include some headers in stat-file.h.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-11-30 15:44:28 +00:00
Frediano Ziglio
47f56a72e0 Free statistic file on spice_server_destroy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-11-30 12:36:47 +00:00
Frediano Ziglio
002c7c9eeb Make RedStatFile private inside stat-file.c
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-16 16:38:32 +00:00
Frediano Ziglio
41c042ca36 Avoid leaking file descriptor for statistics
mmap memory area will remain even if the descriptor is closed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-16 16:38:30 +00:00
Frediano Ziglio
d163f17a36 Use g_strdup_printf instead of manually malloc/snprintf
Make the code easier and shorter.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-16 16:38:27 +00:00
Frediano Ziglio
fe543c6b45 Fix node removal
Avoid to produce loop in the tree removing and adding nodes.
Unlink the node from the containing tree.
This possibly will create unlinked trees if a parent node is
deleted.

What was happening is that the creation of loops inside
the tree caused some statistical function to go into an
infinite loop (and reds_stat tool too).

Nodes were only invalidated but still linked so when reused
the new node could point to an already existing node (like a
sibling) which pointed to the new reused one.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-16 16:38:21 +00:00
Frediano Ziglio
f9ccabfaea Separate code to manage statistic file
Code is quite independent so move in separate file.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-16 16:38:13 +00:00