RE: Weston SDK

2013-02-15 Thread Eoff, Ullysses A
I do have some test extension scenarios in mind that would greatly benefit from 
having the “x11_compositor” and “x11_output” structures partially exported:

struct x11_compositor {
struct weston_compositor base;
Display *dpy;
xcb_connection_t *conn;
xcb_screen_t *screen;
};

struct x11_output {
struct weston_output base;
xcb_window_t window;
};

U. Artie

From: wayland-devel-bounces+ullysses.a.eoff=intel@lists.freedesktop.org 
[mailto:wayland-devel-bounces+ullysses.a.eoff=intel@lists.freedesktop.org] 
On Behalf Of Daniel Stone
Sent: Friday, February 15, 2013 11:42 AM
To: Fred Ollinger
Cc: Pekka Paalanen; Kristian Høgsberg; wayland-devel@lists.freedesktop.org
Subject: Re: Weston SDK

Hi,

On 15 February 2013 16:02, Fred Ollinger 
mailto:folli...@gmail.com>> wrote:
Surely there is functionality that plugin authors will want which will
not change?

Yes, but exactly what that is is a far more difficult question.  Help welcome.

Cheers,
Daniel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] Install header files and pkg-config file for external modules

2013-02-15 Thread Kristian Høgsberg
This patch installs the three header files that define the compositor
plugin interface as well as a pkg-config file.  This allows
building weston plugins outside the weston tree.  We currently don't make
any guarantees about the plugin API/ABI except that within a stable
branch we won't break it.
---
 configure.ac | 17 +++--
 src/Makefile.am  | 11 +++
 src/compositor.c |  9 +
 src/compositor.h |  8 ++--
 src/xwayland/Makefile.am |  1 +
 tests/Makefile.am|  6 +-
 6 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 32fbb4b..4f2a9e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,10 +1,21 @@
