aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Farley <ryan.farley@gmx.com>2021-04-07 13:10:43 -0500
committerSimon Ser <contact@emersion.fr>2021-04-11 19:09:36 +0200
commitb29ac8fbaceeac7f902fc75bb94a13b9cd9a0465 (patch)
treea47bd9bb8d4265386c3abb5ad7be6a7a397bbfb0
parent5a178c4a2398de612b7a4cb39d060ec62eec666b (diff)
util/uuid: replace with util/token, remove libuuid
Use 128-bit hexadecimal string tokens generated with /dev/urandom instead of UUIDs for xdg-foreign handles, removing the libuuid dependency. Update readme and CI. Closes #2830. build: remove xdg-foreign feature With no external dependencies required, there's no reason not to always build it. Remove WLR_HAS_XDG_FOREIGN as well.
-rw-r--r--.builds/alpine.yml1
-rw-r--r--.builds/freebsd.yml1
-rw-r--r--README.md1
-rw-r--r--include/meson.build7
-rw-r--r--include/util/token.h9
-rw-r--r--include/util/uuid.h8
-rw-r--r--include/wlr/config.h.in2
-rw-r--r--meson.build11
-rw-r--r--meson_options.txt1
-rw-r--r--types/meson.build10
-rw-r--r--types/wlr_xdg_foreign_registry.c4
-rw-r--r--util/meson.build7
-rw-r--r--util/token.c29
-rw-r--r--util/uuid.c34
14 files changed, 44 insertions, 81 deletions
diff --git a/.builds/alpine.yml b/.builds/alpine.yml
index 3caed345..5427f275 100644
--- a/.builds/alpine.yml
+++ b/.builds/alpine.yml
@@ -7,7 +7,6 @@ packages:
- mesa-dev
- meson
- pixman-dev
- - util-linux-dev
- wayland-dev
- wayland-protocols
- xcb-util-image-dev
diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml
index 7806b72c..4262feed 100644
--- a/.builds/freebsd.yml
+++ b/.builds/freebsd.yml
@@ -10,7 +10,6 @@ packages:
- graphics/png
- graphics/wayland
- graphics/wayland-protocols
- - misc/e2fsprogs-libuuid
- multimedia/ffmpeg
- x11/libX11
- x11/libinput
diff --git a/README.md b/README.md
index 83d818c6..f8f9583b 100644
--- a/README.md
+++ b/README.md
@@ -51,7 +51,6 @@ Install dependencies:
* udev
* pixman
* libseat (optional, for (e)logind and seatd support)
-* libuuid (optional, for xdg-foreign support)
If you choose to enable X11 support:
diff --git a/include/meson.build b/include/meson.build
index c72eada5..747e5984 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -9,13 +9,6 @@ if not features.get('xwayland')
else
subdir('xwayland')
endif
-if not features.get('xdg-foreign')
- exclude_files += [
- 'types/wlr_xdg_foreign_v1.h',
- 'types/wlr_xdg_foreign_v2.h',
- 'types/wlr_xdg_foreign_registry.h',
- ]
-endif
install_subdir('wlr',
install_dir: get_option('includedir'),
diff --git a/include/util/token.h b/include/util/token.h
new file mode 100644
index 00000000..bdfdaf45
--- /dev/null
+++ b/include/util/token.h
@@ -0,0 +1,9 @@
+#ifndef UTIL_TOKEN_H
+#define UTIL_TOKEN_H
+
+#include <stdbool.h>
+
+#define TOKEN_STRLEN 33
+bool generate_token(char out[static TOKEN_STRLEN]);
+
+#endif
diff --git a/include/util/uuid.h b/include/util/uuid.h
deleted file mode 100644
index 2fecb407..00000000
--- a/include/util/uuid.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef UTIL_UUID_H
-#define UTIL_UUID_H
-
-#include <stdbool.h>
-
-bool generate_uuid(char out[static 37]);
-
-#endif
diff --git a/include/wlr/config.h.in b/include/wlr/config.h.in
index 15aacbfe..bcea55a1 100644
--- a/include/wlr/config.h.in
+++ b/include/wlr/config.h.in
@@ -7,6 +7,4 @@
#mesondefine WLR_HAS_XWAYLAND
-#mesondefine WLR_HAS_XDG_FOREIGN
-
#endif
diff --git a/meson.build b/meson.build
index afa9c86a..84e1a521 100644
--- a/meson.build
+++ b/meson.build
@@ -84,7 +84,6 @@ features = {
'libseat': false,
'x11-backend': false,
'xwayland': false,
- 'xdg-foreign': false,
}
internal_features = {
'xcb-errors': false,
@@ -104,16 +103,6 @@ pixman = dependency('pixman-1')
math = cc.find_library('m')
rt = cc.find_library('rt')
-if not get_option('xdg-foreign').disabled()
- uuid = dependency('uuid', required: false)
- uuid_create = cc.has_function('uuid_create')
- if uuid.found() or uuid_create
- features += { 'xdg-foreign': true }
- elif get_option('xdg-foreign').enabled()
- error('Missing dependency uuid and uuid_create function not available ' +
- 'cannot build with xdg-foreign support')
- endif
-endif
wlr_files = []
wlr_deps = [
diff --git a/meson_options.txt b/meson_options.txt
index 770f604d..033019cc 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -4,4 +4,3 @@ option('xwayland', type: 'feature', value: 'auto', yield: true, description: 'En
option('x11-backend', type: 'feature', value: 'auto', description: 'Enable X11 backend')
option('examples', type: 'boolean', value: true, description: 'Build example applications')
option('icon_directory', description: 'Location used to look for cursors (default: ${datadir}/icons)', type: 'string', value: '')
-option('xdg-foreign', type: 'feature', value: 'auto', description: 'Enable xdg-foreign protocol')
diff --git a/types/meson.build b/types/meson.build
index d7b1bc5d..47431429 100644
--- a/types/meson.build
+++ b/types/meson.build
@@ -63,13 +63,9 @@ wlr_files += files(
'wlr_virtual_pointer_v1.c',
'wlr_xcursor_manager.c',
'wlr_xdg_decoration_v1.c',
+ 'wlr_xdg_foreign_v1.c',
+ 'wlr_xdg_foreign_v2.c',
+ 'wlr_xdg_foreign_registry.c',
'wlr_xdg_output_v1.c',
)
-if features.get('xdg-foreign')
- wlr_files += files(
- 'wlr_xdg_foreign_v1.c',
- 'wlr_xdg_foreign_v2.c',
- 'wlr_xdg_foreign_registry.c',
- )
-endif
diff --git a/types/wlr_xdg_foreign_registry.c b/types/wlr_xdg_foreign_registry.c
index 7af137b5..0b75e593 100644
--- a/types/wlr_xdg_foreign_registry.c
+++ b/types/wlr_xdg_foreign_registry.c
@@ -1,6 +1,6 @@
#include <wlr/types/wlr_xdg_foreign_registry.h>
#include "util/signal.h"
-#include "util/uuid.h"
+#include "util/token.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -9,7 +9,7 @@ bool wlr_xdg_foreign_exported_init(
struct wlr_xdg_foreign_exported *exported,
struct wlr_xdg_foreign_registry *registry) {
do {
- if (!generate_uuid(exported->handle)) {
+ if (!generate_token(exported->handle)) {
return false;
}
} while (wlr_xdg_foreign_registry_find_by_handle(registry, exported->handle) != NULL);
diff --git a/util/meson.build b/util/meson.build
index 9d3f1587..5e31cbbe 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -6,11 +6,6 @@ wlr_files += files(
'shm.c',
'signal.c',
'time.c',
+ 'token.c',
)
-
-if features.get('xdg-foreign')
- add_project_arguments('-DHAS_LIBUUID=@0@'.format(uuid.found().to_int()), language: 'c')
- wlr_deps += uuid
- wlr_files += files('uuid.c')
-endif
diff --git a/util/token.c b/util/token.c
new file mode 100644
index 00000000..cf6034a3
--- /dev/null
+++ b/util/token.c
@@ -0,0 +1,29 @@
+#include "util/token.h"
+#include "wlr/util/log.h"
+
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+bool generate_token(char out[static TOKEN_STRLEN]) {
+ static FILE *urandom = NULL;
+ uint64_t data[2];
+
+ if (!urandom) {
+ if (!(urandom = fopen("/dev/urandom", "r"))) {
+ wlr_log_errno(WLR_ERROR, "Failed to open random device");
+ return false;
+ }
+ }
+ if (fread(data, sizeof(data), 1, urandom) != 1) {
+ wlr_log_errno(WLR_ERROR, "Failed to read from random device");
+ return false;
+ }
+ if (snprintf(out, TOKEN_STRLEN, "%016" PRIx64 "%016" PRIx64, data[0], data[1]) != TOKEN_STRLEN - 1) {
+ wlr_log_errno(WLR_ERROR, "Failed to format hex string token");
+ return false;
+ }
+ return true;
+}
+
diff --git a/util/uuid.c b/util/uuid.c
deleted file mode 100644
index 82e310b9..00000000
--- a/util/uuid.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include <uuid.h>
-#include "util/uuid.h"
-
-#if HAS_LIBUUID
-bool generate_uuid(char out[static 37]) {
- uuid_t uuid;
- uuid_generate_random(uuid);
- uuid_unparse(uuid, out);
- return true;
-}
-#else
-#include <assert.h>
-#include <string.h>
-#include <stdlib.h>
-
-bool generate_uuid(char out[static 37]) {
- uuid_t uuid;
- uint32_t status;
- uuid_create(&uuid, &status);
- if (status != uuid_s_ok) {
- return false;
- }
- char *str;
- uuid_to_string(&uuid, &str, &status);
- if (status != uuid_s_ok) {
- return false;
- }
-
- assert(strlen(str) + 1 == 37);
- memcpy(out, str, 37);
- free(str);
- return true;
-}
-#endif