diff options
author | Ray Strode <rstrode@redhat.com> | 2008-12-21 18:01:26 -0800 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2008-12-22 09:40:04 -0800 |
commit | 6639e18ed88a3d92e6f6353a966061cf8ae004a3 (patch) | |
tree | e2bef4bf3228d9d0cf1307e4a56507c405280327 | |
parent | aa21c60263140051918ca92221c52c4f538216a2 (diff) |
Try to take name on bus and bail if unable
We only want one system wayland instance
(and eventually one wayland instance per
session). We ensure this by taking a
name on the message bus.
-rw-r--r-- | Makefile.in | 12 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | dbus.c | 24 | ||||
-rw-r--r-- | org.freedesktop.Wayland.conf | 14 | ||||
-rw-r--r-- | org.freedesktop.Wayland.service.in | 5 | ||||
-rw-r--r-- | wayland-system-compositor.c | 7 | ||||
-rw-r--r-- | wayland-system-compositor.h | 4 |
7 files changed, 64 insertions, 4 deletions
diff --git a/Makefile.in b/Makefile.in index 1e11680..565ff6b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -7,7 +7,7 @@ libs = libwayland-server.so libwayland.so clients = flower gears screenshot terminal compositors = wayland-system-compositor -all : $(libs) $(compositors) $(clients) +all : $(libs) $(compositors) $(clients) org.freedesktop.Wayland.service libwayland-server.so : \ wayland.o \ @@ -48,15 +48,21 @@ terminal : LDLIBS += -lutil $(clients) : CFLAGS += @CLIENT_CFLAGS@ $(clients) : LDLIBS += -L. -lwayland @CLIENT_LIBS@ -lrt -install : $(libs) wayland-system-compositor - install -d @libdir@ @libdir@/pkgconfig +install : $(libs) wayland-system-compositor org.freedesktop.Wayland.service + install -d @libdir@ @libdir@/pkgconfig @sysconfdir@/dbus-1/system.d @datarootdir@/dbus-1/system-services install $(libs) @libdir@ install wayland-system-compositor @sbindir@ install wayland-server.pc wayland.pc @libdir@/pkgconfig install wayland-client.h @includedir@ + install -m644 org.freedesktop.Wayland.conf @sysconfdir@/dbus-1/system.d + install -m644 org.freedesktop.Wayland.service @datarootdir@/dbus-1/system-services clean : rm -f $(clients) $(compositors) *.o *.so Makefile : Makefile.in ./config.status + +org.freedesktop.Wayland.service : org.freedesktop.Wayland.service.in + ./config.status + diff --git a/configure.ac b/configure.ac index ce44897..2f1a218 100644 --- a/configure.ac +++ b/configure.ac @@ -14,5 +14,5 @@ if test $CC = gcc; then fi AC_SUBST(GCC_CFLAGS) -AC_CONFIG_FILES([Makefile wayland-server.pc wayland.pc]) +AC_CONFIG_FILES([org.freedesktop.Wayland.service Makefile wayland-server.pc wayland.pc]) AC_OUTPUT @@ -256,3 +256,27 @@ wlsc_dbus_init(struct wl_event_loop *loop) return dbus; } + +bool wlsc_dbus_take_name(struct wlsc_dbus *dbus, const char *name, bool should_replace) +{ + DBusError error; + int result; + uint32_t flags; + + dbus_error_init(&error); + + flags = DBUS_NAME_FLAG_ALLOW_REPLACEMENT | DBUS_NAME_FLAG_DO_NOT_QUEUE; + + if (should_replace) + flags |= DBUS_NAME_FLAG_REPLACE_EXISTING; + + result = dbus_bus_request_name(dbus->connection, name, flags, &error); + + if (dbus_error_is_set(&error)) { + fprintf(stderr, "failed to request name on system bus: %s\n", error.message); + dbus_error_free(&error); + return false; + } + + return result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER; +} diff --git a/org.freedesktop.Wayland.conf b/org.freedesktop.Wayland.conf new file mode 100644 index 0000000..c61cd7d --- /dev/null +++ b/org.freedesktop.Wayland.conf @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE busconfig PUBLIC + "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> + +<busconfig> + <policy user="root"> + <allow own="org.freedesktop.Wayland"/> + </policy> + + <policy context="default"> + <allow send_destination="org.freedesktop.Wayland"/> + </policy> +</busconfig> diff --git a/org.freedesktop.Wayland.service.in b/org.freedesktop.Wayland.service.in new file mode 100644 index 0000000..e34d1dd --- /dev/null +++ b/org.freedesktop.Wayland.service.in @@ -0,0 +1,5 @@ +[D-BUS Service] +Name=org.freedesktop.Wayland +Exec=@sbindir@/wayland-system-compositor +User=root + diff --git a/wayland-system-compositor.c b/wayland-system-compositor.c index e9ddc78..6d4e21d 100644 --- a/wayland-system-compositor.c +++ b/wayland-system-compositor.c @@ -862,12 +862,15 @@ static const char *macbook_air_default_input_device[] = { static const char *option_background = "background.jpg"; static const char **option_input_devices = macbook_air_default_input_device; +static bool should_replace; static const GOptionEntry option_entries[] = { { "background", 'b', 0, G_OPTION_ARG_STRING, &option_background, "Background image" }, { "input-device", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &option_input_devices, "Input device glob" }, + { "replace", 'r', 0, G_OPTION_ARG_NONE, + &should_replace, "Stop running compositor and take over" }, { NULL } }; @@ -1107,6 +1110,10 @@ int main(int argc, char *argv[]) display = wl_display_create(loop); + if (!wlsc_dbus_take_name(dbus, "org.freedesktop.Wayland", should_replace)) { + exit(EXIT_FAILURE); + } + ec = egl_compositor_create(display, loop, dbus); if (ec == NULL) { fprintf(stderr, "failed to create compositor\n"); diff --git a/wayland-system-compositor.h b/wayland-system-compositor.h index 49112a7..4b1b01e 100644 --- a/wayland-system-compositor.h +++ b/wayland-system-compositor.h @@ -19,11 +19,15 @@ #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_ #define _WAYLAND_SYSTEM_COMPOSITOR_H_ +#include <stdbool.h> + struct egl_compositor; struct wlsc_dbus; struct wlsc_dbus * wlsc_dbus_init(struct wl_event_loop *loop); +bool +wlsc_dbus_take_name(struct wlsc_dbus *dbus, const char *name, bool should_replace); struct wlsc_input_device; void |