+m4_define([weston_major_version], [1])
+m4_define([weston_minor_version], [0])
+m4_define([weston_micro_version], [90])
+m4_define([weston_version],
+  [weston_major_version.weston_minor_version.weston_micro_version])
+
 AC_PREREQ([2.64])
 AC_INIT([weston],
-[1.0.90],
-
[https://bugs.freedesktop.org/enter_bug.cgi?product=Wayland&component=weston&version=1.0.90],
+[weston_version],
+
[https://bugs.freedesktop.org/enter_bug.cgi?product=Wayland&component=weston&version=weston_version],
 [weston],
 [http://wayland.freedesktop.org/])
 
+AC_SUBST([WESTON_VERSION_MAJOR], [weston_major_version])
+AC_SUBST([WESTON_VERSION_MINOR], [weston_minor_version])
+AC_SUBST([WESTON_VERSION_MICRO], [weston_micro_version])
+AC_SUBST([WESTON_VERSION], [weston_version])
+
 AC_CONFIG_HEADERS([config.h])
 
 AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
@@ -294,6 +305,8 @@ AC_CONFIG_FILES([Makefile
 shared/Makefile
 src/Makefile
 src/xwayland/Makefile
+src/version.h
+src/weston.pc
 clients/Makefile
 wcap/Makefile
 data/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index cfb072e..ce1aad3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,6 +2,7 @@ bin_PROGRAMS = weston   \
$(weston_launch)
 
 AM_CPPFLAGS =  \
+   -I$(top_srcdir)/shared  \
-DDATADIR='"$(datadir)"'\
-DMODULEDIR='"$(moduledir)"'\
-DLIBEXECDIR='"$(libexecdir)"'  \
@@ -77,6 +78,16 @@ endif
 
 endif # BUILD_WESTON_LAUNCH
 
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = weston.pc
+
+westonincludedir = @includedir@/weston
+westoninclude_HEADERS =\
+   version.h   \
+   compositor.h\
+   ../shared/matrix.h  \
+   ../shared/config-parser.h
+
 moduledir = @libdir@/weston
 module_LTLIBRARIES =   \
$(desktop_shell)\
diff --git a/src/compositor.c b/src/compositor.c
index 63fe793..d1fd2e5 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -53,6 +53,7 @@
 #include "compositor.h"
 #include "../shared/os-compatibility.h"
 #include "git-version.h"
+#include "version.h"
 
 static struct wl_list child_process_list;
 static struct weston_compositor *segv_compositor;
@@ -3041,6 +3042,14 @@ weston_compositor_shutdown(struct weston_compositor *ec)
wl_event_loop_destroy(ec->input_loop);
 }
 
+WL_EXPORT void
+weston_version(int *major, int *minor, int *micro)
+{
+   *major = WESTON_VERSION_MAJOR;
+   *minor = WESTON_VERSION_MINOR;
+   *micro = WESTON_VERSION_MICRO;
+}
+
 static int on_term_signal(int signal_number, void *data)
 {
struct wl_display *display = data;
diff --git a/src/compositor.h b/src/compositor.h
index c0694e8..c39abe3 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -28,8 +28,9 @@
 #include 
 #include 
 
-#include "../shared/matrix.h"
-#include "../shared/config-parser.h"
+#include "version.h"
+#include "matrix.h"
+#include "config-parser.h"
 
 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
 
@@ -496,6 +497,9 @@ enum weston_key_state_update {
 };
 
 void
+weston_version(int *major, int *minor, int *micro);
+
+void
 weston_surface_update_transform(struct weston_surface *surface);
 
 void
diff --git a/src/xwayland/Makefile.am b/src/xwayland/Makefile.am
index 8f3bddd..77124ff 100644
--- a/src/xwayland/Makefile.am
+++ b/src/xwayland/Makefile.am
@@ -1,4 +1,5 @@
 AM_CPPFLAGS =  \
+   -I$(top_srcdir)/shared  \
-DDATADIR='"$(datadir)"'\
-DMODULEDIR='"$(moduledir)"'\
-DLIBEXECDIR='"$(libexecdir)"'  \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 11cd4ec..f2960f1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -32,7 +32,11 @@ check_PROGRAMS = \
$(weston_tests)
 
 AM_CFLAGS = $(GCC_CFLAGS)
-AM_CPPFLAGS = -I$(top_srcdir)/src -DUNIT_TEST $(COMPOS

Patch queue update

2013-02-15 Thread Kristian Høgsberg
Hi all,

Here's the patch queue update for today.  Since last time, I've merge
Tiagos non-blocking auth for xwayland and Jans input method patches.
New on the list is the FreeBSD porting patches from Philip.  I was
hoping to go through Jonas' per-output workspace series this week, but
the 1.0.5 release and bug-fixing took up quite a bit of my time.

Kristian


* FreeBSD patches (Philip Withnall, Feb 15)

  - Doesn't look too invasive, but need to review in detail.


* Probe-area (Robert Bradford)

  - Looks good, what we've discussed in the past.  Just need
documentation update to describe self-destruction of result object.

  - Tweaks from Pekka?

  - Pending verification in GTK+, potential issue with right-side clipping?


* Per-output workspaces (Jonas Ådahl, Jan 26)

  - Patches on list, discussed the core stacking implementation with
Jonas before, should be ok.


* Subsurface (Pekka Paalanen)

  - Still work-in-progress.  There are a few corner cases around
commit behavior and clipping that we need to get consensus on.
Also, I think we need to allow recursive sub-surfaces.

  - Up to v2 now.  Verified useful for maliit and Qt decorations.


* Language binding patches (Jason Ekstrand)

  - v2 looks good.  Not much happened since last time.

  - New series is "custom dispatchers".  Looks very clean.


* surface_data and surface panel list (Scott Moreau)

  - This one was in good shape at the last resend, but I think there
was a few more issues we still we discussion.  I forget (sorry).


* resize from center (Scott Moreau)

  - I think we got stuck discussion how to trigger resize-from-center.
I think we can just handle it in the compositor, by remembering
the initial center (pre-resize) and then center the window there
if shift is pressed during resize, and jump back to normal
resizing if shift is released.

  - Scott said he got the idea working, but still some issues to work
out.

  - Patches on list to implement this, tested and briefly reviewed.


* Gamma correct compositing patches (John Kåre Alsaker)

  - Would like to break this into two or three series: first series to
do the dynamic shader creation using GLSL #ifdef and including a
generated "#define YUV_SHADER" snippet first to determine which
combination to compile.  Then the indirect rendering series and
then the color correct compositing patches.
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 0/5] Input method support cleanup

2013-02-15 Thread Kristian Høgsberg
On Thu, Jan 31, 2013 at 03:52:18PM +0100, Jan Arne Petersen wrote:
> From: Jan Arne Petersen 
> 
> Another series of input method support patches. Mostly some
> cleanups in the protocol:
> 
> * Remove some unused requests events (set_preedit etc)
> 
> * Add a commit request to allow to batch different state
>   changes on application side together. That needs some more
>   documentation (also how it works in the other direction on
>   preedit_string and commit_string events).
> 
> * Add show/hide input panel requests to allow not always shwoing
>   input panels when activated (for example requiring an extra touch).
> 
> * Rename set_micro_focus to set_cursor_rectangle to make more
>   clear what the requests does.
> 
> * Split out the cursor position change from the commit_string into
>   an own event (and also allow to change the anchor position).

Grabbed this one too, thanks.
Kristian

> Jan Arne Petersen (5):
>   text: Remove unused requests/events
>   text: Add commit request
>   text: Add show/hide_input_panel requests
>   text: Rename set_micro_focus request
>   text: Split out cursor_position
> 
>  clients/editor.c   | 103 
> ++---
>  clients/keyboard.c |  41 --
>  clients/weston-simple-im.c |  27 +---
>  protocol/input-method.xml  |   7 ++-
>  protocol/text.xml  |  34 ---
>  src/shell.c|   3 ++
>  src/text-backend.c |  75 +++--
>  7 files changed, 217 insertions(+), 73 deletions(-)
> 
> -- 
> 1.8.1
> 
> ___
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 00/18] Input method support patches

2013-02-15 Thread Kristian Høgsberg
On Wed, Jan 16, 2013 at 09:26:37PM +0100, Jan Arne Petersen wrote:
> From: Jan Arne Petersen 
> 
> There are some penfing input method support patches. I rebased them on master.

I grabbed this series, it mostly looks good.  There's still some
discussion about these and the other series, but for now I just want
to land this series to avoid the patches getting stale.

Kristian

> * Add pre-edit styling support to the text protocol and the
> keyboard and editor examples. The editor example client
> depends on pango (for text layout) now.
> 
> * Support content types in text protocol. Content is defined by a hint
> bitmask and a purpose field.
> 
> * Add invoke_action request to text protocol. Called by the client when the 
> word
> currently being composed is tapped by the user. Input methods often use this
> information to offer more word suggestions to the user.
> 
> * Fix weston key bindings with input methods
> 
> * Fix some input_panel issues in shell
> 
> Jan Arne Petersen (18):
>   text: add pre-edit styling support to protocol
>   text: add serial argument to text protocol
>   editor: support commit on reset
>   keyboard: Add support for pre-edit styling
>   editor: add support for pre-edit styling
>   text: Add content type support to text protocol
>   keyboard: Add support for a numeric layout
>   editor: Add content type example
>   text: add support for invoke_action request
>   editor: add support for invoke_action
>   keyboard: add support for invoke_action
>   simple-im: fix for protocol changes
>   text: fix weston key bindings with input methods
>   doc: add some more text protocol documentation
>   editor: Add support for backspace keysym events
>   shell: Do not crash when hiding input_panel
>   shell: Do not hang after setting input_panel twice
>   text: Move input_panel interface to input-method
> 
>  clients/Makefile.am|   8 +-
>  clients/editor.c   | 617 
> +++--
>  clients/keyboard.c | 252 +++---
>  clients/weston-simple-im.c |  53 +++-
>  configure.ac   |   3 +
>  protocol/desktop-shell.xml |  18 --
>  protocol/input-method.xml  |  51 
>  protocol/text.xml  | 115 -
>  src/compositor.c   |  29 ++-
>  src/compositor.h   |   9 +-
>  src/shell.c| 155 +---
>  src/text-backend.c | 136 +++---
>  src/util.c |   3 +
>  tests/weston-test.c|   2 +-
>  14 files changed, 989 insertions(+), 462 deletions(-)
> 
> -- 
> 1.8.1
> 
> ___
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH] shell: Set the DPMS state if the screensaver fails to launch or dies

2013-02-15 Thread Kristian Høgsberg
On Fri, Feb 15, 2013 at 06:44:19PM +0200, Ander Conselvan de Oliveira wrote:
> From: Ander Conselvan de Oliveira 
> 
> The lock hook in desktop-shell only changes the DPMS state the second
> time it is called, because during the first time it launches the
> screensaver and wakes the compositor again when the screensaver surface
> is configured. However, if the screensaver fails to launch, the output
> is left in an enabled state, even thought there's no content being
> displayed on the screen.
> 
> Fix this by disabling the outputs when the screensaver dies if the
> shell is still locked.

Yeah, that looks like the problem.  I've committed the patch and
closed the bug, but this state machine is a little wonky overall.
First off, once we get sigchild from failing to launch the
screensaver, the compositor is still in th IDLE state.  This means we
still have a timer running and eventually ends up calling into lock
again, and setting dpms off once more.  We could add a
weston_compositor_sleep() that sets the sleep state and cancels the
timer, and then call that from the sigchild handler as well.

However, I think we need to overhaul the split between shell.c and
core weston a bit more.  The whole fade-to-black behavior shouldn't be
hard-coded in core weston, and the lock and unlock signals would be
better named idle_signal and wake_signal and they'd do only that.
Changing compositor state and fading in or out would be controlled by
shell.c.  Then we can track the fade/screensaver/lock dialog/dpms
state in shell.c and it should all be a little easier to follow, and
we avoid the hardcoded fade policy in core weston.  We can move all
the fade code to util.c.  Or maybe we should move all the
spring/animation/fade code from util. into animation.c, the binding
code into bindings.c and the last couple of util.c functions back into
compositor.c.  And then just kill off util.c (always avoid util.c
files).

Also, I don't know if I have a problem with my kernel or something,
but my laptop never comes back after we hit dpms off.  I doubt it's a
kernel problem though - X works fine, and I had the same problem on my
old laptop with an older Fedora install.  Did you see this problem or
were you able to recover?

Kristian

> https://bugs.freedesktop.org/show_bug.cgi?id=60084
> ---
>  src/shell.c |9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/shell.c b/src/shell.c
> index dcbabf3..8d89bc2 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -2085,7 +2085,16 @@ static const struct wl_shell_interface 
> shell_implementation = {
>  static void
>  handle_screensaver_sigchld(struct weston_process *proc, int status)
>  {
> + struct desktop_shell *shell =
> + container_of(proc, struct desktop_shell, screensaver.process);
> + struct weston_output *output;
> +
>   proc->pid = 0;
> +
> + if (shell->locked)
> + wl_list_for_each(output, &shell->compositor->output_list, link)
> + if (output->set_dpms)
> + output->set_dpms(output, WESTON_DPMS_STANDBY);
>  }
>  
>  static void
> -- 
> 1.7.9.5
> 
> ___
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: Weston SDK

2013-02-15 Thread Daniel Stone
Hi,

On 15 February 2013 16:02, Fred Ollinger  wrote:

> Surely there is functionality that plugin authors will want which will
> not change?
>

Yes, but exactly what that is is a far more difficult question.  Help
welcome.

Cheers,
Daniel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 05/12] event-loop-test: Add some more assertions and work around a FreeBSD bug

2013-02-15 Thread Dima Ryazanov
Ah, got it, sorry.

On Fri, Feb 15, 2013 at 10:20 AM, Pekka Paalanen wrote:

> On Fri, 15 Feb 2013 09:48:35 -0500
> Dima Ryazanov  wrote:
>
> > On Fri, Feb 15, 2013 at 7:56 AM, Philip Withnall  >wrote:
> >
> > > There’s a bug in FreeBSD’s handling of timer events which means we
> have to
> > > be more relaxed about how we check when timer events have happened
> because
> > > FreeBSD can’t manage enough precision on scheduling the events.
> > >
> > > Signed-off-by: Philip Withnall 
> > > ---
> > >  tests/event-loop-test.c | 22 --
> > >  1 file changed, 16 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c
> > > index c46d3b0..cf9dabe 100644
> > > --- a/tests/event-loop-test.c
> > > +++ b/tests/event-loop-test.c
> > > @@ -155,10 +155,11 @@ TEST(event_loop_signal)
> > >
> > > source = wl_event_loop_add_signal(loop, SIGUSR1,
> > >   signal_callback, &got_it);
> > > -   wl_event_loop_dispatch(loop, 0);
> > > +   assert(source);
> > > +   assert(wl_event_loop_dispatch(loop, 0) == 0);
> > >
> >
> > You shouldn't put code with side effects inside asserts, since it'll be
> > compiled out in release mode.
>
> That's actually standard procedure in the test suite. The test suite
> refuses to work at all, if you compile asserts away. We rely on them
> here, but you are right in general.
>
>
> Thanks,
> pq
>
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] shell: Set the DPMS state if the screensaver fails to launch or dies

2013-02-15 Thread Ander Conselvan de Oliveira
From: Ander Conselvan de Oliveira 

The lock hook in desktop-shell only changes the DPMS state the second
time it is called, because during the first time it launches the
screensaver and wakes the compositor again when the screensaver surface
is configured. However, if the screensaver fails to launch, the output
is left in an enabled state, even thought there's no content being
displayed on the screen.

Fix this by disabling the outputs when the screensaver dies if the
shell is still locked.

https://bugs.freedesktop.org/show_bug.cgi?id=60084
---
 src/shell.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/src/shell.c b/src/shell.c
index dcbabf3..8d89bc2 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -2085,7 +2085,16 @@ static const struct wl_shell_interface 
shell_implementation = {
 static void
 handle_screensaver_sigchld(struct weston_process *proc, int status)
 {
+   struct desktop_shell *shell =
+   container_of(proc, struct desktop_shell, screensaver.process);
+   struct weston_output *output;
+
proc->pid = 0;
+
+   if (shell->locked)
+   wl_list_for_each(output, &shell->compositor->output_list, link)
+   if (output->set_dpms)
+   output->set_dpms(output, WESTON_DPMS_STANDBY);
 }
 
 static void
-- 
1.7.9.5

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: Weston SDK

2013-02-15 Thread Fred Ollinger
Why not have an external api which does not change?

Surely there is functionality that plugin authors will want which will
not change?

I know that one objection is that there's the question of who is going
to maintain the glue b/w the external and internal. Perhaps we can
leave that to the plugin authors...

Sincrerely,

Fred

>> Now, I don't want this to slow down what we can do with weston
>> internals, so this won't be stable API across major releases for the
>> forseeable future.  But for a stable branch we should be able to avoid
>> breaking the plugin API.  For 1.0 for example, we haven't changed the
>> API or ABI at all.
>>
>> Another caveat is that this doesn't imply that the exported API is
>> particular useful or coherent.  I think what we have is fairly decent
>> though, it's just that we never developed it with an eye to be an
>> external, self-contained API.  So we may be exposing too little or too
>> much or there may be broken or inconsitent stuff in there.  But I
>> think the first step towards working this out is to try to expose the
>> API and just be careful about not promising too much in
>> terms of usefulness or stability initially.
>
>
> Thanks,
> pq
> ___
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 02/12] event-loop: Add support for BSD???s kevent() instead of epoll()

2013-02-15 Thread Jason Ekstrand
I'm a little worried that we're going to make event-loop too much of a
mess of #defines without covering all the cases.  My use-case,
Android, is Linux but not GNU/Linux; it uses something called Bionic.
Same kernel, different standard library and a different set of system
calls.  Specifically, timerfd and signalfd are missing.

Would it be a better overall solution if we simply replace timerfd and
signalfd with a more generic architecture and then move the guts of
the event loop to poll or select?  Another idea that was brought up on
IRC this last weekend was to use an external library such as libevent
where they've already done all of the event abstraction for us.
However, that involves pulling in another dependency which may not be
worth it.

Thoughts?

--Jason Ekstrand

On Fri, Feb 15, 2013 at 6:56 AM, Philip Withnall  wrote:
> This is a large step towards supporting the BSDs. There’s quite a lot of
> little in the test suite).
>
> Signed-off-by: Philip Withnall 
> ---
>  configure.ac |   8 ++
>  src/event-loop.c | 361 
> +--
>  src/wayland-os.c |  23 ++-
>  src/wayland-os.h |   7 +
>  tests/os-wrappers-test.c |  34 +
>  5 files changed, 419 insertions(+), 14 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 883411c..935afbd 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -41,6 +41,14 @@ AC_SUBST(GCC_CFLAGS)
>
>  AC_CHECK_FUNCS([accept4 mkostemp])
>
> +# Use epoll on Linux or kqueue on BSD
> +AC_CHECK_HEADERS([sys/epoll.h sys/event.h])
> +if test "x$ac_cv_header_sys_epoll_h" != "xyes" && test 
> "x$ac_cv_header_sys_event_h" != "xyes"; then
> +   AC_MSG_ERROR([Can't find sys/epoll.h or sys/event.h. Please ensure 
> either epoll or kqueue is available.])
> +fi
> +
> +AC_CHECK_HEADERS([sys/signalfd.h sys/timerfd.h])
> +
>  AC_ARG_ENABLE([scanner],
>[AC_HELP_STRING([--disable-scanner],
>[Disable compilation of wayland-scanner])],
> diff --git a/src/event-loop.c b/src/event-loop.c
> index e556cc7..05baa48 100644
> --- a/src/event-loop.c
> +++ b/src/event-loop.c
> @@ -20,6 +20,8 @@
>   * OF THIS SOFTWARE.
>   */
>
> +#include "../config.h"
> +
>  #include 
>  #include 
>  #include 
> @@ -29,9 +31,23 @@
>  #include 
>  #include 
>  #include 
> +
> +#ifdef HAVE_SYS_EPOLL_H
>  #include 
> +#ifdef HAVE_SYS_SIGNALFD_H
>  #include 
> +#endif /* signalfd */
> +#ifdef HAVE_SYS_TIMERFD_H
>  #include 
> +#endif /* timerfd */
> +#elif HAVE_SYS_EVENT_H
> +#include 
> +#include 
> +#include 
> +#else /* !epoll && !kqueue */
> +#error "Unsupported event system. Only epoll and kqueue are supported."
> +#endif
> +
>  #include 
>  #include 
>  #include "wayland-server.h"
> @@ -39,7 +55,7 @@
>  #include "wayland-os.h"
>
>  struct wl_event_loop {
> -   int epoll_fd;
> +   int event_fd;
> struct wl_list check_list;
> struct wl_list idle_list;
> struct wl_list destroy_list;
> @@ -48,8 +64,13 @@ struct wl_event_loop {
>  };
>
>  struct wl_event_source_interface {
> +#ifdef HAVE_SYS_EPOLL_H
> int (*dispatch)(struct wl_event_source *source,
> struct epoll_event *ep);
> +#elif HAVE_SYS_EVENT_H
> +   int (*dispatch)(struct wl_event_source *source,
> +   struct kevent *ep);
> +#endif
>  };
>
>  struct wl_event_source {
> @@ -66,11 +87,13 @@ struct wl_event_source_fd {
> int fd;
>  };
>
> +#ifdef HAVE_SYS_EPOLL_H
>  static int
>  wl_event_source_fd_dispatch(struct wl_event_source *source,
> struct epoll_event *ep)
>  {
> -   struct wl_event_source_fd *fd_source = (struct wl_event_source_fd *) 
> source;
> +   struct wl_event_source_fd *fd_source =
> +   (struct wl_event_source_fd *) source;
> uint32_t mask;
>
> mask = 0;
> @@ -85,11 +108,32 @@ wl_event_source_fd_dispatch(struct wl_event_source 
> *source,
>
> return fd_source->func(fd_source->fd, mask, source->data);
>  }
> +#elif HAVE_SYS_EVENT_H
> +static int
> +wl_event_source_fd_dispatch(struct wl_event_source *source,
> +struct kevent *ev)
> +{
> +   struct wl_event_source_fd *fd_source =
> +   (struct wl_event_source_fd *) source;
> +   uint32_t mask;
> +
> +   mask = 0;
> +   if (ev->filter == EVFILT_READ)
> +   mask |= WL_EVENT_READABLE;
> +   if (ev->filter == EVFILT_WRITE)
> +   mask |= WL_EVENT_WRITABLE;
> +   if (ev->flags & EV_ERROR)
> +   mask |= WL_EVENT_ERROR;
> +
> +   return fd_source->func(fd_source->fd, mask, source->data);
> +}
> +#endif
>
>  struct wl_event_source_interface fd_source_interface = {
> wl_event_source_fd_dispatch,
>  };
>
> +#ifdef HAVE_SYS_EPOLL_H
>  static struct wl_event_source *
>  add_source(struct wl_event_loop *loop,
>struct wl_event_source *source, uint32_t mask, void *data)
> @@ -113,7 +157,47 @@ add

Re: [PATCH 05/12] event-loop-test: Add some more assertions and work around a FreeBSD bug

2013-02-15 Thread Pekka Paalanen
On Fri, 15 Feb 2013 09:48:35 -0500
Dima Ryazanov  wrote:

> On Fri, Feb 15, 2013 at 7:56 AM, Philip Withnall 
> wrote:
> 
> > There’s a bug in FreeBSD’s handling of timer events which means we have to
> > be more relaxed about how we check when timer events have happened because
> > FreeBSD can’t manage enough precision on scheduling the events.
> >
> > Signed-off-by: Philip Withnall 
> > ---
> >  tests/event-loop-test.c | 22 --
> >  1 file changed, 16 insertions(+), 6 deletions(-)
> >
> > diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c
> > index c46d3b0..cf9dabe 100644
> > --- a/tests/event-loop-test.c
> > +++ b/tests/event-loop-test.c
> > @@ -155,10 +155,11 @@ TEST(event_loop_signal)
> >
> > source = wl_event_loop_add_signal(loop, SIGUSR1,
> >   signal_callback, &got_it);
> > -   wl_event_loop_dispatch(loop, 0);
> > +   assert(source);
> > +   assert(wl_event_loop_dispatch(loop, 0) == 0);
> >
> 
> You shouldn't put code with side effects inside asserts, since it'll be
> compiled out in release mode.

That's actually standard procedure in the test suite. The test suite
refuses to work at all, if you compile asserts away. We rely on them
here, but you are right in general.


Thanks,
pq
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 05/12] event-loop-test: Add some more assertions and work around a FreeBSD bug

2013-02-15 Thread Dima Ryazanov
On Fri, Feb 15, 2013 at 7:56 AM, Philip Withnall wrote:

> There’s a bug in FreeBSD’s handling of timer events which means we have to
> be more relaxed about how we check when timer events have happened because
> FreeBSD can’t manage enough precision on scheduling the events.
>
> Signed-off-by: Philip Withnall 
> ---
>  tests/event-loop-test.c | 22 --
>  1 file changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c
> index c46d3b0..cf9dabe 100644
> --- a/tests/event-loop-test.c
> +++ b/tests/event-loop-test.c
> @@ -155,10 +155,11 @@ TEST(event_loop_signal)
>
> source = wl_event_loop_add_signal(loop, SIGUSR1,
>   signal_callback, &got_it);
> -   wl_event_loop_dispatch(loop, 0);
> +   assert(source);
> +   assert(wl_event_loop_dispatch(loop, 0) == 0);
>

You shouldn't put code with side effects inside asserts, since it'll be
compiled out in release mode.


> assert(!got_it);
> -   kill(getpid(), SIGUSR1);
> -   wl_event_loop_dispatch(loop, 0);
> +   assert(kill(getpid(), SIGUSR1) == 0);
> +   assert(wl_event_loop_dispatch(loop, 0) == 0);
> assert(got_it);
>
> wl_event_source_remove(source);
> @@ -183,12 +184,21 @@ TEST(event_loop_timer)
> int got_it = 0;
>
> source = wl_event_loop_add_timer(loop, timer_callback, &got_it);
> -   wl_event_source_timer_update(source, 10);
> -   wl_event_loop_dispatch(loop, 0);
> +   assert(source);
> +   assert(wl_event_source_timer_update(source, 10) == 0);
> +   assert(wl_event_loop_dispatch(loop, 0) == 0);
> assert(!got_it);
> -   wl_event_loop_dispatch(loop, 20);
> +   /* FreeBSD has a bug where it converts ms_timeout to ticks; it
> always adds 1 to the tick count.
> +* Consequently, we need to grossly overcompensate here.
> +* See:
> http://unix.derkeiler.com/Mailing-Lists/FreeBSD/hackers/2012-07/msg00319.html*/
> +   assert(wl_event_loop_dispatch(loop, 50) == 0);
> assert(got_it);
>
> +   /* Check it doesn't fire again. */
> +   got_it = 0;
> +   assert(wl_event_loop_dispatch(loop, 20) == 0);
> +   assert(!got_it);
> +
> wl_event_source_remove(source);
> wl_event_loop_destroy(loop);
>  }
> --
> 1.7.11.7
>
>
> ___
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 12/12] wayland-server.c: Fix dereferencing types of new objects

2013-02-15 Thread Philip Withnall
The type should be stored in the same location as the argument. This
fixes the test suite on FreeBSD.

Signed-off-by: Philip Withnall 
---
 src/wayland-server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 8eef048..a6966e1 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -214,7 +214,7 @@ deref_new_objects(struct wl_closure *closure)
switch (signature[i]) {
case 'n':
closure->args[i + 2] = *(uint32_t **) closure->args[i + 
2];
-   closure->types[i] = &ffi_type_uint32;
+   closure->types[i + 2] = &ffi_type_uint32;
break;
}
}
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 11/12] queue-test: Add another assertion

2013-02-15 Thread Philip Withnall
Ensure that the round trip succeeds.

Signed-off-by: Philip Withnall 
---
 tests/queue-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/queue-test.c b/tests/queue-test.c
index c9d3668..da2b237 100644
--- a/tests/queue-test.c
+++ b/tests/queue-test.c
@@ -86,7 +86,7 @@ client_test_proxy_destroy(void)
registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, ®istry_listener,
 &counter);
