summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFriedrich, Eugen (ADITG/SW1) <efriedrich@de.adit-jv.com>2016-04-05 20:43:29 +0000
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2016-04-06 14:12:02 +0300
commit265aeb316bce85a9c1941fb6e51b2b7b90760255 (patch)
treef306fb50086422512dc57f11b7f5ce6c5cc50642 /src
parentd962be149391ac2e00e1197612f2e6ec18dfa9f3 (diff)
downloadweston-265aeb316bce85a9c1941fb6e51b2b7b90760255.tar.gz
systemd: take over sockets created by systemd
Systemd provides a feature of socket-based activation, details in [1] This commit adds an implementation to check if sockets were provided by systemd and adds this as an additional socket to wayland display. before adding sockets are checked for the correctness: only AF_UNIX of type SOCK_STREAM are accepted This is usefull for early rendering use-cases where weston and early-rendering-application can be started parallel. [1] https://www.freedesktop.org/software/systemd/man/systemd.socket.html Signed-off-by: Eugen Friedrich <efriedrich@de.adit-jv.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/systemd-notify.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/systemd-notify.c b/src/systemd-notify.c
index e61db0fb..44070597 100644
--- a/src/systemd-notify.c
+++ b/src/systemd-notify.c
@@ -28,6 +28,7 @@
#include <errno.h>
#include <stdlib.h>
#include <systemd/sd-daemon.h>
+#include <sys/socket.h>
#include <wayland-server.h>
#include "shared/helpers.h"
#include "shared/zalloc.h"
@@ -40,6 +41,47 @@ struct systemd_notifier {
};
static int
+add_systemd_sockets(struct weston_compositor *compositor)
+{
+ int fd;
+ int cnt_systemd_sockets;
+ int current_fd = 0;
+
+ cnt_systemd_sockets = sd_listen_fds(1);
+
+ if (cnt_systemd_sockets < 0) {
+ weston_log("sd_listen_fds failed with: %d\n",
+ cnt_systemd_sockets);
+ return -1;
+ }
+
+ /* socket-based activation not used, return silently */
+ if (cnt_systemd_sockets == 0)
+ return 0;
+
+ while (current_fd < cnt_systemd_sockets) {
+ fd = SD_LISTEN_FDS_START + current_fd;
+
+ if (sd_is_socket(fd, AF_UNIX, SOCK_STREAM,1) <= 0) {
+ weston_log("invalid socket provided from systemd\n");
+ return -1;
+ }
+
+ if (wl_display_add_socket_fd(compositor->wl_display, fd)) {
+ weston_log("wl_display_add_socket_fd failed"
+ "for systemd provided socket\n");
+ return -1;
+ }
+ current_fd++;
+ }
+
+ weston_log("info: add %d socket(s) provided by systemd\n",
+ current_fd);
+
+ return current_fd;
+}
+
+static int
watchdog_handler(void *data)
{
struct systemd_notifier *notifier = data;
@@ -89,6 +131,9 @@ module_init(struct weston_compositor *compositor,
wl_signal_add(&compositor->destroy_signal,
&notifier->compositor_destroy_listener);
+ if (add_systemd_sockets(compositor) < 0)
+ return -1;
+
sd_notify(0, "READY=1");
/* 'WATCHDOG_USEC' is environment variable that is set