mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-08 22:45:58 +01:00
b29ac8fbac
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.
29 lines
726 B
C
29 lines
726 B
C
#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;
|
|
}
|
|
|