-   wl_display_roundtrip(display);
+   client_assert(wl_display_roundtrip(display) > -1);
 
client_assert(counter == 1);
 
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 10/12] tests: Use /dev/fd on FreeBSD to determine open FDs

2013-02-15 Thread Philip Withnall
FreeBSD doesn’t have /proc/self/fd; it uses fdescfs instead, which must be
mounted explicitly before the test suite can be run, using:
mount -f fdescfs fdescfs /dev/fd

Signed-off-by: Philip Withnall 
---
 tests/test-helpers.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index 4761b09..969e4f1 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -20,6 +20,12 @@
  * OF THIS SOFTWARE.
  */
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_PARAM_H
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -28,6 +34,16 @@
 
 #include "test-runner.h"
 
+#ifdef __FreeBSD__
+/* FreeBSD uses fdescfs (which must be mounted using:
+ *mount -t fdescfs fdescfs /dev/fd
+ * before the test suite can be run). */
+#define OPEN_FDS_DIR "/dev/fd"
+#else
+/* Linux. */
+#define OPEN_FDS_DIR "/proc/self/fd"
+#endif
+
 int
 count_open_fds(void)
 {
@@ -35,8 +51,8 @@ count_open_fds(void)
struct dirent *ent;
int count = 0;
 
-   dir = opendir("/proc/self/fd");
-   assert(dir && "opening /proc/self/fd failed.");
+   dir = opendir(OPEN_FDS_DIR);
+   assert(dir && "opening " OPEN_FDS_DIR " failed.");
 
errno = 0;
while ((ent = readdir(dir))) {
@@ -45,7 +61,7 @@ count_open_fds(void)
continue;
count++;
}
-   assert(errno == 0 && "reading /proc/self/fd failed.");
+   assert(errno == 0 && "reading " OPEN_FDS_DIR " failed.");
 
closedir(dir);
 
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 09/12] tests: Update test suite to work on FreeBSD

