Commit Graph

872 Commits

Author SHA1 Message Date
Marc-André Lureau
17096d1dc8 server/input: avoid double free() of RedChannel on disconnect
Current master is calling red_channel_destroy() on incoming error, but
reds Channels still references it, which causes a double free() later
on (see valgrind report below).

Instead, on error condition, do like the rest of the channels and call
reds_disconnect(), which remove the references and call shutdown(),
which then call red_channel_destroy() and finally free the channel
with red_channel_destroy().

Note: the previous code intention was certainly to be able to keep the
rest of the channels connected when input channel has errors. This is
not addressed by this patch.

red_channel_shutdown:
==29792== Invalid read of size 8
==29792==    at 0x4C6F063: red_channel_shutdown (red_channel.c:460)
==29792==    by 0x4C51EFA: inputs_shutdown (inputs_channel.c:463)
==29792==    by 0x4C48445: reds_shatdown_channels (reds.c:539)
==29792==    by 0x4C4868A: reds_disconnect (reds.c:603)
==29792==    by 0x4C519E9: main_channel_on_error (main_channel.c:765)
==29792==    by 0x4C6E80A: red_channel_peer_on_incoming_error (red_channel.c:215)
==29792==    by 0x4C6E22D: red_peer_handle_incoming (red_channel.c:87)
==29792==    by 0x4C6E551: red_channel_receive (red_channel.c:154)
==29792==    by 0x4C6F329: red_channel_event (red_channel.c:531)
==29792==    by 0x41CB8C: main_loop_wait (vl.c:1365)
==29792==    by 0x437CDE: kvm_main_loop (qemu-kvm.c:1589)
==29792==    by 0x41FE9A: main (vl.c:1411)
==29792==  Address 0x30b0f6d0 is 0 bytes inside a block of size 28,648 free'd
==29792==    at 0x4A05372: free (vg_replace_malloc.c:366)
==29792==    by 0x4C6F032: red_channel_destroy (red_channel.c:454)
==29792==    by 0x4C6E80A: red_channel_peer_on_incoming_error (red_channel.c:215)
==29792==    by 0x4C6E22D: red_peer_handle_incoming (red_channel.c:87)
==29792==    by 0x4C6E551: red_channel_receive (red_channel.c:154)
==29792==    by 0x4C6F329: red_channel_event (red_channel.c:531)
==29792==    by 0x41CB8C: main_loop_wait (vl.c:1365)
==29792==    by 0x437CDE: kvm_main_loop (qemu-kvm.c:1589)
==29792==    by 0x41FE9A: main (vl.c:1411)

https://bugs.freedesktop.org/show_bug.cgi?id=34971
2011-03-03 14:59:31 +01:00
Marc-André Lureau
28f3007145 Revert "server/red_channel: red_channel_event: push on blocked"
This reverts commit 5062433d8a.

red_channel_receive() can call red_channel_destroy() which frees
channel.

The condition bellow is then checked, which can access a freed
channel:

if (event & SPICE_WATCH_EVENT_WRITE || channel->send_data.blocked)

Reverting this commit solves the issue without any apparent
bugs/drawbacks, which kind of clears out the weird TODO.

handle_dev_input: cursor connect
==11826== Invalid read of size 4
==11826==    at 0x4C6F83C: red_channel_event (red_channel.c:535)
==11826==    by 0x41CB8C: main_loop_wait (vl.c:1365)
==11826==    by 0x437CDE: kvm_main_loop (qemu-kvm.c:1589)
==11826==    by 0x41FE9A: main (vl.c:1411)
==11826==  Address 0x31fb00f0 is 96 bytes inside a block of size 28,648 free'd
==11826==    at 0x4A05372: free (vg_replace_malloc.c:366)
==11826==    by 0x4C6F536: red_channel_destroy (red_channel.c:453)
==11826==    by 0x4C52B5D: inputs_channel_on_incoming_error (inputs_channel.c:449)
==11826==    by 0x4C6ED0E: red_channel_peer_on_incoming_error (red_channel.c:215)
==11826==    by 0x4C6E731: red_peer_handle_incoming (red_channel.c:87)
==11826==    by 0x4C6EA55: red_channel_receive (red_channel.c:154)
==11826==    by 0x4C6F82D: red_channel_event (red_channel.c:530)
==11826==    by 0x41CB8C: main_loop_wait (vl.c:1365)
==11826==    by 0x437CDE: kvm_main_loop (qemu-kvm.c:1589)
==11826==    by 0x41FE9A: main (vl.c:1411)
==11826==

