Commit Graph

2359 Commits

Author SHA1 Message Date
Christophe Fergeau
400a5d13cf Remove compress_buf_new
This commit reworks a bit the management of RedCompressBuf so that
compress_buf_new/compress_buf_free become unneeded.
Since d25d6ca0 and the introduction of encoder_data_reset,
compress_buf_free is already unused outside of dcc-encoders.c and could
be static. This in turn makes compress_buf_new a bit odd as the matching
destructor is never used in dcc.c.
This commit introduces an encoder_data_init() method which is hiding
the initialization of the EncoderData structure from the dcc.c code,
allowing to get rid of compress_buf_new() calls from dcc.c code.

It also uses this as an opportunity to stop using GSlice for
RedCompressBuf.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-14 16:39:30 +00:00
Frediano Ziglio
eff5e83936 channel: simplify red_channel_client_send_item
Acked-by: Pavel Grunt <pgrunt@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-01-14 14:16:53 +00:00
Marc-Andre Lureau
f438bd6ae9 tests: add fdpass stream test
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-14 11:04:49 +00:00
Marc-André Lureau
5c1073266e reds-stream: add send_msgfd()
A new function to send fd with unix socket anciliary data.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-14 10:55:36 +00:00
Marc-Andre Lureau
2628197b99 build-sys: build a utility libserver.la
This allow tests programs to link with statically built library to access all symbols

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-14 10:53:25 +00:00
Christophe Fergeau
6e66366f9b Update NEWS for 0.13.0 release 2016-01-13 12:51:25 +01:00
Christophe Fergeau
9ea5348efc spicevmc: Drop unsent data on client disconnection
When redirecting a USB webcam over a slow link, it's currently possible
to hit an assertion in spice-server by running cheese (application using
the webcam), killing the client with ctrl+c and then restarting the
client:
qemu-kvm: spicevmc.c:324: spicevmc_red_channel_alloc_msg_rcv_buf:
Assertion `!state->recv_from_client_buf' failed.

This happens when red_peer_handle_incoming tries to allocate memory for
a message using spicevmc:
handler->msg = handler->cb->alloc_msg_buf(handler->opaque, msg_type,
msg_size);

red_peer_handle_incoming() is called when there is client data to be
read, and does
- call alloc_msg_buf() to allocate memory for the message
- read the message
- if the read was partial, return early, the main loop will call again
  red_peer_handle_incoming() when there is more data available for that
  channel
- parse the message
- call release_msg_buf() to free the message

For channels based on spicevmc (usbredir and port), alloc_msg_buf()
stores message data in SpiceVmcState::recv_from_client_buf and before
allocating new memory, it asserts that it's NULL.

This is what causes this crash in the following scenario:
- SpiceVmc::alloc_msg_buf() is called and allocates memory for a new
  message in SpiceVmcState::recv_from_client_buf
- red_peer_handle_incoming() returns early as all the spicevmc message
  data hasn't been received yet
- the client gets killed
- the main channel notices the disconnect and calls
  main_dispatcher_client_disconnect() which will disconnect all the
  channels
- SpiceVmc::on_disconnect is called
- after the new client connects, SpiceVmc::alloc_msg_buf() is called,
  notices that SpiceVmcState::recv_from_client_buf is already set, and
  asserts()

This commit makes sure the partial SpiceVmcState::recv_from_client_buf
data is cleared on disconnect so that the assert does not trigger.

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1264113
2016-01-13 11:45:56 +01:00
Sunny Shin
b9b0590bc0 channel: add option tcp keepalive timeout to channels 2016-01-12 15:10:47 +01:00
Christophe Fergeau
02c8a0f386 stat: Make stat_compress_init/stat_init the same
When COMPRESS_STAT is not set, and RED_WORKER_STAT is set,
stat_time() will be a no-op, but stat_start_time_init() will try to use
stat_info_t::clock. This causes a compile warning on 32 bit arches (not
sure why not on 64 bit builds), as well as an error from valgrind.

Since stat_time() and stat_compress_time() are both doing the same work,
this commit makes them the same function, which ensures
stat_info_t::clock will be set and stat_start_time_init() can be used
regardless of the _init() method which is called.
2016-01-12 11:46:32 +01:00
Francois Gouget
a57f227235 server: Fix conversions between QXLPHYSICAL and pointers
This avoids compilation errors with -Werror on 32 bit systems as the
pointer size differs from that of a QXLPHYSICAL.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-01-12 10:57:21 +01:00
Francois Gouget
0de8f7f94e server: Simplify the next chunk initialization in red_replay_data_chunks()
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-01-12 10:57:20 +01:00
Francois Gouget
e617a59969 server: Fix a pointer to uint64_t cast in spice_replay_next_cmd()
This avoids a compilation error with -Werror on 32 bit systems as the
pointer size differs from that of an uint64_t.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-01-12 10:57:20 +01:00
Frediano Ziglio
77830036e2 channel: use iface parameter to distinguish interface context
Now we can use the iface parameter to distinguish the context instead
of doing strange assumption on opaque and its state.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:40:17 +00:00
Frediano Ziglio
ba175f9be1 channel: add interface parameters to SpiceCoreInterfaceInternal
This patch and previous ones want to solve the problem of not having a
context in SpiceCoreInterface. SpiceCoreInterface defines a set of
callbacks to handle events in spice-server. These callbacks allow to
handle timers, watch for file descriptors and send channel events.
All these callbacks do not accept a context (usually in C passed as a
void* parameter) so it is hard for them to differentiate the interface
specified.
Unfortunately this structure is used even internally from different
contexts for instance every RedWorker thread has a different context. To
solve this issue some workarounds are used. Currently for timers a variable
depending on the current thread is used while for watches the opaque
parameter to pass to the event callback is used as it currently points just
to RedChannelClient structure.  This however imposes some implicit
maintainance problem in the future. What happens for instance if for some
reason a timer is registered during worker initialization, run in another
thread? What if we decide to register a file descriptor callback for
something not a RedChannelClient?  Could be that the program will run
without any issue till some bytes change and weird things could happen.

The implementation of this solution is done implementing an internal "core"
interface that has context specific and use it to differentiate the
context instead of relying on some other, hard to maintain, detail. Then an
adapter structure (name inpired to the adapter pattern) will provide the
internal core interface using the external, public, definition (in the
future this technique can be used to extend the external interface without
breaking the ABI).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:40:17 +00:00
Frediano Ziglio
9745ef5f9a channel: build adapter for public core interface
Add wrapper functions for SpiceCoreInterface in order to present
a SpiceCoreInterfaceInternal. These functions just expect
SpiceCoreInterfaceInternal API and forward request to
SpiceCoreInterface.
This allows to change ABI details of internal one.

See comments in "channel: add interface parameters to
SpiceCoreInterfaceInternal" patch.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:40:12 +00:00
Frediano Ziglio
adc0751950 channel: add a new internal SpiceCoreInterface
Define an internal structure that matches 100% the ABI of the public one.
The structure will be changed by following patches.
See comments in "channel: add interface parameters to
SpiceCoreInterfaceInternal" patch.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:29:53 +00:00
Frediano Ziglio
26c7e33de3 stats: use CLOCK_THREAD_CPUTIME_ID for cpu statistics
Use CLOCK_THREAD_CPUTIME_ID instead of getting the clock
with pthread_getcpuclockid.
This avoids to call red_worker_get_clockid. This function returns
uninitialized value at the time DisplayChannel is built resulting in setting
statistics to CLOCK_REALTIME (which is 0) instead to cpu time as expected.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 16:29:08 +00:00
Frediano Ziglio
1b6af4779a dcc: avoid to report errors triggered by client
Client can always send report even if a stream is not available.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-11 14:45:02 +00:00
Frediano Ziglio
d3b5d2c97e add some tests for cursors parsing
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 18:16:47 +00:00
Frediano Ziglio
6ea345b820 add test for QXL parsing functions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 18:16:47 +00:00
Frediano Ziglio
f84239a035 check properly if red_get_data_chunks fails or not
Instead of returning 0 which could be a valid value returns an invalid
one and check on the caller.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 18:16:42 +00:00
Frediano Ziglio
2571cec5eb prevent integer overflow in red_get_clip_rects
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 16:33:27 +00:00
Frediano Ziglio
d25d6ca0f2 dcc: write and use a new encoder_data_reset function to clean buffers
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 16:25:37 +00:00
Frediano Ziglio
bd8c74d7a4 dcc: free glz buffer after zlib compression
For zlib+glz compression image if first compressed with glz then the
resulting buffer is compressed again with zlib then the buffer from
zlib is returned to the caller.
However the temporary glz buffer was not freed resulting in a memory
leak.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 16:25:25 +00:00
Eduardo Lima (Etrunko)
8c6dcc5eaf server: Fix tests Makefile
As reported in https://bugs.freedesktop.org/show_bug.cgi?id=93520, the
build from git is failing in Archlinux systems with undefined
references to glib symbols.

This patch fixes the problem by simply reordering the order libraries
will be linked. Also, removes duplicate $(GLIB_LIBS) variable.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-08 12:23:54 +00:00
Pavel Grunt
2decbd2116 syntax-check: Fix sc_cast_of_argument_to_free
red_replay_qxl.c was renamed in 525cd67be7

Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 11:24:17 +00:00
Pavel Grunt
952aaca3d7 syntax-check: Remove empty line at EOF
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 11:24:14 +00:00
Pavel Grunt
1a158ce728 syntax-check: Fix missing AUTHORS
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-01-08 11:23:44 +00:00
Frediano Ziglio
cc5fa8fa9b replay: better help for -s option
-s accepts an option to delay command queueing.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <mlureau@redhat.com>
2015-12-22 16:45:48 +00:00
Marc-André Lureau
9a0efecd93 reds-stream: add reds_stream_is_plain_unix()
Utility function used in follow-up code.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-21 13:20:53 +00:00
Pavel Grunt
2db3868864 build-sys: Use sasl check from spice-common
Support only libsasl2 providing libsasl2.pc file

Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-12-21 13:40:19 +01:00
Marc-Andre Lureau
3364af70a3 tests: remove test_util.h
Replace ASSERT() with spice_assert().

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-21 11:44:34 +00:00
Frediano Ziglio
f5f103b8d7 tests: remove unused macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-21 10:39:56 +00:00
Lukas Venhoda
6c4f11191c dcc: Don't disconnect channel, when compression is not supported
Don't disconnect the display channel, when unsupported compression is
requested from the client. Not changing the compression is enough.

https://bugs.freedesktop.org/show_bug.cgi?id=92821
Acked-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-17 12:29:52 +01:00
Christophe Fergeau
bc1adb5ccf build: Remove unused SPICEC_STATIC_LINKAGE_BSTATIC
A left-over from the client code.
2015-12-16 14:44:09 +01:00
Marc-Andre Lureau
e64135179f stream: consitify reds_stream_get_family() argument
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-16 10:16:43 +00:00
Francois Gouget
3c4e735e9e server: Use '%zu' to print size_t variables
The size_t definition is different between 32 and 64 bit systems so that
neither '%u' nor '%lu' work for both. '%zu' should be used instead.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-15 17:50:05 +00:00
Francois Gouget
badee40030 server: Remove an unneeded mjpeg-encoder.h include
The corresponding code has been moved elsewhere during the refactoring.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-15 17:48:58 +00:00
Francois Gouget
110c31439b server: Use PRI macros in printf for 32/64 bit compatibility
Some integer type definitions are different between 32 and 64 bit
systems which causes problems in printf. The PRI macros automatically
provide the printf format appropriate for the system.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-15 17:47:50 +00:00
Frediano Ziglio
b953a4e35f tests: reuse Makefile macro
For coherency use COMMON_BASE macro instead of including single
files.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2015-12-15 17:39:49 +00:00
Frediano Ziglio
276d9f08cd tests: allocate memory in a coherent fashion
Do not free memory allocated with C functions (like calloc) using g_free;
although this is possible with default Glib allocator this is not safe.
Also use consistent allocation functions. All other spice-server code
does not use Glib allocations so for coherence do not use them for
watches.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2015-12-15 17:39:38 +00:00
Marc-André Lureau
13b2c97e79 red-channel: constify some callback structs
Because we can.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-14 13:59:39 +00:00
Christophe Fergeau
10377fa065 build: Don't list some installed headers twice
Since commit febaed3, spice.h and spice-experimental.h are listed both
in libspice_server_la_HEADERS and libspice_server_la_SOURCES. Since we
want these headers to be installed, we can remove them from _SOURCES.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-14 12:27:09 +00:00
Francois Gouget
8bddb1444e server: Add time constants to go with spice_get_monotonic_time_ms()
They clarify the time unit being used and simplify calculations.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-12-14 11:24:47 +00:00
Francois Gouget
5c9fb9a0f3 server: Add time constants to go with spice_get_monotonic_time_ns()
They clarify the time unit being used, reduce the need for casts and
simplify calculations.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-12-14 11:24:34 +00:00
Francois Gouget
cbc4e07682 server: Rename DISPLAY_CLIENT_TIMEOUT and de-duplicate it
Given that it is used for both cursor and display, COMMON_CLIENT_TIMEOUT
seems more appropriate. Also define it only in red-worker.h.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-14 10:53:40 +00:00
Pavel Grunt
67f619d551 worker: Rename function name in the comment as well
It was renamed in 47b023866f

Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-12-11 16:04:16 +00:00
Frediano Ziglio
9c56c884ad dcc: do not cause problem with multiple threads.
With multiple cards configured you can have multiple workers running in
different thread.
With such configuration static variables not syncronized could lead
to undefined behavior.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-11 14:57:05 +00:00
Frediano Ziglio
765b5209ef reds: do not use g_malloc0 in server code
The rest of code is using spice_malloc* functions, use them for
consistency.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-12-11 14:55:32 +00:00
Francois Gouget
c9282b3bc7 server: Use spice_get_monotonic_time_ms() in spice_timer_queue.c
This reduces code duplication.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-12-11 12:43:26 +00:00