2013-02-15 Thread Philip Withnall
 • Add missing #includes which FreeBSD needs.
 • Disable leak checking because malloc() and friends can’t be overridden.
 • Use waitpid() instead of waitid() (which doesn’t exist on FreeBSD).

Signed-off-by: Philip Withnall 
---
 configure.ac|  7 +++
 tests/queue-test.c  |  5 +
 tests/test-runner.c | 44 
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 35b89c8..a63b6b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,6 +56,13 @@ AC_CHECK_HEADERS([sys/ucred.h])
 AC_CHECK_LIB([dl], [dlsym], [DL_LIBS=-ldl])
 AC_SUBST([DL_LIBS])
 
+# Defines __FreeBSD__ if we're on FreeBSD.
+AC_CHECK_HEADERS([sys/param.h])
+
+# waitid() and signal.h are needed for the test suite.
+AC_CHECK_FUNCS([waitid])
+AC_CHECK_HEADERS([signal.h])
+
 AC_ARG_ENABLE([scanner],
   [AC_HELP_STRING([--disable-scanner],
   [Disable compilation of wayland-scanner])],
diff --git a/tests/queue-test.c b/tests/queue-test.c
index 3abb71f..c9d3668 100644
--- a/tests/queue-test.c
+++ b/tests/queue-test.c
@@ -20,6 +20,8 @@
  * OF THIS SOFTWARE.
  */
 
+#include "../config.h"
+
 #include 
 #include 
 #include 
@@ -27,6 +29,9 @@
 #include 
 #include 
 #include 
+#ifdef HAVE_SIGNAL_H
+#include 
+#endif
 
 #include "wayland-client.h"
 #include "wayland-server.h"
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 9c6865a..27e72ed 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -22,6 +22,12 @@
 
 #define _GNU_SOURCE
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_PARAM_H
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -34,15 +40,18 @@
 #include "test-runner.h"
 
 static int num_alloc;
+int leak_check_enabled;
+
+extern const struct test __start_test_section, __stop_test_section;
+
+/* This is all disabled for FreeBSD because it gives "can't allocate initial
+ * thread" aborts otherwise. */
+#ifndef __FreeBSD__
 static void* (*sys_malloc)(size_t);
 static void (*sys_free)(void*);
 static void* (*sys_realloc)(void*, size_t);
 static void* (*sys_calloc)(size_t, size_t);
 
-int leak_check_enabled;
-
-extern const struct test __start_test_section, __stop_test_section;
-
 __attribute__ ((visibility("default"))) void *
 malloc(size_t size)
 {
@@ -76,6 +85,7 @@ calloc(size_t nmemb, size_t size)
 
return sys_calloc(nmemb, size);
 }
+#endif /* !__FreeBSD__ */
 
 static const struct test *
 find_test(const char *name)
@@ -127,8 +137,13 @@ int main(int argc, char *argv[])
const struct test *t;
pid_t pid;
int total, pass;
+#ifdef HAVE_WAITID
siginfo_t info;
+#else /* if HAVE_WAITPID */
+   int status;
+#endif /* HAVE_WAITPID */
 
+#ifndef __FreeBSD__
/* Load system malloc, free, and realloc */
sys_calloc = dlsym(RTLD_NEXT, "calloc");
sys_realloc = dlsym(RTLD_NEXT, "realloc");
@@ -136,6 +151,10 @@ int main(int argc, char *argv[])
sys_free = dlsym(RTLD_NEXT, "free");
 
leak_check_enabled = !getenv("NO_ASSERT_LEAK_CHECK");
+#else /* if !__FreeBSD__ */
+   /* Disable leak checking on FreeBSD since we can't override malloc(). */
+   leak_check_enabled = 0;
+#endif /* __FreeBSD__ */
 
if (argc == 2 && strcmp(argv[1], "--help") == 0)
usage(argv[0], EXIT_SUCCESS);
@@ -160,6 +179,7 @@ int main(int argc, char *argv[])
if (pid == 0)
run_test(t); /* never returns */
 
+#ifdef HAVE_WAITID
if (waitid(P_ALL, 0, &info, WEXITED)) {
fprintf(stderr, "waitid failed: %m\n");
abort();
@@ -177,6 +197,22 @@ int main(int argc, char *argv[])
fprintf(stderr, "signal %d", info.si_status);
break;
}
+#else /* if HAVE_WAITPID */
+   if (waitpid(-1, &status, 0) == -1) {
+   fprintf(stderr, "waitpid failed: %s\n",
+   strerror(errno));
+   abort();
+   }
+
+   fprintf(stderr, "test \"%s\":\t", t->name);
+   if (WIFEXITED(status)) {
+   fprintf(stderr, "exit status %d", WEXITSTATUS(status));
+   if (WEXITSTATUS(status) == EXIT_SUCCESS)
+   success = 1;
+   } else if (WIFSIGNALED(status)) {
+   fprintf(stderr, "signal %d", WTERMSIG(status));
+   }
+#endif /* HAVE_WAITPID */
 
if (t->must_fail)
success = !success;
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 08/12] wayland-server: Abort if a read from a client gives 0 length

