Commit graph

671 commits

Author SHA1 Message Date
Kristian Høgsberg
de961dc1f3 client: Make wl_display thread safe
Not all entry points are thread safe: global listeners and global lookup
is still only main thread.
2012-10-10 20:59:00 -04:00
Kristian Høgsberg
ce1f4c29ab client: Split event handling into demarshal and dispatch steps
This lets us demarshal with a mutex held and then do dispatching after
releasing the mutex.
2012-10-10 20:59:00 -04:00
Kristian Høgsberg
53d24713a3 Change filedescriptor API to be thread safe
The update callback for the file descriptors was always a bit awkward and
un-intuitive.  The idea was that whenever the protocol code needed to
write data to the fd it would call the 'update' function.  This function
would adjust the mainloop so that it polls for POLLOUT on the fd so we
can eventually flush the data to the socket.

The problem is that in multi-threaded applications, any thread can issue
a request, which writes data to the output buffer and thus triggers the
update callback.  Thus, we'll be calling out with the display mutex
held and may call from any thread.

The solution is to eliminate the udpate callback and just require that
the application or server flushes all connection buffers before blocking.
This turns out to be a simpler API, although we now require clients to
deal with EAGAIN and non-blocking writes.  It also saves a few syscalls,
since the socket will be writable most of the time and most writes will
complete, so we avoid changing epoll to poll for POLLOUT, then write and
then change it back for each write.
2012-10-10 20:59:00 -04:00
Rob Bradford
6685d19301 connection: Add missing free from error path
On the error codepath that errors out on ENOMEM we should free the allocated
closure.

Signed-off-by: Rob Bradford <rob@linux.intel.com>
2012-10-09 23:01:42 -04:00
Kristian Høgsberg
5495bcd15a connection: Drop unused static closures 2012-10-01 13:21:29 -04:00
David Herrmann
003a946aa6 event-loop: export wl_event_loop_dispatch_idle()
When integrating the wayland event-loop into another event-loop, we
currently have no chance of checking whether there are pending idle
sources that have to be called. This patch exports the
"dispatch_idle_sources()" call so other event loops can call this before
going to sleep. This is what wl_event_loop_dispatch() currently does so we
simply allow external event-loops to do the same now.

To avoid breaking existing applications, we keep the call to
dispatch_idle_sources() in wl_event_loop_dispatch() for now. However, if
we want we can remove this later and require every application to call
this manually. This needs to be discussed, but the overhead is negligible
so we will probably leave it as it is.

This finally allows to fully integrate the wayland-server API into
existing event-loops without any nasty workarounds.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-12 12:28:54 -04:00
David Herrmann
9fe135c46f wayland-server: return new ID in wl_client_add_resource()
wl_client_add_resource() used to return no error even though the new
resource wasn't added to the client. This currently makes it very easy to
DOS weston by simply posting thousands of "create_surface" requests with
an invalid ID. Weston simply assumes the wl_client_add_resource() request
succeeds but will never destroy the surface again as the "destroy" signal
is never called (because the surface isn't linked into the wl_map).

This change makes wl_client_add_resource() return the new ID of the added
object and 0 on failure. Servers (like weston) can now correctly
immediately destroy the surface when this call fails instead of leaving
the surface around and producing memory-leaks.

Instead of returning -1 on failure and 0 on success, I made it return the
new ID as this seems more appropriate. We can directly use it when calling
it with new_id==0.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-10 21:44:47 -04:00
David Herrmann
397a0c6ada event-loop: remove dead code
There is really no need to increment "n" if we never read the value. The
do-while() loop overwrites the value before it is read the first time.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-10 21:28:34 -04:00
Kristian Høgsberg
7d3ccec18e Add wl_shm_buffer_create() 2012-08-16 10:49:48 -04:00
Kristian Høgsberg
c855d6eec4 client: Add wl_display_connect_to_fd() function
This lets us connect a display to an already existing socket fd.
2012-08-16 10:49:48 -04:00
Kristian Høgsberg
915cdeee29 connection: zero out string padding
We don't want to send random data to the client and this also keeps
valgrind happy.
2012-08-03 22:39:51 -04:00
Daniel Stone
3ec40512c7 More consistent ID printing
Use unsigned rather than signed for IDs, so they match up with what we
see in other prints.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23 20:17:10 -04:00
Daniel Stone
db0add6d5e Make NEW_IDs nullable
The connection-handling code already allows this, so make it legal in
the protocol definition too.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23 20:16:57 -04:00
Daniel Stone
efe23443d8 Unstatic arg_count_for_signature and get_next_argument
Expose these to other files using wayland-private.h, so wayland-client.c
can walk NULLables properly.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23 20:15:28 -04:00
Mathias Fiedler
0b8b397e34 connection: reserve id on incoming new object
If a new object id arrives ensure that there is an empty array entry
created, otherwise we might get out of sync for new ids if object isn't
created by interface implementation.
2012-07-22 14:09:51 -04:00
Mathias Fiedler
bfcd681930 wayland-util: add method for reserving new object id
wl_map_reserve_new() ensures that new id is valid and will point to an
empty array entry.
2012-07-22 14:09:48 -04:00
Mathias Fiedler
900e4b63ef wayland-server: send error on invalid new object id
Creation of new client resources was silently ignored when
wl_client_add_resource() was used on server side and new object id was out
of range.

An error is now send out to the client in such case.

Also changed error message in wl_client_add_object, since
wl_map_insert_at() returns -1 only at invalid new id.
2012-07-22 14:06:37 -04:00
Kristian Høgsberg
76bfd68f47 wayland-shm: Commit the width/height getters that actually compile 2012-07-20 12:30:07 -04:00
Kristian Høgsberg
7ba218c9f8 shm: Add shm_buffer getters for width and height 2012-07-20 12:04:42 -04:00
Robert Ancell
0a9cd16f6a wayland-client: Add missing newline from an error message 2012-07-20 12:04:05 -04:00
Dmitry Guryanov
2e79c4877f remove listener from wl_data_source destroy_signal listener list
I've found a bug during wayland exploration - if you make two
drag'n'drops in weston client example, dnd - weston crashes with
segfault. I've tried to investigate it and found a problem.

In function drag_grab_button we first call data_device_end_drag_grab,
which sets seat->drag_data_source to NULL. Then we remove
listener from list only if drag_data_source is not NULL.

So if client will not free wl_data_source and start another drag'n'drop,
after the first one. Then two wl_data_source structures will be
free'd on client exit (let's name them s1 and s2).

