summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
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);