2013-02-15 Thread Philip Withnall
This happens if the socket has been gracefully closed.

Signed-off-by: Philip Withnall 
---
 src/wayland-server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 614dd2f..8eef048 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -252,7 +252,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
len = 0;
if (mask & WL_EVENT_READABLE) {
len = wl_connection_read(connection);
-   if (len < 0 && errno != EAGAIN) {
+   if (len <= 0 && errno != EAGAIN) {
wl_client_destroy(client);
return 1;
}
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 07/12] wayland-os: Always use CLOEXEC fallbacks on FreeBSD

2013-02-15 Thread Philip Withnall
FreeBSD doesn’t support useful flags like SOCK_CLOEXEC, so we have to suffer
the race condition and always use the fcntl(F_SETFD, FD_CLOEXEC) fallback
on FreeBSD.

This also requires disabling some tests which test whether the fallbacks have
been hit.

Signed-off-by: Philip Withnall 
---
 src/wayland-os.c | 26 ++
 src/wayland-os.h |  3 +++
 tests/client-test.c  |  3 ++-
 tests/connection-test.c  |  6 +++---
 tests/os-wrappers-test.c | 15 +--
 5 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/src/wayland-os.c b/src/wayland-os.c
index aad6da6..7d69476 100644
--- a/src/wayland-os.c
+++ b/src/wayland-os.c
@@ -66,26 +66,50 @@ wl_os_socket_cloexec(int domain, int type, int protocol)
 {
int fd;
 
+#ifdef SOCK_CLOEXEC
fd = socket(domain, type | SOCK_CLOEXEC, protocol);
if (fd >= 0)
return fd;
if (errno != EINVAL)
return -1;
+#endif
 
fd = socket(domain, type, protocol);
return set_cloexec_or_close(fd);
 }
 
 int
+wl_os_socketpair_cloexec(int domain, int type, int protocol, int sv[2])
+{
+   int retval;
+
+#ifdef SOCK_CLOEXEC
+   retval = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
+   if (retval >= 0)
+   return retval;
+   if (errno != EINVAL)
+   return -1;
+#endif
+
+   retval = socketpair(domain, type, protocol, sv);
+   if (set_cloexec_or_close(sv[0]) < 0 || set_cloexec_or_close(sv[1]) < 0)
+   retval = -1;
+
+   return retval;
+}
+
+int
 wl_os_dupfd_cloexec(int fd, long minfd)
 {
int newfd;
 
+#ifdef F_DUPFD_CLOEXEC
newfd = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
if (newfd >= 0)
return newfd;
if (errno != EINVAL)
return -1;
+#endif
 
newfd = fcntl(fd, F_DUPFD, minfd);
return set_cloexec_or_close(newfd);
@@ -125,6 +149,7 @@ recvmsg_cloexec_fallback(int sockfd, struct msghdr *msg, 
int flags)
 ssize_t
 wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags)
 {
+#ifdef MSG_CMSG_CLOEXEC
ssize_t len;
 
len = recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC);
@@ -132,6 +157,7 @@ wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int 
flags)
return len;
if (errno != EINVAL)
return -1;
+#endif
 
