projects
/
citadel.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0160890
)
Use the kernelspace uuid generator if available
author
Art Cancro
<ajc@uncensored.citadel.org>
Mon, 16 Jan 2012 16:51:08 +0000
(11:51 -0500)
committer
Art Cancro
<ajc@uncensored.citadel.org>
Mon, 16 Jan 2012 16:51:08 +0000
(11:51 -0500)
libcitadel/lib/tools.c
patch
|
blob
|
history
diff --git
a/libcitadel/lib/tools.c
b/libcitadel/lib/tools.c
index cef6e82b5cd9f5029750b1ea9f00e7288d459ef8..43a7882303921c94ceab0ff3ad5880bf8170fe1d 100644
(file)
--- 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);
*/
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();
if (seq == (-1)) {
seq = (int)rand();