<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 3, 2016 at 1:18 PM, Friedrich, Eugen (ADITG/SW1) <span dir="ltr"><<a href="mailto:efriedrich@de.adit-jv.com" target="_blank">efriedrich@de.adit-jv.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">systemd provides a feature of socket-based activation, details in [1]<br>
This commit adds an implementation to check if sockets were provided by<br>
systemd and adds this as an additional socket to wayland display.<br>
before adding sockets are checked for the correctness:<br>
only AF_UNIX of type SOCK_STREAM are accepted<br>
<br>
This is usefull for early rendering use-cases where weston and<br>
early-rendering-application can be started parallel.<br>
<br>
[1] <a href="https://www.freedesktop.org/software/systemd/man/systemd.socket.html" rel="noreferrer" target="_blank">https://www.freedesktop.org/software/systemd/man/systemd.socket.html</a><br>
<br>
Signed-off-by: Eugen Friedrich <<a href="mailto:efriedrich@de.adit-jv.com">efriedrich@de.adit-jv.com</a>><br>
---<br>
 <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a>         |  5 ++++-<br>
 src/systemd-notify.c | 27 +++++++++++++++++++++++++++<br>
 2 files changed, 31 insertions(+), 1 deletion(-)<br>
 mode change 100644 => 100755 src/systemd-notify.c<br>
<br>
diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
index 9e8115a..447cf6b 100644<br>
--- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
@@ -634,7 +634,10 @@ AC_ARG_ENABLE(systemd_notify,<br>
               AS_HELP_STRING([--enable-systemd-notify],<br>
                              [Enables systemd notifications to<br>
                               notify systemd about weston state<br>
-                              and update watchdog.]),,<br>
+                              and update watchdog.<br>
+                              Also sockets provided by systemd<br>
+                              in case of socket-base activation<br>
+                              are added to wayland display]),,<br>
               enable_systemd_notify=no)<br>
 AM_CONDITIONAL(SYSTEMD_NOTIFY_SUPPORT, test x$enable_systemd_notify = xyes)<br>
 if test "x$enable_systemd_notify" = "xyes"; then<br>
diff --git a/src/systemd-notify.c b/src/systemd-notify.c<br>
old mode 100644<br>
new mode 100755<br>
index e61db0f..0be1f6f<br>
--- a/src/systemd-notify.c<br>
+++ b/src/systemd-notify.c<br>
@@ -28,6 +28,7 @@<br>
 #include <errno.h><br>
 #include <stdlib.h><br>
 #include <systemd/sd-daemon.h><br>
+#include <sys/socket.h><br>
 #include <wayland-server.h><br>
 #include "shared/helpers.h"<br>
 #include "shared/zalloc.h"<br>
@@ -79,6 +80,8 @@ module_init(struct weston_compositor *compositor,<br>
        struct wl_event_loop *loop;<br>
        long watchdog_time_conv;<br>
        struct systemd_notifier *notifier;<br>
+       int fd;<br></blockquote><div><br></div><div>I think you can move this declaration into the loop next to "int current_fd = 0;"</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+       int systemd_socket_fds = 0;<br>
<br>
        notifier = zalloc(sizeof *notifier);<br>
        if (notifier == NULL)<br>
@@ -89,6 +92,30 @@ module_init(struct weston_compositor *compositor,<br>
        wl_signal_add(&compositor->destroy_signal,<br>
                      &notifier->compositor_destroy_listener);<br>
<br>
+       /*take additional display sockets if provided by systemd*/<br>
+       systemd_socket_fds = sd_listen_fds(1);<br>
+<br>
+       if (systemd_socket_fds > 0) {<br>
+               int current_fd = 0;<br></blockquote><div><br></div><div>ie put it here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+               for (;current_fd < systemd_socket_fds; current_fd++) {<br>
+                       fd = SD_LISTEN_FDS_START + current_fd;<br>
+<br>
+                       if (sd_is_socket(fd, AF_UNIX, SOCK_STREAM,1) > 0) {<br>
+                               if (wl_display_add_socket_fd(compositor->wl_display, fd)) {<br>
+                                       weston_log("wl_display_add_socket_fd failed\n");<br>
+                                       return -1;<br>
+                               }<br>
+                       } else {<br>
+                               weston_log("invalid socket provided from systemd\n");<br>
+                               return -1;<br>
+                       }<br>
+               }<br>
+<br>
+               weston_log("info: add %d socket(s) provided by systemd\n",<br>
+                               current_fd);<br>
+       }<br>
+<br>
        sd_notify(0, "READY=1");<br>
<br>
        /* 'WATCHDOG_USEC' is environment variable that is set<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.4.11<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div></div>