return recvmsg_cloexec_fallback(sockfd, msg, flags);
 }
diff --git a/src/wayland-os.h b/src/wayland-os.h
index b2c3567..0db67e1 100644
--- a/src/wayland-os.h
+++ b/src/wayland-os.h
@@ -27,6 +27,9 @@ int
 wl_os_socket_cloexec(int domain, int type, int protocol);
 
 int
+wl_os_socketpair_cloexec(int domain, int type, int protocol, int sv[2]);
+
+int
 wl_os_dupfd_cloexec(int fd, long minfd);
 
 ssize_t
diff --git a/tests/client-test.c b/tests/client-test.c
index 5cf374d..1d7c7fa 100644
--- a/tests/client-test.c
+++ b/tests/client-test.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 
+#include "wayland-os.h"
 #include "wayland-server.h"
 #include "wayland-private.h"
 #include "test-runner.h"
@@ -56,7 +57,7 @@ TEST(client_destroy_listener)
struct client_destroy_listener a, b;
int s[2];
 
-   assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
+   assert(wl_os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, s) == 0);
display = wl_display_create();
assert(display);
client = wl_client_create(display, s[0]);
diff --git a/tests/connection-test.c b/tests/connection-test.c
index 1ac88d2..ce4cd1a 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include "wayland-os.h"
 #include "wayland-private.h"
 #include "test-runner.h"
 
@@ -42,7 +43,7 @@ setup(int *s)
 {
struct wl_connection *connection;
 
-   assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
+   assert(wl_os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, s) == 0);
 
connection = wl_connection_create(s[0]);
assert(connection);
@@ -136,8 +137,7 @@ struct marshal_data {
 static void
 setup_marshal_data(struct marshal_data *data)
 {
-   assert(socketpair(AF_UNIX,
- SOCK_STREAM | SOCK_CLOEXEC, 0, data->s) == 0);
+   assert(wl_os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, data->s) == 0);
data->read_connection = wl_connection_create(data->s[0]);
assert(data->read_connection);
data->write_connection = wl_connection_create(data->s[1]);
diff --git a/tests/os-wrappers-test.c b/tests/os-wrappers-test.c
index ca79c5e..af7901c 100644
--- a/tests/os-wrappers-test.c
+++ b/tests/os-wrappers-test.c
@@ -85,10 +85,12 @@ socket(int domain, int type, int protocol)
 {
wrapped_calls_socket++;
 
+#ifdef SOCK_CLOEXEC
if (fall_back && (type & SOCK_CLOEXEC)) {
errno = EINVAL;
return -1;
}
+#endif
 
return real_socket(domain, type, protocol);
 }
@@ -101,10 +103,12 @

[PATCH 06/12] event-loop.c: Use correct OS abstraction function for dupfd()

2013-02-15 Thread Philip Withnall
Signed-off-by: Philip Withnall 
---
 src/event-loop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/event-loop.c b/src/event-loop.c
index 05baa48..6330763 100644
--- a/src/event-loop.c
+++ b/src/event-loop.c
@@ -220,7 +220,7 @@ wl_event_loop_add_fd(struct wl_event_loop *loop,
return NULL;
 
source->base.interface = &fd_source_interface;
-   source->base.fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
+   source->base.fd = wl_os_dupfd_cloexec(fd, 0);
source->func = func;
source->fd = fd;
 
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 05/12] event-loop-test: Add some more assertions and work around a FreeBSD bug

2013-02-15 Thread Philip Withnall
There’s a bug in FreeBSD’s handling of timer events which means we have to
be more relaxed about how we check when timer events have happened because
FreeBSD can’t manage enough precision on scheduling the events.

Signed-off-by: Philip Withnall 
---
 tests/event-loop-test.c | 22 --
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c
index c46d3b0..cf9dabe 100644
--- a/tests/event-loop-test.c
+++ b/tests/event-loop-test.c
@@ -155,10 +155,11 @@ TEST(event_loop_signal)
 
source = wl_event_loop_add_signal(loop, SIGUSR1,
  signal_callback, &got_it);
-   wl_event_loop_dispatch(loop, 0);
+   assert(source);
+   assert(wl_event_loop_dispatch(loop, 0) == 0);
assert(!got_it);
-   kill(getpid(), SIGUSR1);
-   wl_event_loop_dispatch(loop, 0);
+   assert(kill(getpid(), SIGUSR1) == 0);
+   assert(wl_event_loop_dispatch(loop, 0) == 0);
assert(got_it);
 
wl_event_source_remove(source);
@@ -183,12 +184,21 @@ TEST(event_loop_timer)
int got_it = 0;
 
source = wl_event_loop_add_timer(loop, timer_callback, &got_it);
-   wl_event_source_timer_update(source, 10);
-   wl_event_loop_dispatch(loop, 0);
+   assert(source);
+   assert(wl_event_source_timer_update(source, 10) == 0);
+   assert(wl_event_loop_dispatch(loop, 0) == 0);
assert(!got_it);
-   wl_event_loop_dispatch(loop, 20);
+   /* FreeBSD has a bug where it converts ms_timeout to ticks; it always 
adds 1 to the tick count.
+* Consequently, we need to grossly overcompensate here.
+* See: 
http://unix.derkeiler.com/Mailing-Lists/FreeBSD/hackers/2012-07/msg00319.html */
+   assert(wl_event_loop_dispatch(loop, 50) == 0);
assert(got_it);
 
+   /* Check it doesn't fire again. */
+   got_it = 0;
+   assert(wl_event_loop_dispatch(loop, 20) == 0);
+   assert(!got_it);
+
wl_event_source_remove(source);
wl_event_loop_destroy(loop);
 }
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 04/12] configure: Use AC_CHECK_LIB() to find libdl

2013-02-15 Thread Philip Withnall
This is necessary on FreeBSD.

Signed-off-by: Philip Withnall 
---
 configure.ac  | 4 
 tests/Makefile.am | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 3ad39ab..35b89c8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,6 +52,10 @@ AC_CHECK_HEADERS([sys/signalfd.h sys/timerfd.h])
 # Credential support on FreeBSD.
 AC_CHECK_HEADERS([sys/ucred.h])
 
+# dlopen()
+AC_CHECK_LIB([dl], [dlsym], [DL_LIBS=-ldl])
+AC_SUBST([DL_LIBS])
+
 AC_ARG_ENABLE([scanner],
   [AC_HELP_STRING([--disable-scanner],
   [Disable compilation of wayland-scanner])],
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 54157bc..604996a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,7 +45,7 @@ AM_CFLAGS = $(GCC_CFLAGS) $(FFI_CFLAGS)
 LDADD = $(top_builddir)/src/libwayland-util.la \
$(top_builddir)/src/libwayland-client.la \
$(top_builddir)/src/libwayland-server.la \
-   -lrt -ldl $(FFI_LIBS)
+   -lrt $(DL_LIBS) $(FFI_LIBS)
 
 exec_fd_leak_checker_SOURCES = \
exec-fd-leak-checker.c  \
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 03/12] server: Add support for BSD’s xucred credentials

