From b29ac8fbaceeac7f902fc75bb94a13b9cd9a0465 Mon Sep 17 00:00:00 2001 From: Ryan Farley Date: Wed, 7 Apr 2021 13:10:43 -0500 Subject: 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. --- util/meson.build | 7 +------ util/token.c | 29 +++++++++++++++++++++++++++++ util/uuid.c | 34 ---------------------------------- 3 files changed, 30 insertions(+), 40 deletions(-) create mode 100644 util/token.c delete mode 100644 util/uuid.c (limited to 'util') 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 +#include +#include +#include + +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 -#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 -#include -#include - -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 -- cgit v1.2.3