https://bugs.freedesktop.org/show_bug.cgi?id=34971
2011-03-03 14:59:31 +01:00
Alon Levy
23ba2ce3e5 server/red_worker: use red_channel_pipe_item_init
replaces in file red_pipe_item_init.
2011-03-02 17:27:53 +02:00
Alon Levy
c771182274 server/red_channel: move out_bytes_counter from Outgoing to RedChannel 2011-03-02 17:27:53 +02:00
Alon Levy
692b41f946 server/red_channel: split Incoming/Outgoing to callback and state
This allows later to have the callback table under RedChannel when
the callbacks actually get used by RedChannelClient. Since the cb's
are identical for different clients of the same channel it makes sense
to store the callback pointers in one place per channel. The rest of
the incoming and outgoing struct just gets moved to RedChannelClient.
2011-03-02 17:27:53 +02:00
Alon Levy
d1feaeb282 server/red_channel: no opaque in red_channel_peer_on_*_error 2011-03-02 17:27:53 +02:00
Alon Levy
b5ae7133c0 server/red_worker: use red_channel_is_connected 2011-03-02 17:27:53 +02:00
Alon Levy
7890b623b5 server/red_channel: add red_channel_disconnect, use in red_worker
replace channel_release_res in red_worker with red_channel_disconnect.
2011-03-02 17:27:53 +02:00
Alon Levy
aa5d23fdec server/red_channel: reset send_data.item to NULL after release 2011-03-02 17:27:53 +02:00
Alon Levy
d4c187c043 server/red_worker: remove RedChannel argument from add_buf_from_info
It was unused.
2011-03-02 17:27:53 +02:00
Alon Levy
5575d6e5fa server/red_channel: add red_channel_{,no_}item_being_sent 2011-03-02 17:27:53 +02:00
Alon Levy
17ebd6a719 server/red_worker: complete removal of send_data.marshaller use 2011-03-02 17:27:53 +02:00
Alon Levy
992252104c server/red_worker: replace _send_ functions by _marshall_
Changes in display channel for a code size win.

A note about this and the previous cursor change: it will appear that we are
now (with these changes) releasing resources too early. This is not so - send
always has the option of blocking, which means after send you can not release
resources anyway, that's what the release_item callback is for. So both the
code before and now are doing the same accounting.
2011-03-02 17:27:52 +02:00
Alon Levy
88db43879b server/red_channel: add red_channel_send_message_pending 2011-03-02 17:27:52 +02:00
Alon Levy
7a650e9641 server/red_channel: add red_channel_all_blocked 2011-03-02 17:27:52 +02:00
Alon Levy
b7dbc14b1c server/red_worker: cursor channel: replace _send_ with _marshall_ 2011-03-02 17:27:52 +02:00
Alon Levy
e9be6ca82c server/red_channel (all): add red_channel_get_header
This is useful during the channel specific channel_send_pipe_item_proc
callback, it allows altering or reader the header being sent.
2011-03-02 17:27:52 +02:00
Alon Levy
17d5761322 server/red_channel: add red_channel_get_first_socket
Use in main_channel. This is just for backward portability later
when multiple clients are introduced - needs to be considered (which
sockets do we want to export from libspiceserver?)
2011-03-02 17:27:52 +02:00
Alon Levy
8cd5568c92 server/red_channel (+): remove red_channel_add_buf 2011-03-02 17:27:52 +02:00
Alon Levy
16bff20f91 server/tunnel: pass SpiceMarshaller reference from send
Introduce SpiceMarshaller param to all send's that do add_buf

Next patch will use marshaller in all functions that currently don't by
replacing red_channel_add_buf with marshaller add_ref. Note - currently
tunnel is broken due to wrong size in messages.
2011-03-02 17:27:52 +02:00
Alon Levy
a05628bf06 server/red_channel (all): add red_channel_get_stream
use in config_socket, this makes the stream internal to the RedChannel
implementation that will change later for multiple client support.
2011-03-02 17:27:52 +02:00
Alon Levy
6b86259646 ring: add RING_FOREACH{,_SAFE,_REVERSED} 2011-03-02 17:27:52 +02:00
Alon Levy
38e13ef1a8 server/common: introduce common/spice_common.h
move all the ASSERT/PANIC/PANIC_ON/red_error/red_printf* macros
to a common file to be used with ring.h that is going to be used externally
(by spice-gtk).
2011-03-02 17:27:51 +02:00
Alon Levy
ce03dcfbb5 server/red_channel (all): handle MIGRATE_DATA and MIGRATE_FLUSH_DATA
Handling done in red_channel instead of per channel, using call backs
for the channel specific part.
Intended to reduce furthur reliance of channels on RedChannel struct.

The commit makes the code harder to understand because of the artificial
get_serial stuff, should later be fixed by having a joint migration
header with the serial (since all channels pass it).
2011-03-02 17:27:51 +02:00
Alon Levy
8002a30f9c server/red_channel (all): add red_channel_get_marshaller
For ussage in the send_item callback. It's only valid during this
time anyway (should make it return NULL in other occasions?)

No more direct usage of RedChannel.send_data.marshaller by channels.
2011-03-02 17:27:51 +02:00
Alon Levy
9e46945a61 server/red_worker: use red_channel_destroy 2011-03-02 17:27:51 +02:00
Alon Levy
966201c1ad server/inputs_channel: s/PIPE_ITEM_INIT/PIPE_ITEM_INPUTS_INIT/ 2011-03-02 17:27:51 +02:00
Alon Levy
5e1ba1101b server/red_channel: move SET_ACK to red_channel 2011-03-02 17:27:51 +02:00
Alon Levy
2fcd35b073 server/red_channel: add more ack api 2011-03-02 17:27:51 +02:00
Alon Levy
766bb420bb server: use red_channel_get_message_serial 2011-03-02 17:27:51 +02:00
Alon Levy
17b6a58f1e server/red_channel (all): makes red_channel_reset_send_data private
ready the way for handling ack messages in RedChannel.
2011-03-02 17:27:51 +02:00
Alon Levy
cd99a0b4b3 server/red_worker: use red_channel 2011-03-02 17:27:50 +02:00
Alon Levy
ce3efca360 server/red_channe: make hold_item take a channel arg 2011-03-02 17:27:50 +02:00
Alon Levy
73858b93dc server/red_worker: introduce red_peer_handle_outgoing and OutgoingHandler
From red_channel.
2011-03-02 17:27:50 +02:00
Alon Levy
29a7bcd596 server/red_worker: introduce common_channel_config_socket 2011-03-02 17:27:50 +02:00
Alon Levy
beba2c7206 server/red_worker: line width fix 2011-03-02 17:27:50 +02:00
Alon Levy
724348ce49 server/red_worker: don't push to NULL channel (called from device input) 2011-03-02 17:27:50 +02:00
Alon Levy
705254b399 server/red_worker: introduce red_channel_pipe_clear
No more common_release_pipe_item
2011-03-02 17:27:50 +02:00
Alon Levy
a0a9718423 server/red_worker: add red_channel_push 2011-03-02 17:27:50 +02:00
Alon Levy
111cf51103 server/red_worker: add send_item 2011-03-02 17:27:50 +02:00
Alon Levy
f7a99f858e server/red_worker: red_channel renames
The renames are part of refactoring red_worker's RedChannel to reuse
red_channel.h's RedChannel at the end.

s/red_send_data/red_channel_send/
s/red_pipe_get/red_channel_pipe_get/
s/recive_data/incoming/
s/red_receive/red_channel_receive/
s/channel_handle_message/red_channel_handle_message/
s/channel_is_connected/red_channel_is_connected/
s/red_pipe_add_type/red_channel_pipe_add_type/
2011-03-02 17:27:49 +02:00
Alon Levy
b3ea0bec3d server/red_tunnel_worker: use message_serial setter and getter
fixes breakage in --enable-tunnel compilation.
2011-03-02 17:27:49 +02:00
Hans de Goede
15b8252289 x11: Use _exit rather then exit on X errors (rhbz#680763)
This avoids us trying to restore the original resolution when we're fullscreen
and an X error happens. As restoring fullscreen is a bad idea then as this
involves making more X calls, which can get us stuck (in side an XLockDisplay
call for example).
2011-03-01 18:08:20 +02:00
Uri Lublin
e9ee6cf914 client: exit nicely for --controller with no SPICE_XPI_SOCKET (rhbz#644292)
When starting spicec with --controller, SPICE_XPI_SOCKET environment
variable must be defined so spicec and the controller can be connected.
2011-03-01 17:58:47 +02:00
Hans de Goede
0c88a60ecc Fix keyb modifiers not syncing from client to client os (rhbz#679467) 2011-03-01 16:12:32 +02:00
Marc-André Lureau
8f9cbd19db server: add SASL support
We introduce 2 public functions to integrate with the library user.

spice_server_set_sasl() - turn on SASL
spice_server_set_sasl_appname() - specify the name of the app (It is
used for where to find the default configuration file)

The patch for QEMU is on its way.

https://bugs.freedesktop.org/show_bug.cgi?id=34795
2011-02-28 16:36:35 +01:00
Marc-André Lureau
f4dddc50f0 server: add auth mechanism selection
https://bugs.freedesktop.org/show_bug.cgi?id=34795
2011-02-28 16:36:35 +01:00
Marc-André Lureau
4f983b2c9c server: add reds_channel_dispose()
Try to have a common base dispose() method for channels. For now, it
just free the caps.

Make use of it in snd_worker, and in sync_write() - sync_write() is
going to have default caps later on.

https://bugs.freedesktop.org/show_bug.cgi?id=34795
2011-02-28 16:36:35 +01:00
Marc-André Lureau
09c01c9516 server: simplify and constify sync_write()
+ symplify, improving style of code using it.

https://bugs.freedesktop.org/show_bug.cgi?id=34795
2011-02-28 16:36:35 +01:00
Marc-André Lureau
37dbb8aec9 server: pull out reds_handle_link(), for future reuse
+ a couple of indent, style change

https://bugs.freedesktop.org/show_bug.cgi?id=34795
2011-02-28 16:36:35 +01:00