2013-02-15 Thread Philip Withnall
This is an alternative to the traditional ucred on Linux.

Signed-off-by: Philip Withnall 
---
 configure.ac |  3 ++
 src/wayland-server.c | 33 +++
 src/wayland-shm.c| 91 +++-
 3 files changed, 126 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 935afbd..3ad39ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,6 +49,9 @@ fi
 
 AC_CHECK_HEADERS([sys/signalfd.h sys/timerfd.h])
 
+# Credential support on FreeBSD.
+AC_CHECK_HEADERS([sys/ucred.h])
+
 AC_ARG_ENABLE([scanner],
   [AC_HELP_STRING([--disable-scanner],
   [Disable compilation of wayland-scanner])],
diff --git a/src/wayland-server.c b/src/wayland-server.c
index dae7177..614dd2f 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -22,6 +22,8 @@
 
 #define _GNU_SOURCE
 
+#include "../config.h"
+
 #include 
 #include 
 #include 
@@ -40,6 +42,10 @@
 #include 
 #include 
 #include 
+#ifdef HAVE_SYS_UCRED_H
+#include 
+#include 
+#endif
 
 #include "wayland-private.h"
 #include "wayland-server.h"
@@ -75,7 +81,13 @@ struct wl_client {
struct wl_list link;
struct wl_map objects;
struct wl_signal destroy_signal;
+#ifdef HAVE_SYS_UCRED_H
+   /* FreeBSD. */
+   struct xucred xucred;
+#else
+   /* Linux. */
struct ucred ucred;
+#endif
int error;
 };
 
@@ -346,10 +358,20 @@ wl_client_create(struct wl_display *display, int fd)
if (!client->source)
goto err_client;
 
+#if defined(SO_PEERCRED)
+   /* Linux. */
len = sizeof client->ucred;
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
   &client->ucred, &len) < 0)
goto err_source;
+#elif defined(LOCAL_PEERCRED)
+   /* FreeBSD. */
+   len = sizeof client->xucred;
+   if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED, &client->xucred,
+  &len) < 0 ||
+   client->xucred.cr_version != XUCRED_VERSION)
+   goto err_source;
+#endif
 
client->connection = wl_connection_create(fd);
if (client->connection == NULL)
@@ -384,12 +406,23 @@ WL_EXPORT void
 wl_client_get_credentials(struct wl_client *client,
  pid_t *pid, uid_t *uid, gid_t *gid)
 {
+#ifdef HAVE_SYS_UCRED_H
+   /* FreeBSD. */
+   if (pid)
+   *pid = 0; /* FIXME: not defined on FreeBSD */
+   if (uid)
+   *uid = client->xucred.cr_uid;
+   if (gid)
+   *gid = client->xucred.cr_gid;
+#else
+   /* Linux. */
if (pid)
*pid = client->ucred.pid;
if (uid)
*uid = client->ucred.uid;
if (gid)
*gid = client->ucred.gid;
+#endif
 }
 
 WL_EXPORT uint32_t
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 47c126b..c783d0e 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -27,6 +27,8 @@
 
 #define _GNU_SOURCE
 
+#include "../config.h"
+
 #include 
 #include 
 #include 
@@ -41,6 +43,9 @@ struct wl_shm_pool {
int refcount;
char *data;
int size;
+#ifdef HAVE_SYS_UCRED_H
+   int fd;
+#endif
 };
 
 struct wl_shm_buffer {
@@ -58,6 +63,10 @@ shm_pool_unref(struct wl_shm_pool *pool)
if (pool->refcount)
return;
 
+#ifdef HAVE_SYS_UCRED_H
+   close(pool->fd);
+#endif
+
munmap(pool->data, pool->size);
free(pool);
 }
@@ -154,14 +163,88 @@ shm_pool_destroy(struct wl_client *client, struct 
wl_resource *resource)
wl_resource_destroy(resource);
 }
 
