summaryrefslogtreecommitdiffstats
path: root/super0.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2005-06-07 23:03:48 +0000
committerNeil Brown <neilb@suse.de>2005-06-07 23:03:48 +0000
commitdfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2 (patch)
tree0fd6aa40bd1559c813eab17392936bdaf2514a1f /super0.c
parent892debc8200517e8b00750367acd890199f9f4de (diff)
downloadmdadm-dfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2.tar.gz
mdadm-dfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2.tar.xz
mdadm-dfe47e008e10d5640c6b3d0ae6de7ef6cefcb7b2.zip
Make sure to seed the random number generator for uuids
Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
Diffstat (limited to 'super0.c')
-rw-r--r--super0.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/super0.c b/super0.c
index d6619d5..2b57147 100644
--- a/super0.c
+++ b/super0.c
@@ -326,6 +326,7 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
{
mdp_super_t *sb = malloc(MD_SB_BYTES);
int spares;
+ int rfd;
memset(sb, 0, MD_SB_BYTES);
if (info->major_version == -1) {
@@ -340,12 +341,14 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
return 0;
}
+ rfd = open("/dev/urandom", O_RDONLY);
sb->md_magic = MD_SB_MAGIC;
sb->major_version = 0;
sb->minor_version = 90;
sb->patch_version = 0;
sb->gvalid_words = 0; /* ignored */
- sb->set_uuid0 = random();
+ if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
+ sb->set_uuid0 = random();
sb->ctime = time(0);
sb->level = info->level;
sb->size = info->size;
@@ -353,9 +356,13 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
sb->raid_disks = info->raid_disks;
sb->md_minor = info->md_minor;
sb->not_persistent = 0;
- sb->set_uuid1 = random();
- sb->set_uuid2 = random();
- sb->set_uuid3 = random();
+ if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
+ sb->set_uuid1 = random();
+ sb->set_uuid2 = random();
+ sb->set_uuid3 = random();
+ }
+ if (rfd >= 0)
+ close(rfd);
sb->utime = sb->ctime;
sb->state = info->state;