next and prev pointer of
wl_data_source.resource.destroy_signal.listener_list in both
wl_data_source structures will be seat->drag_data_source_listener,
but next and prev in seat->drag_data_source_listener.link point
to listener_list in s2.

So if you try to iterate over listener_list in s1
then you get drag_data_source_listener as first item and
(struct wl_listener *)(&s2.resource.destroy_signal.listener_list)

Iteration over that list occurs in
wl_resource_destroy->destroy_resource->wl_signal_emit->wl_signal_emit
and try to call function at address of wl_resource->client, so
weston segfaults there.
2012-07-17 16:54:07 -04:00
Pekka Paalanen
9326498d03 server: fix wl_seat_set_keyboard
This makes wl_seat_set_keyboard similar to wl_seat_set_pointer in that
it's a no-op, if you try to set keyboard to NULL when it already is
NULL, instead of refusing to set it to NULL ever.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-07-10 14:08:01 -04:00
Pekka Paalanen
23bf48063f server: add lose_touch_focus()
Just like wl_keyboard and wl_pointer, add a signal handler for losing
touch focus.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-07-10 13:57:33 -04:00
Robert Ancell
e7e1296682 scanner: Include weston-client.h as the inline functions require it 2012-07-09 22:01:25 -04:00
Kristian Høgsberg
b4aff6b79f wayland-shm: Add return before we hit the error clean-up path
Regression in c94c0946db
2012-07-09 21:50:39 -04:00
Martin Olsson
dba322c1c0 Fixup source comment in wayland-util.h and fix typo in TODO 2012-07-09 18:11:06 -04:00
Martin Olsson
c94c0946db shm: Plug leak in shm_create_pool() 2012-07-09 17:59:45 -04:00
Martin Olsson
53bb401704 server: Don't crash for wl_seat_set_touch(seat, NULL) 2012-07-09 17:59:36 -04:00
Martin Olsson
e760ec9fa9 scanner: Plug memory leak in end_element() 2012-07-09 17:59:23 -04:00
Christopher James Halse Rogers
161c690b55 protocol: Add explicit nullable types
Most of the time it does not make sense to pass a NULL object, string, or array
to a protocol request. This commit adds an explicit “allow-null” attribute
to mark the request arguments where NULL makes sense.

Passing a NULL object, string, or array to a protocol request which is not
marked as allow-null is now an error. An implementation will never receive
a NULL value for these arguments from a client.

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
2012-07-02 13:53:02 -04:00
Dylan Noblesmith
af5f8cc200 wayland-client: reject socket paths longer than 108 bytes
Attempting to write anything longer into the embedded char
array would create a non-null-terminated string, and all
later reads would run off the end into invalid memory.

This is a hard limitation of AF_LOCAL/AF_UNIX sockets.
2012-06-30 19:58:36 +00:00
Dylan Noblesmith
00c25a0565 wayland-server: reject socket paths longer than 108 bytes
Attempting to write anything longer into the embedded char
array would create a non-null-terminated string, and all
later reads would run off the end into invalid memory.

This is a hard limitation of AF_LOCAL/AF_UNIX sockets.
2012-06-30 19:58:05 +00:00
Dylan Noblesmith
4522467268 wayland-server: add more logging of errors 2012-06-30 19:57:22 +00:00
Dylan Noblesmith
30ff420ca9 wayland-server: fix socket ownership race condition
Always unlink() the lock file before closing the file
descriptor for it. Otherwise, there is a race like this:

Process A closes fd, releasing the lock
Process B opens the same file, taking the lock
Process A unlinks the lock file
Process C opens the same file, which now no longer exists,
and takes the lock on the newly created lock file

Process B and C both 'own' the same display socket.

unlink()ing while holding the lock is effectively a better
way to release the lock atomically.
2012-06-30 19:50:09 +00:00
Dylan Noblesmith
9475257459 wayland-server: fix fd leak on error path
And restructure get_socket_lock() so it's clearer that it's
allocating a new file descriptor.

Uncovered by an upcoming test.
2012-06-30 19:37:42 +00:00
Dylan Noblesmith
cadd999292 drop use of strerror()
It isn't thread-safe. Use the %m conversion specifier instead,
like the rest of the code already does.
2012-06-30 19:37:04 +00:00
Dylan Noblesmith
bb6e48b1b0 wayland-server: reduce use of magic numbers
Make it clear what the significance of '5' and '113' actually is.
Also drop an unneeded function argument.
2012-06-30 19:37:04 +00:00
Kristian Høgsberg
9de9e39f87 Allocate client proxy automatically for new objects
When the server send a new object ID, the client used to have to allocate
the proxy manually and without type-safety.  We now allocate the proxy
in a client-side post-processing step on the incoming closure.
2012-06-28 22:01:58 -04:00
Kristian Høgsberg
9afb5f61f8 Send modifier event to pointer focus when it changes too 2012-06-22 14:38:12 -04:00
Kristian Høgsberg
67e16be8aa Send keyboard modifier event using the keyboard resource 2012-06-22 12:20:00 -04:00
Daniel Stone
bcefacb89d Maintain keyboard modifier state in wayland-server
Provide a slot for keyboard modifier state inside wl_keyboard for
implementations to update, and use this to send wl_keyboard:;modifier
events whenever the keyboard or pointer focus changes.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-06-22 11:06:44 -04:00
Kristian Høgsberg
c806dde7e6 data-device: Fix list corruption when the source goes away
If the data source is destroyed, the corresponding offers may stay around for
a little longer (until the owning client destroys it).  When the offer is
finally destroyed, we have to be careful to only remove the source
destroy listener if the source hasn't yet been destroyed.

Thanks to Martin Minarik for tracking down where the corruption happened.
2012-06-18 12:09:47 -04:00
Kristian Høgsberg
8dc57f4dda connection: Set closure->start in demarshal too 2012-06-13 10:45:38 -04:00
Kristian Høgsberg
46f9745c10 connection: Always malloc closure
This lets us allocate the closure just big enough and is a first step towards
a message queue.
2012-06-13 10:45:34 -04:00
Jonas Ådahl
1432bd62df wayland-server: Add destroy signal to wl_seat
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-06-12 20:18:42 -04:00
Jonas Ådahl
f36f32a0e0 wayland-util: wl_list_insert_list() should accept empty lists
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-06-12 20:18:38 -04:00
Pekka Paalanen
c29020332a server: require XDG_RUNTIME_DIR
An arbitrary fallback to the current directory is only confusing.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-06-06 13:07:33 -04:00
Pekka Paalanen
0c7ca38c7f client: require XDG_RUNTIME_DIR
An arbitrary fallback to the current directory is only confusing.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-06-06 13:07:25 -04:00
Kristian Høgsberg
aa792ad3d6 Add a focus change signal for wl_pointer and wl_keyboard 2012-06-05 09:56:42 -04:00
Kristian Høgsberg
68f058ffd3 data-device: Don't implement data source through data offer object
The wl_data_source object used to specify the implementation for data
offers created for it.  This means you need a data offer to retrieve the
data from the source, which makes it awkward to use in-process in a
compositor.  Now we instead have three virtual functions that can be
connected to a protocol object or in-process data-sources such as an
X server proxy or clipboard.
2012-06-03 17:30:12 -04:00