+#ifdef HAVE_MREMAP
+static void *
+mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size,
+  int old_prot, int old_flags, int old_fd)
+{
+   return mremap(old_address, old_size, new_size, MREMAP_MAYMOVE);
+}
+#else
+static void *
+mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size,
+  int old_prot, int old_flags, int old_fd)
+{
+   /* FreeBSD doesn't support mremap() yet, so we have to emulate it.
+* This assumes MREMAP_MAYMOVE is the only flag in use. */
+   if (new_size == old_size) {
+   return old_address;
+   } else if (new_size < old_size) {
+   /* Shrinking: munmap() the spare region. */
+   munmap(old_address + old_size, new_size - old_size);
+   return old_address;
+   } else {
+   void *ret;
+
+   /* Growing. Try and mmap() the extra region at the end of
+* our existing allocation. If that gets mapped in the
+* wrong place, fall back to mmap()ing an entirely new
+* region of new_size and copying the data across. */
+   ret = mmap(old_address + old_size, new_size - old_size,
+  old_prot, old_flags, old_fd, 0);
+
+/* TODO: msync() before munmap()? */
+   if (ret == MAP_FAILED) {
+

[PATCH 02/12] event-loop: Add support for BSD???s kevent() instead of epoll()

2013-02-15 Thread Philip Withnall
This is a large step towards supporting the BSDs. There’s quite a lot of
little in the test suite).

Signed-off-by: Philip Withnall 
---
 configure.ac |   8 ++
 src/event-loop.c | 361 +--
 src/wayland-os.c |  23 ++-
 src/wayland-os.h |   7 +
 tests/os-wrappers-test.c |  34 +
 5 files changed, 419 insertions(+), 14 deletions(-)

diff --git a/configure.ac b/configure.ac
index 883411c..935afbd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,14 @@ AC_SUBST(GCC_CFLAGS)
 
 AC_CHECK_FUNCS([accept4 mkostemp])
 
+# Use epoll on Linux or kqueue on BSD
+AC_CHECK_HEADERS([sys/epoll.h sys/event.h])
+if test "x$ac_cv_header_sys_epoll_h" != "xyes" && test 
"x$ac_cv_header_sys_event_h" != "xyes"; then
+   AC_MSG_ERROR([Can't find sys/epoll.h or sys/event.h. Please ensure 
either epoll or kqueue is available.])
+fi
+
+AC_CHECK_HEADERS([sys/signalfd.h sys/timerfd.h])
+
 AC_ARG_ENABLE([scanner],
   [AC_HELP_STRING([--disable-scanner],
   [Disable compilation of wayland-scanner])],
diff --git a/src/event-loop.c b/src/event-loop.c
index e556cc7..05baa48 100644
--- a/src/event-loop.c
+++ b/src/event-loop.c
@@ -20,6 +20,8 @@
  * OF THIS SOFTWARE.
  */
 
+#include "../config.h"
+
 #include 
 #include 
 #include 
@@ -29,9 +31,23 @@
 #include 
 #include 
 #include 
+
+#ifdef HAVE_SYS_EPOLL_H
 #include 
+#ifdef HAVE_SYS_SIGNALFD_H
 #include 
+#endif /* signalfd */
+#ifdef HAVE_SYS_TIMERFD_H
 #include 
+#endif /* timerfd */
+#elif HAVE_SYS_EVENT_H
+#include 
+#include 
+#include 
+#else /* !epoll && !kqueue */
+#error "Unsupported event system. Only epoll and kqueue are supported."
+#endif
+
 #include 
 #include 
 #include "wayland-server.h"
@@ -39,7 +55,7 @@
 #include "wayland-os.h"
 
 struct wl_event_loop {
-   int epoll_fd;
+   int event_fd;
struct wl_list check_list;
struct wl_list idle_list;
struct wl_list destroy_list;
@@ -48,8 +64,13 @@ struct wl_event_loop {
 };
 
 struct wl_event_source_interface {
+#ifdef HAVE_SYS_EPOLL_H
int (*dispatch)(struct wl_event_source *source,
struct epoll_event *ep);
+#elif HAVE_SYS_EVENT_H
+   int (*dispatch)(struct wl_event_source *source,
+   struct kevent *ep);
+#endif
 };
 
 struct wl_event_source {
@@ -66,11 +87,13 @@ struct wl_event_source_fd {
int fd;
 };
 
+#ifdef HAVE_SYS_EPOLL_H
 static int
 wl_event_source_fd_dispatch(struct wl_event_source *source,
struct epoll_event *ep)
 {
-   struct wl_event_source_fd *fd_source = (struct wl_event_source_fd *) 
source;
+   struct wl_event_source_fd *fd_source =
+   (struct wl_event_source_fd *) source;
uint32_t mask;
 
mask = 0;
@@ -85,11 +108,32 @@ wl_event_source_fd_dispatch(struct wl_event_source *source,
 
return fd_source->func(fd_source->fd, mask, source->data);
 }
+#elif HAVE_SYS_EVENT_H
+static int
+wl_event_source_fd_dispatch(struct wl_event_source *source,
+struct kevent *ev)
+{
+   struct wl_event_source_fd *fd_source =
+   (struct wl_event_source_fd *) source;
+   uint32_t mask;
+
+   mask = 0;
+   if (ev->filter == EVFILT_READ)
+   mask |= WL_EVENT_READABLE;
+   if (ev->filter == EVFILT_WRITE)
+   mask |= WL_EVENT_WRITABLE;
+   if (ev->flags & EV_ERROR)
+   mask |= WL_EVENT_ERROR;
+
+   return fd_source->func(fd_source->fd, mask, source->data);
+}
+#endif
 
 struct wl_event_source_interface fd_source_interface = {
wl_event_source_fd_dispatch,
 };
 
+#ifdef HAVE_SYS_EPOLL_H
 static struct wl_event_source *
 add_source(struct wl_event_loop *loop,
   struct wl_event_source *source, uint32_t mask, void *data)
@@ -113,7 +157,47 @@ add_source(struct wl_event_loop *loop,
ep.events |= EPOLLOUT;
ep.data.ptr = source;
 
-   if (epoll_ctl(loop->epoll_fd, EPOLL_CTL_ADD, source->fd, &ep) < 0) {
+   if (epoll_ctl(loop->event_fd, EPOLL_CTL_ADD, source->fd, &ep) < 0) {
+   close(source->fd);
+   free(source);
+   return NULL;
+   }
+
+   return source;
+}
+#elif HAVE_SYS_EVENT_H
+static struct wl_event_source *
+add_source(struct wl_event_loop *loop,
+   struct wl_event_source *source, uint32_t mask, void *data)
+{
+   struct kevent events[2];
+   unsigned int num_events = 0;
+
+   if (source->fd < 0) {
+   fprintf(stderr, "could not add source\n: %m");
+   free(source);
+   return NULL;
+   }
+
+   source->loop = loop;
+   source->data = data;
+   wl_list_init(&source->link);
+
+   if (mask & WL_EVENT_READABLE) {
+   EV_SET(&events[num_events], source->fd, EVFILT_READ,
+  EV_ADD | EV_ENABLE, 0, 0, source);
+   num_events++;
+   }
+
+   

[PATCH 01/12] connection: Fix sendmsg() on FreeBSD

2013-02-15 Thread Philip Withnall
It expects ((msg_controllen == 0) == (msg_control == NULL)), and returns
EINVAL otherwise. It can’t hurt to be tidy about things on other platforms
either though.

See: http://www.freebsd.org/cgi/query-pr.cgi?pr=docs/99356#reply2

Signed-off-by: Philip Withnall 
---
 src/connection.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 8707d40..1e00443 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -284,10 +284,19 @@ wl_connection_flush(struct wl_connection *connection)
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = count;
-   msg.msg_control = cmsg;
-   msg.msg_controllen = clen;
+   msg.msg_control = NULL;
+   msg.msg_controllen = 0;
msg.msg_flags = 0;
 
+   /* FreeBSD requires msg_control to be set to NULL iff
+* msg_controllen is 0 (see
+* http://www.freebsd.org/cgi/query-pr.cgi?pr=docs/99356#reply2)
+* Can't hurt to do that on all platforms. */
+   if (clen > 0) {
+   msg.msg_controllen = clen;
+   msg.msg_control = cmsg;
+   }
+
do {
len = sendmsg(connection->fd, &msg,
  MSG_NOSIGNAL | MSG_DONTWAIT);
-- 
1.7.11.7



signature.asc
Description: This is a digitally signed message part
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: Weston SDK

2013-02-15 Thread Pekka Paalanen
On Thu, 14 Feb 2013 11:27:22 -0500
Kristian Høgsberg  wrote:

> Hi,
> 
> I made a little experiment last night:
> 
>   http://cgit.freedesktop.org/~krh/overlay-plugin
> 
> It's an out-of-tree weston plugin.  It's just a silly little overlay
> that you can pop up with mod-space, but the interesting part here is
> that it's building outside weston [1].  Current, that works by copying
> the header files that defines the weston <-> plugins API, but I'd like
> to start thinking about how to formalize this process.  I don't think
> it should be a big problem, it more or less boils down to:
> 
>  - Interface version in headers and at runtime
> 
>  - Header files installed in /usr/include/weston
> 
>  - pkg-config file
> 

If we take this one step further and think about supporting the
replacement of, say, weston-desktop-shell client, we will need the
protocol XMl files, too. Also language binding kits would probably like
to have wayland.xml available from Wayland installation instead of
maintaining a copy.

Could [1] be solved while at it?

[1] https://bugs.freedesktop.org/show_bug.cgi?id=55183

> Now, I don't want this to slow down what we can do with weston
> internals, so this won't be stable API across major releases for the
> forseeable future.  But for a stable branch we should be able to avoid
> breaking the plugin API.  For 1.0 for example, we haven't changed the
> API or ABI at all.  
> 
> Another caveat is that this doesn't imply that the exported API is
> particular useful or coherent.  I think what we have is fairly decent
> though, it's just that we never developed it with an eye to be an
> external, self-contained API.  So we may be exposing too little or too
> much or there may be broken or inconsitent stuff in there.  But I
> think the first step towards working this out is to try to expose the
> API and just be careful about not promising too much in
> terms of usefulness or stability initially.


Thanks,
pq
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 2/2] compositor-drm: Fix inconsistency in finish frame timestamps

2013-02-15 Thread Pekka Paalanen
On Thu, 14 Feb 2013 11:51:15 -0500
Kristian Høgsberg  wrote:

> On Wed, Feb 13, 2013 at 04:06:38PM +0200, Ander Conselvan de Oliveira wrote:
> > The page flip event timestamps comes from the monotonic clock, while
> > idle_repaint() gets the time with gettimeofday(). That leads to
> > inconsistent timestamps on the frame callbacks.
> > 
> > Fix this by making the drm backend page flip to the current buffer and
> > call weston_output_finish_frame() with the page flip event timestamp,
> > instead of using gettimeofday().
> 
> Yup, this looks right, but I think we need to require that all
> backends provide a start_repaint_loop function.  Only the backend
> knows what kind of timestamp comes back in finish_frame, so we can't
> assume gttimeofday() as a fallback.  compositor-wayland.c uses the
> frame callback timestamp, for example, and if the host weston is
> running on KMS, that's a monotonic timestamp from the underlying
> pageflip event.

Hi,

while you are making the timestamps consistent, could also make them,
err... correct?

I think the current code in weston_output_repaint() is sending out the
frame callbacks at the moment the rendering has been started, not when
when it has hit the screen. Do you agree?


Thanks,
pq
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel