From 1280d6bb4910e2020c3ff9121ebe468622f88079 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 16 Jan 2012 11:51:08 -0500 Subject: [PATCH] Use the kernelspace uuid generator if available --- libcitadel/lib/tools.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c index cef6e82b5..43a788230 100644 --- a/libcitadel/lib/tools.c +++ b/libcitadel/lib/tools.c @@ -875,6 +875,24 @@ char *strcpy(char *dest, const char *src) { */ void generate_uuid(char *buf) { static int seq = (-1); + static int no_kernel_uuid = 0; + + /* If we are running on Linux then we have a kernelspace uuid generator available */ + + if (no_kernel_uuid == 0) { + FILE *fp; + fp = fopen("/proc/sys/kernel/random/uuid", "rb"); + if (fp) { + int rv; + rv = fread(buf, 36, 1, fp); + fclose(fp); + if (rv == 1) return; + } + } + + /* If the kernel didn't provide us with a uuid, we generate a pseudo-random one */ + + no_kernel_uuid = 1; if (seq == (-1)) { seq = (int)rand(); -- 2.30.2