summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-10-01 23:11:23 +0200
committerLennart Poettering <lennart@poettering.net>2013-10-01 23:11:49 +0200
commita3b6fafed441d96380a3f089118f7486d6aa3126 (patch)
treebdef526be65bc02f5a5b401e474b90748f0bb6cb /src/shared/util.c
parentef7939dfbb454f5ed7a00c2c4c686e0c5aa48f00 (diff)
hashmap: randomize hash functions a bit
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 5dc605eb8d..9be6acfc8f 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2424,6 +2424,25 @@ fallback:
return random() * RAND_MAX + random();
}
+unsigned random_u(void) {
+ _cleanup_close_ int fd;
+ unsigned u;
+ ssize_t r;
+
+ fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
+ if (fd < 0)
+ goto fallback;
+
+ r = loop_read(fd, &u, sizeof(u), true);
+ if (r != sizeof(u))
+ goto fallback;
+
+ return u;
+
+fallback:
+ return random() * RAND_MAX + random();
+}
+
void rename_process(const char name[8]) {
assert(name);